This repository has been archived by the owner on Jul 6, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 57
http2: add test for invalid pseudo headers #170
Open
yosuke-furukawa
wants to merge
1
commit into
nodejs:master
Choose a base branch
from
yosuke-furukawa:test_pseudo_header_error
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+54
−0
Open
Changes from all commits
Commits
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 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,54 @@ | ||
// Flags: --expose-http2 | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const http2 = require('http2'); | ||
const body = | ||
'Cannot set HTTP/2 pseudo-headers'; | ||
|
||
const invalidHeaders = [ | ||
{ key: ':status', value: 200 }, | ||
{ key: ':method', value: 'GET' }, | ||
{ key: ':path', value: '/' }, | ||
{ key: ':authority', value: 'example.com' }, | ||
{ key: ':scheme', value: 'http' } | ||
]; | ||
|
||
const checkServer = (invalidHeader, value) => { | ||
const server = http2.createServer((req, res) => { | ||
res.setHeader('foobar', 'baz'); | ||
res.setHeader('X-POWERED-BY', 'node-test'); | ||
try { | ||
res.setHeader(invalidHeader, value); | ||
} catch (e) { | ||
res.statusCode = 500; | ||
res.end(e.message); | ||
} | ||
}); | ||
|
||
server.listen(0, common.mustCall(() => { | ||
const client = http2.connect(`http://localhost:${server.address().port}`); | ||
const headers = { ':path': '/' }; | ||
const req = client.request(headers); | ||
req.on('response', common.mustCall((headers) => { | ||
assert.strictEqual(headers[':status'], 500); | ||
assert.strictEqual(headers['foobar'], 'baz'); | ||
assert.strictEqual(headers['x-powered-by'], 'node-test'); | ||
})); | ||
|
||
let data = ''; | ||
req.on('data', (d) => data += d); | ||
req.on('end', common.mustCall(() => { | ||
assert.strictEqual(body, data); | ||
server.close(); | ||
client.destroy(); | ||
})); | ||
req.end(); | ||
})); | ||
server.on('error', common.mustNotCall()); | ||
}; | ||
|
||
invalidHeaders.forEach(({ key, value }) => { | ||
checkServer(key, value); | ||
}); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should require a
setEncoding('utf8')
as it should come out asBuffer
here. I assume this test is passing, so maybe there is something else going on.cc @sebdeckers @jasnell
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that should not be. We should be moving buffers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nodejs/node@d515857 is very old. So, no there should be something else into play here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, I read that all wrong. (deleted previous confused messages)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mcollina String concatenation => type coercion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh that's fine then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just checked and
d
is in fact aBuffer
. We're still emitting buffers, not strings, from thedata
event. 😅There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sebdeckers The request from @mcollina is the right way to handle this, that’s what
setEncoding
is there for. In your example you are lucky it works, but if the chunks are e.g.Buffer([0x46, 0xc3])
andBuffer([0x96, 0x4f])
, the result isF��O
(edit: and notFÖO
, as it should be).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@addaleax Yep, absolutely agreed. I'm just saying there is no deeper bug; nothing else is broken in the codebase. Apologies for adding my own confusion to this discussion. 😖
@yosuke-furukawa Can you please add
res.setEncoding('utf8')
here?