Merge commit from fork
Before adoption: this commit came in with the history the project adopted, so no landing records it.
* fix(aws-lambda): preserve multiple Set-Cookie headers instead of joining with `, ` * format
authored by Yusuke Wada · committed by GitHub · parent 1b13848 · Browse files · 2 files·+61 added−4 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+61 added−4 removed
- tests:+58 added−0 removed
- other:+3 added−4 removed
Provenance
- Commit
7ae7cba- Tree
c5bd430- Author
Yusuke Wada <yusuke@kamawada.com>- Committer
GitHub <noreply@github.com>- Parent
1b13848
2 files changed+61 added−4 removed
modified:src/adapter/aws-lambda/handler.test.ts+58 added
1+import { setCookie } from '../../helper/cookie'2 import { Hono } from '../../hono'3 import type { LambdaEvent, LatticeProxyEventV2 } from './handler'4 import {5 getProcessor,390 unmodified lines396 expect(result.statusCode).toBe(400)397 expect(result.body).toBe('Invalid request')398 })399 400+ it('ALB single-header: emits the first Set-Cookie intact, never comma-joined', async () => {401+ const app = new Hono()402+ app.get('/multi-cookie', (c) => {403+ setCookie(c, 'session', 'abc123', { expires: new Date('2026-06-09T00:00:00Z') })404+ setCookie(c, 'csrf', 'xyz789', { expires: new Date('2026-06-10T00:00:00Z') })405+ return c.text('ok')406+ })407+ const handler = handle(app)408+409+ const event = {410+ httpMethod: 'GET',411+ path: '/multi-cookie',412+ headers: { host: 'app.example.com' },413+ body: null,414+ isBase64Encoded: false,415+ requestContext: { elb: { targetGroupArn: 'arn:aws:elasticloadbalancing:...' } },416+ } as unknown as LambdaEvent417+418+ const result = await handler(event)419+420+ expect(result.headers!['set-cookie']).toBe(421+ 'session=abc123; Path=/; Expires=Tue, 09 Jun 2026 00:00:00 GMT'422+ )423+ })424+425+ it('Lattice v2: emits multiple Set-Cookie as an array', async () => {426+ const app = new Hono()427+ app.get('/multi-cookie', (c) => {428+ setCookie(c, 'session', 'abc123')429+ setCookie(c, 'csrf', 'xyz789')430+ return c.text('ok')431+ })432+ const handler = handle(app)433+434+ const event: LatticeProxyEventV2 = {435+ version: '2.0',436+ path: '/multi-cookie',437+ method: 'GET',438+ headers: { host: ['app.example.com'] },439+ queryStringParameters: {},440+ body: null,441+ isBase64Encoded: false,442+ requestContext: {443+ serviceNetworkArn: '',444+ serviceArn: 'arn:aws:vpc-lattice:us-east-1:123456789012:service/svc-0a40',445+ targetGroupArn: '',446+ identity: {},447+ region: 'us-east-1',448+ timeEpoch: '1583348638390123',449+ },450+ }451+452+ const result = await handler(event)453+454+ expect(result.headers!['set-cookie']).toEqual(['session=abc123; Path=/', 'csrf=xyz789; Path=/'])455+ })456+457 it('Should return 400 when request contains invalid header names (v1)', async () => {458 const app = new Hono()459 app.get('/my/path', (c) => c.text('Hello'))460 const handler = handle(app)16 unmodified linesmodified:src/adapter/aws-lambda/handler.ts+3 added-4 removed
95 unmodified lines96 requestContext: ALBRequestContext97 }98 99 type WithHeaders = {100- headers: Record<string, string>100+ headers: Record<string, string | string[]>101 multiValueHeaders?: undefined102 }103 type WithMultiValueHeaders = {104 headers?: undefined471 unmodified lines576 // when multi value headers is enabled577 if (result.multiValueHeaders) {578 result.multiValueHeaders['set-cookie'] = cookies579 } else {580- // otherwise serialize the set-cookie581- result.headers['set-cookie'] = cookies.join(', ')580+ result.headers['set-cookie'] = cookies[0]581 }582 }583 }584 39 unmodified lines624 625 protected setCookiesToResult(result: APIGatewayProxyResult, cookies: string[]): void {626 result.headers = {627 ...result.headers,629- 'set-cookie': cookies.join(', '),628+ 'set-cookie': cookies,629 }630 }631 }632 52 unmodified lines