summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmilien Devos <contact@emiliendevos.be>2020-05-24 01:01:16 +0200
committerEmilien Devos <contact@emiliendevos.be>2020-05-24 01:01:16 +0200
commit159431aea3c73b75fe42991358894b5463907cbe (patch)
treeb1cd6c312a80d00eb82d5cdfb72b930425c12234
parent2bfe081a7f582015f3e4f5cf9aa98c349182276f (diff)
handle response headers + cookies
-rw-r--r--index.js13
1 files changed, 9 insertions, 4 deletions
diff --git a/index.js b/index.js
index af7425b..ec91cb7 100644
--- a/index.js
+++ b/index.js
@@ -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 {