diff options
Diffstat (limited to 'packages/bun-lambda/runtime.ts')
-rwxr-xr-x | packages/bun-lambda/runtime.ts | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/packages/bun-lambda/runtime.ts b/packages/bun-lambda/runtime.ts index b4e08944d..ab03376f5 100755 --- a/packages/bun-lambda/runtime.ts +++ b/packages/bun-lambda/runtime.ts @@ -294,7 +294,6 @@ function formatBody(body?: string, isBase64Encoded?: boolean): string | null { } type HttpEventV1 = { - readonly version: "1.0"; readonly requestContext: { readonly requestId: string; readonly domainName: string; @@ -310,15 +309,12 @@ type HttpEventV1 = { }; function isHttpEventV1(event: any): event is HttpEventV1 { - return event.version === "1.0" && typeof event.requestContext === "object"; + return !event.Records && event.version !== "2.0" && event.version !== "0" && typeof event.requestContext === "object"; } function formatHttpEventV1(event: HttpEventV1): Request { const request = event.requestContext; const headers = new Headers(); - for (const [name, value] of Object.entries(event.headers)) { - headers.append(name, value); - } for (const [name, values] of Object.entries(event.multiValueHeaders ?? {})) { for (const value of values) { headers.append(name, value); @@ -327,9 +323,6 @@ function formatHttpEventV1(event: HttpEventV1): Request { const hostname = headers.get("Host") ?? request.domainName; const proto = headers.get("X-Forwarded-Proto") ?? "http"; const url = new URL(request.path, `${proto}://${hostname}/`); - for (const [name, value] of new URLSearchParams(event.queryStringParameters)) { - url.searchParams.append(name, value); - } for (const [name, values] of Object.entries(event.multiValueQueryStringParameters ?? {})) { for (const value of values ?? []) { url.searchParams.append(name, value); @@ -360,7 +353,7 @@ type HttpEventV2 = { }; function isHttpEventV2(event: any): event is HttpEventV2 { - return event.version === "2.0" && typeof event.requestContext === "object"; + return !event.Records && event.version === "2.0" && typeof event.requestContext === "object"; } function formatHttpEventV2(event: HttpEventV2): Request { @@ -389,6 +382,10 @@ function formatHttpEventV2(event: HttpEventV2): Request { }); } +function isHttpEvent(event: any): boolean { + return isHttpEventV1(event) || isHttpEventV2(event); +} + type WebSocketEvent = { readonly headers: Record<string, string>; readonly multiValueHeaders: Record<string, string[]>; @@ -538,7 +535,7 @@ class LambdaServer implements Server { statusCode: 200, }; } - if (!request?.headers.has("Host")) { + if (!isHttpEvent(event.event)) { return response.text(); } return formatResponse(response); |