fix: treat form-data bodies as binary (#20144)

This commit is contained in:
Marco Lauinger
2022-02-17 19:20:33 +01:00
committed by GitHub
parent 42b0fce6dc
commit 0d3e645359
2 changed files with 18 additions and 0 deletions
+4
View File
@@ -251,6 +251,10 @@ export function getBodyEncoding (req: CyHttpMessages.IncomingRequest): BodyEncod
if (contentType.includes('charset=utf-8') || contentType.includes('charset="utf-8"')) {
return 'utf8'
}
if (contentType.includes('multipart/form-data')) {
return 'binary'
}
}
// with fallback to inspecting the buffer using
@@ -69,5 +69,19 @@ describe('net-stubbing util', () => {
expect(getBodyEncoding(req), 'image').to.equal('binary')
})
it('returns binary for form-data bodies', () => {
const formDataRequest = {
body: Buffer.from('hello world'),
headers: {
'content-type': 'multipart/form-data',
},
method: 'POST',
url: 'somewhere',
httpVersion: '1.1',
}
expect(getBodyEncoding(formDataRequest)).to.equal('binary')
})
})
})