Skip to content

Commit

Permalink
rewrite set cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
taichunmin committed Sep 13, 2024
1 parent abd8c53 commit 251d58d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ const middlewares = [
}
_.each(OMIT_RES_HEADERS, header => { ctx.res.removeHeader(header) })
const axiosRes = await axios(axiosConfig)

// Rewrite Set-Cookie header
_.update(res, 'headers.set-cookie', cookies => {
const rewriteCookie = cookie => cookie.replaceAll(/; (Secure|Partitioned|SameSite=[^;]+)/imsg, '') + '; SameSite=None; Secure; Partitioned'
return _.isArray(cookies) ? _.map(cookies, rewriteCookie) : rewriteCookie(cookies)
})
for (const cookie of res.headers['set-cookie'] ?? []) {}

ctx.res.status(axiosRes.status).header(axiosRes.headers)
if (NODE_ENV !== 'production') {
exports.log({
Expand Down

0 comments on commit 251d58d

Please sign in to comment.