Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 96f93cc

Browse filesBrowse files
mcollinatargos
authored andcommitted
http: remove internal error in assignSocket
Change ServerResponse.assignSocket to not throw an internal error, but an error with its own code. Signed-off-by: Matteo Collina <hello@matteocollina.com> PR-URL: #47723 Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
1 parent 30af5ce commit 96f93cc
Copy full SHA for 96f93cc

File tree

Expand file treeCollapse file tree

4 files changed

+19
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+19
-1
lines changed
Open diff view settings
Collapse file

‎doc/api/errors.md‎

Copy file name to clipboardExpand all lines: doc/api/errors.md
+7Lines changed: 7 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1438,6 +1438,12 @@ Status code was outside the regular status code range (100-999).
14381438

14391439
The client has not sent the entire request within the allowed time.
14401440

1441+
<a id="ERR_HTTP_SOCKET_ASSIGNED"></a>
1442+
1443+
### `ERR_HTTP_SOCKET_ASSIGNED`
1444+
1445+
The given [`ServerResponse`][] was already assigned a socket.
1446+
14411447
<a id="ERR_HTTP_SOCKET_ENCODING"></a>
14421448

14431449
### `ERR_HTTP_SOCKET_ENCODING`
@@ -3590,6 +3596,7 @@ The native call from `process.cpuUsage` could not be processed.
35903596
[`Object.getPrototypeOf`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getPrototypeOf
35913597
[`Object.setPrototypeOf`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf
35923598
[`REPL`]: repl.md
3599+
[`ServerResponse`]: http.md#class-httpserverresponse
35933600
[`Writable`]: stream.md#class-streamwritable
35943601
[`child_process`]: child_process.md
35953602
[`cipher.getAuthTag()`]: crypto.md#ciphergetauthtag
Collapse file

‎lib/_http_server.js‎

Copy file name to clipboardExpand all lines: lib/_http_server.js
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ const {
7575
ERR_HTTP_HEADERS_SENT,
7676
ERR_HTTP_INVALID_STATUS_CODE,
7777
ERR_HTTP_SOCKET_ENCODING,
78+
ERR_HTTP_SOCKET_ASSIGNED,
7879
ERR_INVALID_ARG_VALUE,
7980
ERR_INVALID_CHAR,
8081
} = codes;
@@ -276,7 +277,9 @@ function onServerResponseClose() {
276277
}
277278

278279
ServerResponse.prototype.assignSocket = function assignSocket(socket) {
279-
assert(!socket._httpMessage);
280+
if (socket._httpMessage) {
281+
throw new ERR_HTTP_SOCKET_ASSIGNED();
282+
}
280283
socket._httpMessage = this;
281284
socket.on('close', onServerResponseClose);
282285
this.socket = socket;
Collapse file

‎lib/internal/errors.js‎

Copy file name to clipboardExpand all lines: lib/internal/errors.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,8 @@ E('ERR_HTTP_INVALID_HEADER_VALUE',
11671167
'Invalid value "%s" for header "%s"', TypeError);
11681168
E('ERR_HTTP_INVALID_STATUS_CODE', 'Invalid status code: %s', RangeError);
11691169
E('ERR_HTTP_REQUEST_TIMEOUT', 'Request timeout', Error);
1170+
E('ERR_HTTP_SOCKET_ASSIGNED',
1171+
'ServerResponse has an already assigned socket', Error);
11701172
E('ERR_HTTP_SOCKET_ENCODING',
11711173
'Changing the socket encoding is not allowed per RFC7230 Section 3.', Error);
11721174
E('ERR_HTTP_TRAILER_INVALID',
Collapse file

‎test/parallel/test-http-server-response-standalone.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-http-server-response-standalone.js
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,10 @@ const ws = new Writable({
3131

3232
res.assignSocket(ws);
3333

34+
assert.throws(function() {
35+
res.assignSocket(ws);
36+
}, {
37+
code: 'ERR_HTTP_SOCKET_ASSIGNED'
38+
});
39+
3440
res.end('hello world');

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.