Skip to content

Commit

Permalink
fix: treat form-data bodies as binary (#20144)
Browse files Browse the repository at this point in the history
  • Loading branch information
mlauinger authored Feb 17, 2022
1 parent 42b0fce commit 0d3e645
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/net-stubbing/lib/server/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions packages/net-stubbing/test/unit/util-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
})
})

3 comments on commit 0d3e645

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 0d3e645 Feb 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/9.5.1/linux-x64/circle-develop-0d3e645359b19a7e6399666c4465324d20b94112/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 0d3e645 Feb 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the win32 x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/9.5.1/win32-x64/circle-develop-0d3e645359b19a7e6399666c4465324d20b94112/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 0d3e645 Feb 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/9.5.1/darwin-x64/circle-develop-0d3e645359b19a7e6399666c4465324d20b94112/cypress.tgz

Please sign in to comment.