Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: request.headers for http2 cannot be deepmerged #275

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ function fastifyMultipart (fastify, options, done) {

const req = this.raw

const busboyOptions = deepmerge.all([{ headers: req.headers }, options || {}, opts || {}])
const busboyOptions = deepmerge.all([{ headers: Object.assign({}, req.headers) }, options || {}, opts || {}])
const stream = busboy(busboyOptions)
let completed = false
let files = 0
Expand Down Expand Up @@ -316,7 +316,7 @@ function fastifyMultipart (fastify, options, done) {
let lastError = null
const request = this.raw
const busboyOptions = deepmerge.all([
{ headers: request.headers },
{ headers: Object.assign({}, request.headers) },
options,
opts
])
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"eslint-plugin-typescript": "^0.14.0",
"fastify": "^3.2.1",
"form-data": "^4.0.0",
"h2url": "^0.2.0",
"pre-commit": "^1.2.2",
"pump": "^3.0.0",
"readable-stream": "^3.6.0",
Expand Down
43 changes: 43 additions & 0 deletions test/multipart-http2.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use strict'

const test = require('tap').test
const FormData = require('form-data')
const Fastify = require('fastify')
const multipart = require('..')
const h2url = require('h2url')
const path = require('path')
const fs = require('fs')
const sendToWormhole = require('stream-wormhole')

const filePath = path.join(__dirname, '../README.md')

test('should respond when all files are processed', function (t) {
const fastify = Fastify({ http2: true })
t.teardown(fastify.close.bind(fastify))

fastify.register(multipart)

fastify.post('/', async function (req, reply) {
const parts = req.files()
for await (const part of parts) {
t.ok(part.file)
await sendToWormhole(part.file)
}
reply.code(200).send()
})

fastify.listen(0, async function () {
const url = `http://localhost:${fastify.server.address().port}`
const form = new FormData()

form.append('upload', fs.createReadStream(filePath))
form.append('upload2', fs.createReadStream(filePath))
form.append('hello', 'world')
form.append('willbe', 'dropped')

const res = await h2url.concat({ url, method: 'POST', headers: form.getHeaders(), body: form })

t.equal(res.headers[':status'], 200)
t.end()
})
})