Skip to content
Myr

fix(lambda-edge-adapter): Support Alternate Domain Names and Multiple Cookies in Lambda@Edge (#3858)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* fix(lambda-edge): improve domain name detection Previously, only the CloudFront distribution name was used. Now, the Host header value is utilized for more accurate detection. * fix(lambda-edge): handle multiple Set-Cookie headers correctly Previously, only the last Set-Cookie header was returned. This update ensures all Set-Cookie headers are processed and returned as expected. * fix(lambda-edge): add host fallback detection for unusual request headers

authored by Kent Kwee · committed by GitHub · parent 0ef206b · Browse files · 2 files+93 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+93 added−3 removed

  • tests:+85 added−1 removed
  • other:+8 added−2 removed

2 files+93 added−3 removed

modified:src/adapter/lambda-edge/handler.test.ts+85 added-1 removed
modified:src/adapter/lambda-edge/handler.ts+8 added-2 removed
103 unmodified lines
104 */105const convertHeaders = (headers: Headers): CloudFrontHeaders => {106 const cfHeaders: CloudFrontHeaders = {}107 headers.forEach((value, key) => {108 cfHeaders[key.toLowerCase()] = [{ key: key.toLowerCase(), value }]108 cfHeaders[key.toLowerCase()] = [109 ...(cfHeaders[key.toLowerCase()] || []),110 { key: key.toLowerCase(), value },111 ]112 })113 return cfHeaders114}115
33 unmodified lines
149}150151const createRequest = (event: CloudFrontEdgeEvent): Request => {152 const queryString = event.Records[0].cf.request.querystring153 const host =154 event.Records[0].cf.request.headers?.host?.[0]?.value ||155 event.Records[0].cf.config.distributionDomainName150 const urlPath = `https://${event.Records[0].cf.config.distributionDomainName}${event.Records[0].cf.request.uri}`156 const urlPath = `https://${host}${event.Records[0].cf.request.uri}`157 const url = queryString ? `${urlPath}?${queryString}` : urlPath158159 const headers = new Headers()160 Object.entries(event.Records[0].cf.request.headers).forEach(([k, v]) => {
35 unmodified lines