Polly.JS doesn't encode multipart/form-data requests properly
See original GitHub issueDescription
This is a bug report.
Polly.JS appears to not send all of a multipart/form-data
request to servers when it captures the initial server response. Most servers return an error when they cannot parse multipart form boundaries in a request.
Update: Polly.JS doesn’t pass multipart/form-data bodies with the right encoding. See comments below.
Shareable Source
I created a minimal reproduction here that uses request to upload a file to a simple express server: https://github.com/swashcap/pollyjs-multipart-form-data-error
Error Message & Stack Trace
Most servers return an error when they cannot parse multipart form boundaries in a request. Polly.JS emits an error similar to:
PollyError: [Polly] [persister:fs] Cannot persist response for [GET] http://localhost:3001/ because the status code was 400 and `recordFailedRequests` is `false`
Config
I’m using setup-polly-jest to run tests in Node.js. Here’s the config:
const AdapterNodeHTTP = require('@pollyjs/adapter-node-http')
const PersisterFS = require('@pollyjs/persister-fs')
const path = require('path')
const { Polly } = require('@pollyjs/core')
const { setupPolly } = require('setup-polly-jest')
Polly.register(AdapterNodeHTTP)
Polly.register(PersisterFS)
// ...
describe('this great test', () => {
const context = setupPolly({
adapters: ['node-http'],
persister: 'fs'
})
// ...
})
(see the test here: https://github.com/swashcap/pollyjs-multipart-form-data-error/blob/master/src/upload.spec.js)
Dependencies
$ yarn list --pattern=polly --silent
├─ @pollyjs/adapter-node-http@2.6.2
├─ @pollyjs/adapter@2.6.0
├─ @pollyjs/core@2.6.2
├─ @pollyjs/node-server@2.6.0
├─ @pollyjs/persister-fs@2.6.2
├─ @pollyjs/persister@2.6.2
├─ @pollyjs/utils@2.6.0
└─ setup-polly-jest@0.5.2
Environment
$ node -e "var os=require('os');console.log('Node.js ' + process.version + '\n' + os.platform() + ' ' + os.release())"
Node.js v10.16.3
darwin 18.7.0
$ npm --version
6.9.0
$ yarn --version
1.17.3
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:8 (6 by maintainers)
Yes please 😃
No problem! We’re enjoying Polly.JS quite a bit 🙂
The goal would be to correct the
body
’s encoding when it’s sent to the upstream server inHttpAdapter#passthroughRequest
. Right now it’shex
, it should be decoded toutf8
.This should actually be a pretty small fix; shall I open a PR?