From 3b087087af1873414c85c8db09b5867c0752ab56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Louren=C3=A7o?= Date: Sat, 13 May 2023 14:24:04 -0300 Subject: [PATCH] perf(api-gateway-v2): faster getRequest method --- src/adapters/aws/api-gateway-v2.adapter.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/adapters/aws/api-gateway-v2.adapter.ts b/src/adapters/aws/api-gateway-v2.adapter.ts index 76d26165..770c4b9f 100644 --- a/src/adapters/aws/api-gateway-v2.adapter.ts +++ b/src/adapters/aws/api-gateway-v2.adapter.ts @@ -12,7 +12,6 @@ import { StripBasePathFn, buildStripBasePath, getEventBodyAsBuffer, - getFlattenedHeadersMap, getFlattenedHeadersMapAndCookies, getPathWithQueryStringParams, } from '../../core'; @@ -109,8 +108,10 @@ export class ApiGatewayV2Adapter public getRequest(event: APIGatewayProxyEventV2): AdapterRequest { const method = event.requestContext.http.method; const path = this.getPathFromEvent(event); - - const headers = getFlattenedHeadersMap(event.headers, ',', true); + // accords https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html + // all headers are lowercased and cannot be array + // so no need to format, just a shallow copy will work here + const headers = { ...event.headers }; if (event.cookies) headers.cookie = event.cookies.join('; '); @@ -123,7 +124,8 @@ export class ApiGatewayV2Adapter ); body = bufferBody; - headers['content-length'] = String(contentLength); + // eslint-disable-next-line @typescript-eslint/restrict-plus-operands + headers['content-length'] = contentLength + ''; } const remoteAddress = event.requestContext.http.sourceIp;