fix(lambda-edge): sync content type detection with aws-lambda (#5426)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by sary · committed by GitHub · parent 28e8572 · Browse files · 2 files·+30 added−13 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+30 added−13 removed
- tests:+25 added−12 removed
- other:+5 added−1 removed
Provenance
- Commit
de310ac- Tree
bc3c94d- Author
sary <132046562+sary8@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
28e8572
2 files changed+30 added−13 removed
modified:src/adapter/lambda-edge/handler.test.ts+25 added-12 removed
5 unmodified lines6 import type { Callback, CloudFrontEdgeEvent, CloudFrontRequest } from './handler'7 import { createBody, handle, isContentTypeBinary } from './handler'8 9 describe('isContentTypeBinary', () => {10- it('Should determine whether it is binary', () => {11- expect(isContentTypeBinary('image/png')).toBe(true)12- expect(isContentTypeBinary('font/woff2')).toBe(true)13- expect(isContentTypeBinary('image/svg+xml')).toBe(false)14- expect(isContentTypeBinary('image/svg+xml; charset=UTF-8')).toBe(false)15- expect(isContentTypeBinary('text/plain')).toBe(false)16- expect(isContentTypeBinary('text/plain; charset=UTF-8')).toBe(false)17- expect(isContentTypeBinary('text/css')).toBe(false)18- expect(isContentTypeBinary('text/javascript')).toBe(false)19- expect(isContentTypeBinary('application/json')).toBe(false)20- expect(isContentTypeBinary('application/ld+json')).toBe(false)21- expect(isContentTypeBinary('application/json')).toBe(false)10+ it.each([11+ ['image/png', true],12+ ['font/woff2', true],13+ ['image/svg+xml', false],14+ ['image/svg+xml; charset=UTF-8', false],15+ ['text/plain', false],16+ ['text/plain; charset=UTF-8', false],17+ ['text/css', false],18+ ['text/javascript', false],19+ ['application/json', false],20+ ['application/ld+json', false],21+ ['application/json', false],22+ ['application/vnd.openxmlformats-officedocument.wordprocessingml.document', true],23+ ['application/msword', true],24+ ['application/epub+zip', true],25+ ['application/ld+json', false],26+ ['application/vnd.oasis.opendocument.text', true],27+ ['application/vnd.apple.installer+xml', true],28+ ['application/vnd.apple.installer+xml; charset=UTF-8', true],29+ ['application/vnd.mozilla.xul+xml', true],30+ ['APPLICATION/VND.APPLE.INSTALLER+XML', true],31+ ['APPLICATION/JSON', false],32+ ['TEXT/PLAIN', false],33+ ])('Should determine whether %s it is binary', (mimeType: string, expected: boolean) => {34+ expect(isContentTypeBinary(mimeType)).toBe(expected)35 })36 })37 38 describe('createBody', () => {342 unmodified linesmodified:src/adapter/lambda-edge/handler.ts+5 added-1 removed
210 unmodified lines211 return requestBody.data212 }213 214 export const isContentTypeBinary = (contentType: string): boolean => {215- return !/^(text\/(plain|html|css|javascript|csv).*|application\/(.*json|.*xml).*|image\/svg\+xml.*)$/.test(215+ if (/^application\/vnd\.(?:apple\.installer|mozilla\.xul)\+xml\s*(?:;|$)/i.test(contentType)) {216+ return true217+ }218+219+ return !/^text\/(?:plain|html|css|javascript|csv)|(?:\/|\+)(?:json|xml)\s*(?:;|$)/i.test(220 contentType221 )222 }