Skip to content

Commit 0d3e645

Browse files
authored
fix: treat form-data bodies as binary (#20144)
1 parent 42b0fce commit 0d3e645

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

packages/net-stubbing/lib/server/util.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,10 @@ export function getBodyEncoding (req: CyHttpMessages.IncomingRequest): BodyEncod
251251
if (contentType.includes('charset=utf-8') || contentType.includes('charset="utf-8"')) {
252252
return 'utf8'
253253
}
254+
255+
if (contentType.includes('multipart/form-data')) {
256+
return 'binary'
257+
}
254258
}
255259

256260
// with fallback to inspecting the buffer using

packages/net-stubbing/test/unit/util-spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,19 @@ describe('net-stubbing util', () => {
6969

7070
expect(getBodyEncoding(req), 'image').to.equal('binary')
7171
})
72+
73+
it('returns binary for form-data bodies', () => {
74+
const formDataRequest = {
75+
body: Buffer.from('hello world'),
76+
headers: {
77+
'content-type': 'multipart/form-data',
78+
},
79+
method: 'POST',
80+
url: 'somewhere',
81+
httpVersion: '1.1',
82+
}
83+
84+
expect(getBodyEncoding(formDataRequest)).to.equal('binary')
85+
})
7286
})
7387
})

0 commit comments

Comments
 (0)