Skip to content
Myr

Merge commit from fork

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

authored by Yusuke Wada · committed by GitHub · parent cd3f6f7 · Browse files · 2 files+54 added−23 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+54 added−23 removed

  • tests:+45 added−0 removed
  • other:+9 added−23 removed

2 files+54 added−23 removed

modified:src/adapter/aws-lambda/handler.test.ts+45 added
264 unmodified lines
265 header2: 'value1, value2, value3',266 })267 })268269 it('Should preserve every repeated header value for version 1.0 API Gateway event', () => {270 const event: LambdaEvent = {271 ...baseV1Event,272 headers: {273 'x-forwarded-for': '203.0.113.10',274 },275 multiValueHeaders: {276 'x-forwarded-for': ['203.0.113.1', '203.0.113.10'],277 },278 }279280 const processor = getProcessor(event)281 const request = processor.createRequest(event)282283 expect(request.headers.get('x-forwarded-for')).toEqual('203.0.113.1, 203.0.113.10')284 })285286 it('Should return valid Request object from version 2.0 API Gateway event', () => {287 const event: LambdaEvent = {288 ...baseV2Event,289 rawQueryString: 'parameter1=value1&parameter1=value2&parameter2=value',
79 unmodified lines
369 host: 'my-service-a1b2c3.x1y2z3.vpc-lattice-svcs.us-east-1.on.aws',370 })371 })372373 it('Should preserve every repeated header value for Lattice event', async () => {374 const event: LatticeProxyEventV2 = {375 version: '2.0',376 path: '/my/path',377 method: 'GET',378 headers: {379 host: ['example.test'],380 'x-forwarded-for': ['203.0.113.1', '203.0.113.10'],381 },382 queryStringParameters: {},383 body: null,384 isBase64Encoded: false,385 requestContext: {386 serviceNetworkArn: '',387 serviceArn: '',388 targetGroupArn: '',389 identity: {},390 region: 'us-east-1',391 timeEpoch: '1583348638390123',392 },393 }394395 const processor = getProcessor(event)396 const request = processor.createRequest(event)397398 expect(request.headers.get('x-forwarded-for')).toEqual('203.0.113.1, 203.0.113.10')399 })400401 describe('non-ASCII header value processing', () => {402 it('Should encode non-ASCII header values with encodeURIComponent', async () => {403 const event: LambdaEvent = {404 ...baseV1Event,
150 unmodified lines
modified:src/adapter/aws-lambda/handler.ts+9 added-23 removed
472 unmodified lines
473474 protected getHeaders(event: APIGatewayProxyEvent): Headers {475 const headers = new Headers()476 this.getCookies(event, headers)477 if (event.headers) {478 for (const [k, v] of Object.entries(event.headers)) {479 if (v) {480 headers.set(k, sanitizeHeaderValue(v))481 }482 }483 }477 if (event.multiValueHeaders) {478 for (const [k, values] of Object.entries(event.multiValueHeaders)) {479 if (values) {487 // avoid duplicating already set headers488 const foundK = headers.get(k)489 values.forEach((v) => {490 const sanitizedValue = sanitizeHeaderValue(v)491 return (492 (!foundK || !foundK.includes(sanitizedValue)) && headers.append(k, sanitizedValue)493 )494 })480 values.forEach((v) => headers.append(k, sanitizeHeaderValue(v)))481 }482 }483 }484 if (event.headers) {485 for (const [k, v] of Object.entries(event.headers)) {486 if (v && !headers.has(k)) {487 headers.set(k, sanitizeHeaderValue(v))488 }489 }490 }491 return headers492 }493494 protected setCookiesToResult(result: APIGatewayProxyResult, cookies: string[]): void {
104 unmodified lines
599600 if (event.headers) {601 for (const [k, values] of Object.entries(event.headers)) {602 if (values) {610 // avoid duplicating already set headers611 const foundK = headers.get(k)612 values.forEach((v) => {613 const sanitizedValue = sanitizeHeaderValue(v)614 return (615 (!foundK || !foundK.includes(sanitizedValue)) && headers.append(k, sanitizedValue)616 )617 })603 values.forEach((v) => headers.append(k, sanitizeHeaderValue(v)))604 }605 }606 }607
67 unmodified lines