diff options
Diffstat (limited to 'src/loader')
-rw-r--r-- | src/loader/loader.nim | 33 | ||||
-rw-r--r-- | src/loader/request.nim | 4 |
2 files changed, 23 insertions, 14 deletions
diff --git a/src/loader/loader.nim b/src/loader/loader.nim index 6cc37b71..9c9c2e8a 100644 --- a/src/loader/loader.nim +++ b/src/loader/loader.nim @@ -429,6 +429,21 @@ proc loadResource(ctx: LoaderContext; client: ClientData; request: Request; if tries >= MaxRewrites: handle.rejectHandle(ERROR_TOO_MANY_REWRITES) +proc setupRequestDefaults*(request: Request; config: LoaderClientConfig) = + request.defaultHeadersSet = true + for k, v in config.defaultHeaders.table: + if k notin request.headers.table: + request.headers.table[k] = v + if config.cookieJar != nil and config.cookieJar.cookies.len > 0: + if "Cookie" notin request.headers.table: + let cookie = config.cookieJar.serialize(request.url) + if cookie != "": + request.headers["Cookie"] = cookie + if request.referrer != nil and "Referer" notin request.headers: + let r = request.referrer.getReferrer(request.url, config.referrerPolicy) + if r != "": + request.headers["Referer"] = r + proc onLoad(ctx: LoaderContext; stream: SocketStream; client: ClientData) = var request: Request stream.sread(request) @@ -440,20 +455,10 @@ proc onLoad(ctx: LoaderContext; stream: SocketStream; client: ClientData) = if not client.config.filter.match(request.url): handle.rejectHandle(ERROR_DISALLOWED_URL) else: - for k, v in client.config.defaultHeaders.table: - if k notin request.headers.table: - request.headers.table[k] = v - let cookieJar = client.config.cookieJar - if cookieJar != nil and cookieJar.cookies.len > 0: - if "Cookie" notin request.headers.table: - let cookie = cookieJar.serialize(request.url) - if cookie != "": - request.headers["Cookie"] = cookie - if request.referrer != nil and "Referer" notin request.headers: - let r = request.referrer.getReferrer(request.url, - client.config.referrerPolicy) - if r != "": - request.headers["Referer"] = r + if ctx.pagerClient != client or not request.defaultHeadersSet: + # do not override defaults for pager, because it starts requests that + # later belong to buffers. + request.setupRequestDefaults(client.config) if request.proxy == nil or not client.config.acceptProxy: request.proxy = client.config.proxy ctx.loadResource(client, request, handle) diff --git a/src/loader/request.nim b/src/loader/request.nim index 05b02114..60632041 100644 --- a/src/loader/request.nim +++ b/src/loader/request.nim @@ -81,6 +81,10 @@ type # when set to true, the loader will not write data from the body (not # headers!) into the output until a resume is received. suspended*: bool + # if defaultHeadersSet is set, then loader will not set default headers + # for the request if it was received from the pager. (this is used when + # starting requests for new buffers.) + defaultHeadersSet*: bool jsDestructor(Request) |