Skip to content

Commit

Permalink
perf(api-gateway-v2): faster getRequest method
Browse files Browse the repository at this point in the history
  • Loading branch information
H4ad committed Jun 7, 2023
1 parent 41339c6 commit 3b08708
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/adapters/aws/api-gateway-v2.adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
StripBasePathFn,
buildStripBasePath,
getEventBodyAsBuffer,
getFlattenedHeadersMap,
getFlattenedHeadersMapAndCookies,
getPathWithQueryStringParams,
} from '../../core';
Expand Down Expand Up @@ -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('; ');

Expand All @@ -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;
Expand Down

0 comments on commit 3b08708

Please sign in to comment.