-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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: setEncoding error for incoming socket connections #19344
Changes from all commits
a7e2aab
345ff3c
4643c63
f3c429c
3613e8d
190ef7e
06a34eb
cd2c3ce
a8c605e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,7 @@ const { | |
const { IncomingMessage } = require('_http_incoming'); | ||
const { | ||
ERR_HTTP_HEADERS_SENT, | ||
ERR_HTTP_INCOMING_SOCKET_ENCODING, | ||
ERR_HTTP_INVALID_STATUS_CODE, | ||
ERR_INVALID_CHAR | ||
} = require('internal/errors').codes; | ||
|
@@ -380,6 +381,7 @@ function connectionListenerInternal(server, socket) { | |
|
||
// Override on to unconsume on `data`, `readable` listeners | ||
socket.on = socketOnWrap; | ||
socket.setEncoding = socketSetEncoding; | ||
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. nit: either a comment or a new line here would be nice, since this line isn't related to // Override on to unconsume on `data`, `readable` listeners 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. I agree, because I didn't see that done in |
||
|
||
// We only consume the socket if it has never been consumed before. | ||
if (socket._handle) { | ||
|
@@ -694,6 +696,10 @@ function onSocketPause() { | |
} | ||
} | ||
|
||
function socketSetEncoding() { | ||
throw new ERR_HTTP_INCOMING_SOCKET_ENCODING('setEncoding'); | ||
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. There is no dynamic argument in this error, so there is no need to pass through any arguments. |
||
} | ||
|
||
function unconsume(parser, socket) { | ||
if (socket._handle) { | ||
if (parser._consumed) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const http = require('http'); | ||
|
||
const server = http.createServer().listen(0, connectToServer); | ||
|
||
server.on('connection', (socket) => { | ||
common.expectsError(() => socket.setEncoding(''), | ||
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. I think you might still be testing the old But maybe I'm missing something else that's off about this... not sure. It is throwing an AssertionError though. 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. That For example:
is ok to do. It's only "pre-parse" attempts to manipulate the incoming buffer 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. Yeah, you can ignore me. It's complaining about the fact that you're providing an argument to the error, as mentioned above by @BridgeAR. But if you're saying it's ok then this PR isn't quite valid because calling that 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. But also this isn't strictly correct. It's definitely not OK to call 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. Hmm. Do you know any history behind Right now I override 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. Sorry, we got our wires crossed. I'm just referencing this bit...
It would throw throughout the requests lifetime. Sockets that are used for http should never have their encoding changed. I'm just saying that this is also correct behaviour. To simplify: I'm fine with this PR as is except for the linting issue and the one pointed out by @BridgeAR. 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. This comment from @addaleax on the original PR suggests there are other uses of There's a slight chance it could be necessary when using abstract protocols such as So this would require moving 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. @iSkore Thanks for the link. I might need to think about this more. I think that particular use-case would be addressed by resetting the socket |
||
{ | ||
code: 'ERR_HTTP_INCOMING_SOCKET_ENCODING', | ||
type: Error | ||
}); | ||
|
||
socket.end(); | ||
}); | ||
|
||
function connectToServer() { | ||
const client = new http.Agent().createConnection(this.address().port, () => { | ||
client.end(); | ||
}) | ||
.on('end', () => server.close()); | ||
} |
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 added new line has to be removed again.