diff options
Diffstat (limited to 'src/loader')
| -rw-r--r-- | src/loader/loader.nim | 16 | ||||
| -rw-r--r-- | src/loader/loaderhandle.nim | 2 | ||||
| -rw-r--r-- | src/loader/request.nim | 17 |
3 files changed, 30 insertions, 5 deletions
diff --git a/src/loader/loader.nim b/src/loader/loader.nim index 5a3a85bd..fee84782 100644 --- a/src/loader/loader.nim +++ b/src/loader/loader.nim @@ -85,6 +85,7 @@ type UNREF SET_REFERRER_POLICY PASS_FD + REMOVE_CACHED_URL LoaderContext = ref object refcount: int @@ -201,6 +202,7 @@ proc addFd(ctx: LoaderContext, handle: LoaderHandle, originalUrl: URL) = proc loadStream(ctx: LoaderContext, handle: LoaderHandle, request: Request, originalUrl: URL) = ctx.passedFdMap.withValue(request.url.host, fdp): + handle.canredir = request.canredir handle.sendResult(0) handle.sendStatus(200) handle.sendHeaders(newHeaders()) @@ -430,6 +432,13 @@ proc acceptConnection(ctx: LoaderContext) = let fd = stream.recvFileHandle() ctx.passedFdMap[id] = fd stream.close() + of REMOVE_CACHED_URL: + var surl: string + stream.sread(surl) + ctx.cacheMap.withValue(surl, p): + discard unlink(cstring(p[])) + ctx.cacheMap.del(surl) + stream.close() except ErrorBrokenPipe: # receiving end died while reading the file; give up. stream.close() @@ -837,3 +846,10 @@ proc passFd*(pid: Pid, id: string, fd: FileHandle) = stream.swrite(id) stream.sendFileHandle(fd) stream.close() + +proc removeCachedURL*(loader: FileLoader, surl: string) = + let stream = connectSocketStream(loader.process) + if stream != nil: + stream.swrite(REMOVE_CACHED_URL) + stream.swrite(surl) + stream.close() diff --git a/src/loader/loaderhandle.nim b/src/loader/loaderhandle.nim index 11a97bf4..eb6d61ba 100644 --- a/src/loader/loaderhandle.nim +++ b/src/loader/loaderhandle.nim @@ -38,7 +38,7 @@ type # Only the first handle can be redirected, because a) mailcap can only # redirect the first handle and b) async redirects would result in race # conditions that would be difficult to untangle. - canredir: bool + canredir*: bool outputs*: seq[OutputHandle] cached*: bool cacheUrl*: string diff --git a/src/loader/request.nim b/src/loader/request.nim index 1d0e31cd..a39cded2 100644 --- a/src/loader/request.nim +++ b/src/loader/request.nim @@ -122,15 +122,24 @@ func newRequest*(url: URL, httpMethod = HTTP_GET, headers = newHeaders(), func newRequest*(url: URL, httpMethod = HTTP_GET, headers: seq[(string, string)] = @[], body = opt(string), multipart = opt(FormData), mode = RequestMode.NO_CORS, proxy: URL = nil, - canredir = false): - Request = + canredir = false): Request = let hl = newHeaders() for pair in headers: let (k, v) = pair hl.table[k] = @[v] - return newRequest(url, httpMethod, hl, body, multipart, mode, proxy = proxy) + return newRequest( + url, + httpMethod, + hl, + body, + multipart, + mode, + proxy = proxy, + canredir = canredir + ) -func createPotentialCORSRequest*(url: URL, destination: RequestDestination, cors: CORSAttribute, fallbackFlag = false): Request = +func createPotentialCORSRequest*(url: URL, destination: RequestDestination, + cors: CORSAttribute, fallbackFlag = false): Request = var mode = if cors == NO_CORS: RequestMode.NO_CORS else: |