-
-
Notifications
You must be signed in to change notification settings - Fork 756
fix: content-disposition header parsing #1911
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0c74f9c
fix: content-disposition header parsing
climba03003 90de7f3
test: fix the first header
climba03003 73bad73
refactor: update import
climba03003 5ff9962
refactor: transcode inside onHeadersComplete
climba03003 6a9b0ac
refactor: linting
climba03003 17b8995
fixup
ronag 8c6ec83
fixup: infinite loop
climba03003 34e3633
fixup
ronag dd78f51
test: fix node@12 support
climba03003 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,77 @@ | ||
| 'use strict' | ||
|
|
||
| const { createServer } = require('http') | ||
| const { test } = require('tap') | ||
| const { request } = require('..') | ||
|
|
||
| function createPromise () { | ||
| const result = {} | ||
| result.promise = new Promise((resolve) => { | ||
| result.resolve = resolve | ||
| }) | ||
| return result | ||
| } | ||
|
|
||
| test('should parse content-disposition consistencely', async (t) => { | ||
| t.plan(5) | ||
|
|
||
| // create promise to allow server spinup in parallel | ||
| const spinup1 = createPromise() | ||
| const spinup2 = createPromise() | ||
| const spinup3 = createPromise() | ||
|
|
||
| // variables to store content-disposition header | ||
| const header = [] | ||
|
|
||
| const server = createServer((req, res) => { | ||
| res.writeHead(200, { | ||
| 'content-length': 2, | ||
| 'content-disposition': "attachment; filename='år.pdf'" | ||
| }) | ||
| header.push("attachment; filename='år.pdf'") | ||
| res.end('OK', spinup1.resolve) | ||
| }) | ||
| t.teardown(server.close.bind(server)) | ||
| server.listen(0, spinup1.resolve) | ||
|
|
||
| const proxy1 = createServer(async (req, res) => { | ||
| const { statusCode, headers, body } = await request(`http://localhost:${server.address().port}`, { | ||
| method: 'GET' | ||
| }) | ||
| header.push(headers['content-disposition']) | ||
| delete headers['transfer-encoding'] | ||
| res.writeHead(statusCode, headers) | ||
| body.pipe(res) | ||
| }) | ||
| t.teardown(proxy1.close.bind(proxy1)) | ||
| proxy1.listen(0, spinup2.resolve) | ||
|
|
||
| const proxy2 = createServer(async (req, res) => { | ||
| const { statusCode, headers, body } = await request(`http://localhost:${proxy1.address().port}`, { | ||
| method: 'GET' | ||
| }) | ||
| header.push(headers['content-disposition']) | ||
| delete headers['transfer-encoding'] | ||
| res.writeHead(statusCode, headers) | ||
| body.pipe(res) | ||
| }) | ||
| t.teardown(proxy2.close.bind(proxy2)) | ||
| proxy2.listen(0, spinup3.resolve) | ||
|
|
||
| // wait until all server spinup | ||
| await Promise.all([spinup1.promise, spinup2.promise, spinup3.promise]) | ||
|
|
||
| const { statusCode, headers, body } = await request(`http://localhost:${proxy2.address().port}`, { | ||
| method: 'GET' | ||
| }) | ||
| header.push(headers['content-disposition']) | ||
| t.equal(statusCode, 200) | ||
| t.equal(await body.text(), 'OK') | ||
|
|
||
| // we check header | ||
| // must not be the same in first proxy | ||
| t.notSame(header[0], header[1]) | ||
| // chaining always the same value | ||
| t.equal(header[1], header[2]) | ||
| t.equal(header[2], header[3]) | ||
| }) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.