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.

* 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

2 files+61 added−4 removed

modified:src/adapter/aws-lambda/handler.test.ts+58 added
1import { setCookie } from '../../helper/cookie'2import { Hono } from '../../hono'3import type { LambdaEvent, LatticeProxyEventV2 } from './handler'4import {5 getProcessor,
390 unmodified lines
396 expect(result.statusCode).toBe(400)397 expect(result.body).toBe('Invalid request')398 })399400 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)408409 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 LambdaEvent417418 const result = await handler(event)419420 expect(result.headers!['set-cookie']).toBe(421 'session=abc123; Path=/; Expires=Tue, 09 Jun 2026 00:00:00 GMT'422 )423 })424425 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)433434 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 }451452 const result = await handler(event)453454 expect(result.headers!['set-cookie']).toEqual(['session=abc123; Path=/', 'csrf=xyz789; Path=/'])455 })456457 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 lines
modified:src/adapter/aws-lambda/handler.ts+3 added-4 removed
95 unmodified lines
96 requestContext: ALBRequestContext97}9899type WithHeaders = {100 headers: Record<string, string>100 headers: Record<string, string | string[]>101 multiValueHeaders?: undefined102}103type WithMultiValueHeaders = {104 headers?: undefined
471 unmodified lines
576 // 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 lines
624625 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