handler.test.ts
This file
Path
src/adapter/lambda-edge/handler.test.ts
122 lines · 3.6 KiB · TypeScript
Last changed by
fix(lambda-edge-adapter): Support Alternate Domain Names and Multiple Cookies in Lambda@Edge (#3858)Kent Kweebefore adoptiona1ae224
History of this fileTake it
The walk stopped after 200 commits: lines older than 81a1f07 point at it.
fix(lambda-edge-adapter): Support Alternate Domain Names and Multiple Cookies in Lambda@Edge (#3858)Kent Kweebefore adoptiona1ae224
lines 1–3why, one step back1import { describe } from 'vitest'2import { setCookie } from '../../helper/cookie'3import { Hono } from '../../hono'fix(validator): support multipart headers without a space separating boundary (#3286)Ernest Badubefore adoption81a1f07
line 4why, one step back4import { encodeBase64 } from '../../utils/encode'fix(lambda-edge-adapter): Support Alternate Domain Names and Multiple Cookies in Lambda@Edge (#3858)Kent Kweebefore adoptiona1ae224
lines 5–6why, one step back5import type { CloudFrontEdgeEvent } from './handler'6import { createBody, handle, isContentTypeBinary } from './handler'fix(validator): support multipart headers without a space separating boundary (#3286)Ernest Badubefore adoption81a1f07
lines 7–19why, one step back78describe('isContentTypeBinary', () => {9 it('Should determine whether it is binary', () => {10 expect(isContentTypeBinary('image/png')).toBe(true)11 expect(isContentTypeBinary('font/woff2')).toBe(true)12 expect(isContentTypeBinary('image/svg+xml')).toBe(false)13 expect(isContentTypeBinary('image/svg+xml; charset=UTF-8')).toBe(false)14 expect(isContentTypeBinary('text/plain')).toBe(false)15 expect(isContentTypeBinary('text/plain; charset=UTF-8')).toBe(false)16 expect(isContentTypeBinary('text/css')).toBe(false)17 expect(isContentTypeBinary('text/javascript')).toBe(false)18 expect(isContentTypeBinary('application/json')).toBe(false)19 expect(isContentTypeBinary('application/ld+json')).toBe(false)fix: Remove `charset` parameter from MIME type of `application/json` (#3743)SaekiTominagabefore adoptionbaa231e
line 20why, one step back20 expect(isContentTypeBinary('application/json')).toBe(false)fix(validator): support multipart headers without a space separating boundary (#3286)Ernest Badubefore adoption81a1f07
lines 21–40why, one step back21 })22})2324describe('createBody', () => {25 it('Should the request be a GET or HEAD, the Request must not include a Body', () => {26 const encoder = new TextEncoder()27 const data = encoder.encode('test')28 const body = {29 action: 'read-only',30 data: encodeBase64(data),31 encoding: 'base64',32 inputTruncated: false,33 }3435 expect(createBody('GET', body)).toEqual(undefined)36 expect(createBody('GET', body)).not.toEqual(data)37 expect(createBody('HEAD', body)).toEqual(undefined)38 expect(createBody('HEAD', body)).not.toEqual(data)39 expect(createBody('POST', body)).toEqual(data)40 expect(createBody('POST', body)).not.toEqual(undefined)fix(lambda-edge-adapter): Support Alternate Domain Names and Multiple Cookies in Lambda@Edge (#3858)Kent Kweebefore adoptiona1ae224
lines 41–120why, one step back41 })42})4344describe('handle', () => {45 const cloudFrontEdgeEvent: CloudFrontEdgeEvent = {46 Records: [47 {48 cf: {49 config: {50 distributionDomainName: 'd111111abcdef8.cloudfront.net',51 distributionId: 'EDFDVBD6EXAMPLE',52 eventType: 'viewer-request',53 requestId: '4TyzHTaYWb1GX1qTfsHhEqV6HUDd_BzoBZnwfnvQc_1oF26ClkoUSEQ==',54 },55 request: {56 clientIp: '1.2.3.4',57 headers: {58 host: [59 {60 key: 'Host',61 value: 'hono.dev',62 },63 ],64 accept: [65 {66 key: 'accept',67 value: '*/*',68 },69 ],70 },71 method: 'GET',72 querystring: '',73 uri: '/test-path',74 },75 },76 },77 ],78 }7980 it('Should support alternate domain names', async () => {81 const app = new Hono()82 app.get('/test-path', (c) => {83 return c.text(c.req.url)84 })85 const handler = handle(app)8687 const res = await handler(cloudFrontEdgeEvent)8889 expect(res.body).toBe('https://hono.dev/test-path')90 })9192 it('Should support multiple cookies', async () => {93 const app = new Hono()94 app.get('/test-path', (c) => {95 setCookie(c, 'cookie1', 'value1')96 setCookie(c, 'cookie2', 'value2')97 return c.text('')98 })99 const handler = handle(app)100101 const res = await handler(cloudFrontEdgeEvent)102103 expect(res.headers).toEqual({104 'content-type': [105 {106 key: 'content-type',107 value: 'text/plain; charset=UTF-8',108 },109 ],110 'set-cookie': [111 {112 key: 'set-cookie',113 value: 'cookie1=value1; Path=/',114 },115 {116 key: 'set-cookie',117 value: 'cookie2=value2; Path=/',118 },119 ],120 })fix(validator): support multipart headers without a space separating boundary (#3286)Ernest Badubefore adoption81a1f07
lines 121–122why, one step back121 })122})