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 4b2a015

Browse filesBrowse files
mcollinaMoLow
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 5ca437b commit 4b2a015
Copy full SHA for 4b2a015

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
@@ -1431,6 +1431,12 @@ Status code was outside the regular status code range (100-999).
14311431

14321432
The client has not sent the entire request within the allowed time.
14331433

1434+
<a id="ERR_HTTP_SOCKET_ASSIGNED"></a>
1435+
1436+
### `ERR_HTTP_SOCKET_ASSIGNED`
1437+
1438+
The given [`ServerResponse`][] was already assigned a socket.
1439+
14341440
<a id="ERR_HTTP_SOCKET_ENCODING"></a>
14351441

14361442
### `ERR_HTTP_SOCKET_ENCODING`
@@ -3565,6 +3571,7 @@ The native call from `process.cpuUsage` could not be processed.
35653571
[`Object.getPrototypeOf`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getPrototypeOf
35663572
[`Object.setPrototypeOf`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf
35673573
[`REPL`]: repl.md
3574+
[`ServerResponse`]: http.md#class-httpserverresponse
35683575
[`Writable`]: stream.md#class-streamwritable
35693576
[`child_process`]: child_process.md
35703577
[`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
@@ -76,6 +76,7 @@ const {
7676
ERR_HTTP_INVALID_STATUS_CODE,
7777
ERR_HTTP_SOCKET_ENCODING,
7878
ERR_INVALID_ARG_TYPE,
79+
ERR_HTTP_SOCKET_ASSIGNED,
7980
ERR_INVALID_ARG_VALUE,
8081
ERR_INVALID_CHAR,
8182
} = codes;
@@ -279,7 +280,9 @@ function onServerResponseClose() {
279280
}
280281

281282
ServerResponse.prototype.assignSocket = function assignSocket(socket) {
282-
assert(!socket._httpMessage);
283+
if (socket._httpMessage) {
284+
throw new ERR_HTTP_SOCKET_ASSIGNED();
285+
}
283286
socket._httpMessage = this;
284287
socket.on('close', onServerResponseClose);
285288
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.