Skip to content
Myr

fix(aws-lambda): serve microsoft office files as binary in lambda handler (#4469)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* fix: serve microsoft office files as binary in lambda handler * incorporated suggested changes * updated Regex * added more test cases

authored by Matthias Feist · committed by GitHub · parent 0c6455d · Browse files · 2 files+20 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+20 added−13 removed

  • tests:+19 added−12 removed
  • other:+1 added−1 removed

2 files+20 added−13 removed

modified:src/adapter/aws-lambda/handler.test.ts+19 added-12 removed
79 unmodified lines
80 stageVariables: {},81}8283describe('isContentTypeBinary', () => {84 it('Should determine whether it is binary', () => {85 expect(defaultIsContentTypeBinary('image/png')).toBe(true)86 expect(defaultIsContentTypeBinary('font/woff2')).toBe(true)87 expect(defaultIsContentTypeBinary('image/svg+xml')).toBe(false)88 expect(defaultIsContentTypeBinary('image/svg+xml; charset=UTF-8')).toBe(false)89 expect(defaultIsContentTypeBinary('text/plain')).toBe(false)90 expect(defaultIsContentTypeBinary('text/plain; charset=UTF-8')).toBe(false)91 expect(defaultIsContentTypeBinary('text/css')).toBe(false)92 expect(defaultIsContentTypeBinary('text/javascript')).toBe(false)93 expect(defaultIsContentTypeBinary('application/json')).toBe(false)94 expect(defaultIsContentTypeBinary('application/ld+json')).toBe(false)95 expect(defaultIsContentTypeBinary('application/json')).toBe(false)84 it.each([85 ['image/png', true],86 ['font/woff2', true],87 ['image/svg+xml', false],88 ['image/svg+xml; charset=UTF-8', false],89 ['text/plain', false],90 ['text/plain; charset=UTF-8', false],91 ['text/css', false],92 ['text/javascript', false],93 ['application/json', false],94 ['application/ld+json', false],95 ['application/json', false],96 ['application/vnd.openxmlformats-officedocument.wordprocessingml.document', true],97 ['application/msword', true],98 ['application/epub+zip', true],99 ['application/ld+json', false],100 ['application/vnd.oasis.opendocument.text', true],101 ])('Should determine whether %s it is binary', (mimeType: string, expected: boolean) => {102 expect(defaultIsContentTypeBinary(mimeType)).toBe(expected)103 })104})105106describe('isContentEncodingBinary', () => {
210 unmodified lines
modified:src/adapter/aws-lambda/handler.ts+1 added-1 removed
562 unmodified lines
563 * @param contentType The content type to check.564 * @returns True if the content type is binary, false otherwise.565 */566export const defaultIsContentTypeBinary = (contentType: string): boolean => {567 return !/^(text\/(plain|html|css|javascript|csv).*|application\/(.*json|.*xml).*|image\/svg\+xml.*)$/.test(567 return !/^text\/(?:plain|html|css|javascript|csv)|(?:\/|\+)(?:json|xml)\s*(?:;|$)/.test(568 contentType569 )570}571
6 unmodified lines