-
Notifications
You must be signed in to change notification settings - Fork 59
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
if both isChunked and hasContentLength, set hasContentLength to false. #59
Conversation
Did you mean Do you have a site or example this fixes? Can you verify this doesn't break the previous issue this change was added to fix (I think it should be fine...). |
The pr is effective on node 8.x, but not on node 10.x. Maybe process.binding is deprecated. |
Thanks for posting an example, I'll take a closer look this weekend or early next week. process.binding should still be effective on Node 10 for the 'http_parser' binding, except when used in a child process/forked process, but might need to be changed to internalBinding instead in the future. |
If I use webpack 4.x + electron 3.x and set HTTPParser, it will throw "HPE_INVALID_METHOD" on main process and it is not effective on renderer process. Why? |
I don't know what those are, but if you're on Node 10.x, and it's something with child processes, it could be the Node 10.x issue I alluded to earlier (no longer able to override the process.binding of http_parser in child processes). For the "HPE_INVALID_METHOD", someone else reported getting that on Node 10.x, but never provided any details on how to reproduce. If you have a simple way to reproduce this and could add it to #57, that'd be great. |
Okay, I think this seems good, wanted to also clear this.body_bytes back to null to get it to completely ignore content-length. Behavior is now the same as in Chrome. The parser can no longer parse responses that have these two headers but have a non-chunked body, however, Chrome cannot either, and I think that's probably the less-common case. For my future reference, here's a super-simple server that serves the raw data of either case I used for testing: const net = require('net');
let server = new net.Server();
server.listen(8081);
server.on('connection', function (s) {
if (1) {
// Gives correct 13-byte response on Chrome
s.write([
'HTTP/1.1 200 OK',
'Transfer-Encoding: chunked',
'Content-Type: text/plain',
'Content-Length: 123',
'Connection: keep-alive',
'',
'7',
'thunk1\n',
'6',
'thunk2',
'0',
'',
'',
].join('\r\n'));
} else {
// Invalid chunked encoding on Chrome
s.write([
'HTTP/1.1 200 OK',
'Transfer-Encoding: chunked',
'Content-Type: text/plain',
'Content-Length: 13',
'Connection: keep-alive',
'',
'thunk1\nthunk2',
].join('\r\n'));
}
s.end();
}); The earlier example was confusing because Node's HTTP module handles writing all of chunked headers automatically, so the example was writing some extra stuff (the terminating "0\r\n\r\n" which was also being written by Node). |
// if both isChunked and hasContentLength, content length wins
// because it has been verified to match the body length already
// if both isChunked and hasContentLength, chunk wins
// Because Content-Length is the length of all chunk, when both isChunked and hasContentLength.
// The behavior is the same as chromium.
if (this.isChunked && hasContentLength) {
this.hasContentLength = false;
}