diff options
author | Emilien Devos <contact@emiliendevos.be> | 2020-05-24 01:01:16 +0200 |
---|---|---|
committer | Emilien Devos <contact@emiliendevos.be> | 2020-05-24 01:01:16 +0200 |
commit | 159431aea3c73b75fe42991358894b5463907cbe (patch) | |
tree | b1cd6c312a80d00eb82d5cdfb72b930425c12234 /index.js | |
parent | 2bfe081a7f582015f3e4f5cf9aa98c349182276f (diff) |
handle response headers + cookies
Diffstat (limited to 'index.js')
-rw-r--r-- | index.js | 13 |
1 files changed, 9 insertions, 4 deletions
@@ -13,7 +13,7 @@ const headersToRemove = [ "host", "user-agent", "accept", "accept-encoding", "content-length", "forwarded", "x-forwarded-proto", "x-forwarded-for", "x-cloud-trace-context" ]; -const responseHeadersToRemove = ["Accept-Ranges", "Content-Length", "Keep-Alive", "Connection", "content-encoding"]; +const responseHeadersToRemove = ["Accept-Ranges", "Content-Length", "Keep-Alive", "Connection", "content-encoding", "set-cookie"]; (async () => { let options = { @@ -78,18 +78,23 @@ const responseHeadersToRemove = ["Accept-Ranges", "Content-Length", "Keep-Alive" response = await page.waitForNavigation({ timeout: 30000, waitUntil: 'domcontentloaded' }); responseBody = await page.content(); responseHeaders = response.headers(); + const cookies = await page.cookies(); + if (cookies) + cookies.forEach(cookie => { + const { name, value, secure, expires, domain, ...options } = cookie; + ctx.cookies.set(cookie.name, cookie.value, options); + }); await page.close(); } catch (error) { if (!error.toString().includes("ERR_BLOCKED_BY_CLIENT")) throw (error); } responseHeadersToRemove.forEach(header => { - delete responseHeaders[header]; + delete responseHeaders[header]; }); Object.keys(responseHeaders).forEach(header => { - ctx.set(header, jsesc(responseHeaders[header])); + ctx.set(header, jsesc(responseHeaders[header])); }); - ctx.response.headers = responseHeaders; ctx.body = responseBody; } else { |