-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
http: interpret strings as utf8 #2629
Closed
Closed
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
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,28 @@ | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about 'use strict';
const common = require('../common');
const assert = require('assert');
const http = require('http');
http.createServer(common.mustCall(function(req, res) {
res.end();
this.close();
assert.equal(req.url, '/?тест');
assert.equal(req.headers['x-test'], 'тест');
})).listen(common.PORT, function() {
http.request({
port: common.PORT,
path: new Buffer('/?тест').toString('binary'),
headers: {
'x-test': new Buffer('тест').toString('binary')
}
}).end();
}); |
||
'use strict'; | ||
var common = require('../common'); | ||
var assert = require('assert'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use |
||
|
||
var http = require('http'); | ||
|
||
var req; | ||
|
||
process.on('exit', function() { | ||
assert.equal(req.url, '/?тест'); | ||
assert.equal(req.headers['x-test'], 'тест'); | ||
}); | ||
|
||
|
||
http.createServer(function(req_, res) { | ||
req = req_; | ||
res.end(); | ||
this.close(); | ||
}).listen(common.PORT, function() { | ||
http.request({ | ||
port: common.PORT, | ||
path: new Buffer('/?тест').toString('binary'), | ||
headers: { | ||
'x-test': new Buffer('тест').toString('binary') | ||
} | ||
}).end(); | ||
}); |
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.
Besides the question "is this more correct?", I am curious about the performance impact this may have.
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.
The benchmarks would be bias in out current benchmarks. We need to set some up that have various header lengths.
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.
I'm curious too though, aren't HTTP headers supposed to be ASCII and not unicode?
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.
@bnoordhuis gave an explanation here: #1693 (comment). Basically that most headers use US-ASCII, but traditionally ISO-8859-1 (i.e. latin-1) is allowed. latin-1 is the encoding returned by
OneByteString()
. So is what we currently use. Note that ASCII is a subset of latin-1.While our current implementation is definitely faster, there's a problem with developers/companies moving from v0.10 to v4 LTS being hit by the change in functionality. Any solution outside of what we currently use will be a performance hit. How much will depend on the chosen solution.
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.
So going with what Ben said, why the change to
String::NewFromUtf8
? Does v0.10 read UTF-8 strings 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.
@ronkorving Yes. v0.10 reads in headers as utf-8. Which is incorrect per the specification.
Thing is, if everyone followed US-ASCII then functionally we wouldn't notice a difference. It's not until someone uses the full latin-1 encoding (which is spec compliant) that they'd experience issues.
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.
Got it, thanks.