-
-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: request.headers for http2 cannot be deepmerged
node http2 server initializes headers with Object.create(null) and they not have the propertyIsEnumerable method. This method is needed by deepmerge. Also added unit test for http2 request.
- Loading branch information
Christian van der Leeden
committed
Oct 5, 2021
1 parent
a9d7d8b
commit b526314
Showing
3 changed files
with
46 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}) | ||
}) |