Skip to content

Commit 5bdb794

Browse files
committed
[fixup] add documentation, adjust error message, tweak proxy
1 parent eaa71a1 commit 5bdb794

File tree

7 files changed

+28
-30
lines changed

7 files changed

+28
-30
lines changed

doc/api/errors.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -810,8 +810,8 @@ reached.
810810
<a id="ERR_HTTP2_NO_SOCKET_MANIPULATION"></a>
811811
### ERR_HTTP2_NO_SOCKET_MANIPULATION
812812

813-
Used when attempting to read, write, pause, and/or resume a socket attached to
814-
an `Http2Session`.
813+
Used when attempting to directly manipulate (e.g read, write, pause, resume,
814+
etc.) a socket attached to an `Http2Session`.
815815

816816
<a id="ERR_HTTP2_OUT_OF_STREAMS"></a>
817817
### ERR_HTTP2_OUT_OF_STREAMS

doc/api/http2.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -463,12 +463,16 @@ added: v8.4.0
463463

464464
* Value: {net.Socket|tls.TLSSocket}
465465

466-
A reference to the [`net.Socket`][] or [`tls.TLSSocket`][] to which this
467-
`Http2Session` instance is bound.
466+
Returns a Proxy object that acts as a `net.Socket` (or `tls.TLSSocket`) but
467+
limits available methods to ones safe to use with HTTP/2.
468468

469-
*Note*: It is not recommended for user code to interact directly with a
470-
`Socket` bound to an `Http2Session`. See [Http2Session and Sockets][] for
471-
details.
469+
`destroy`, `emit`, `end`, `pause`, `read`, `resume`, and `write` will throw
470+
an error with code `ERR_HTTP2_NO_SOCKET_MANIPULATION`. See
471+
[Http2Session and Sockets][] for more information.
472+
473+
`setTimeout` method will be called on this `Http2Session`.
474+
475+
All other interactions will be routed directly to the socket.
472476

473477
#### http2session.state
474478
<!-- YAML
@@ -2138,10 +2142,10 @@ Returns `request`.
21382142
added: v8.4.0
21392143
-->
21402144

2141-
* {net.Socket}
2145+
* {net.Socket|tls.TLSSocket}
21422146

2143-
Returns a Proxy object that acts as a `net.Socket` but applies getters,
2144-
setters and methods based on HTTP/2 logic.
2147+
Returns a Proxy object that acts as a `net.Socket` (or `tls.TLSSocket`) but
2148+
applies getters, setters and methods based on HTTP/2 logic.
21452149

21462150
`destroyed`, `readable`, and `writable` properties will be retrieved from and
21472151
set on `request.stream`.
@@ -2293,7 +2297,7 @@ will result in a [`TypeError`][] being thrown.
22932297
added: v8.4.0
22942298
-->
22952299

2296-
* {net.Socket}
2300+
* {net.Socket|tls.TLSSocket}
22972301

22982302
See [`response.socket`][].
22992303

@@ -2510,10 +2514,10 @@ Returns `response`.
25102514
added: v8.4.0
25112515
-->
25122516

2513-
* {net.Socket}
2517+
* {net.Socket|tls.TLSSocket}
25142518

2515-
Returns a Proxy object that acts as a `net.Socket` but applies getters,
2516-
setters and methods based on HTTP/2 logic.
2519+
Returns a Proxy object that acts as a `net.Socket` (or `tls.TLSSocket`) but
2520+
applies getters, setters and methods based on HTTP/2 logic.
25172521

25182522
`destroyed`, `readable`, and `writable` properties will be retrieved from and
25192523
set on `response.stream`.

lib/internal/errors.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,7 @@ E('ERR_HTTP2_INVALID_STREAM', 'The stream has been destroyed');
208208
E('ERR_HTTP2_MAX_PENDING_SETTINGS_ACK',
209209
(max) => `Maximum number of pending settings acknowledgements (${max})`);
210210
E('ERR_HTTP2_NO_SOCKET_MANIPULATION',
211-
'HTTP/2 sockets should not be directly read from, written to, ' +
212-
'paused and/or resumed.');
211+
'HTTP/2 sockets should not be directly manipulated (e.g. read and written)');
213212
E('ERR_HTTP2_OUT_OF_STREAMS',
214213
'No stream ID is available because maximum stream ID has been reached');
215214
E('ERR_HTTP2_PAYLOAD_FORBIDDEN',

lib/internal/http2/core.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -681,8 +681,6 @@ const proxySocketHandler = {
681681
case 'destroy':
682682
case 'emit':
683683
case 'end':
684-
case 'once':
685-
case 'on':
686684
case 'pause':
687685
case 'read':
688686
case 'resume':
@@ -705,8 +703,6 @@ const proxySocketHandler = {
705703
case 'destroy':
706704
case 'emit':
707705
case 'end':
708-
case 'once':
709-
case 'on':
710706
case 'pause':
711707
case 'read':
712708
case 'resume':

test/parallel/test-http2-compat-socket-set.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ const h2 = require('http2');
1212
const errMsg = {
1313
code: 'ERR_HTTP2_NO_SOCKET_MANIPULATION',
1414
type: Error,
15-
message: 'HTTP/2 sockets should not be directly read from, written to, ' +
16-
'paused and/or resumed.'
15+
message: 'HTTP/2 sockets should not be directly manipulated ' +
16+
'(e.g. read and written)'
1717
};
1818

1919
const server = h2.createServer();

test/parallel/test-http2-compat-socket.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ const net = require('net');
1414
const errMsg = {
1515
code: 'ERR_HTTP2_NO_SOCKET_MANIPULATION',
1616
type: Error,
17-
message: 'HTTP/2 sockets should not be directly read from, written to, ' +
18-
'paused and/or resumed.'
17+
message: 'HTTP/2 sockets should not be directly manipulated ' +
18+
'(e.g. read and written)'
1919
};
2020

2121
const server = h2.createServer();

test/parallel/test-http2-socket-proxy.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ const net = require('net');
1212
const errMsg = {
1313
code: 'ERR_HTTP2_NO_SOCKET_MANIPULATION',
1414
type: Error,
15-
message: 'HTTP/2 sockets should not be directly read from, written to, ' +
16-
'paused and/or resumed.'
15+
message: 'HTTP/2 sockets should not be directly manipulated ' +
16+
'(e.g. read and written)'
1717
};
1818

1919
const server = h2.createServer();
@@ -34,8 +34,6 @@ server.on('stream', common.mustCall(function(stream, headers) {
3434
common.expectsError(() => socket.destroy, errMsg);
3535
common.expectsError(() => socket.emit, errMsg);
3636
common.expectsError(() => socket.end, errMsg);
37-
common.expectsError(() => socket.once, errMsg);
38-
common.expectsError(() => socket.on, errMsg);
3937
common.expectsError(() => socket.pause, errMsg);
4038
common.expectsError(() => socket.read, errMsg);
4139
common.expectsError(() => socket.resume, errMsg);
@@ -44,13 +42,14 @@ server.on('stream', common.mustCall(function(stream, headers) {
4442
common.expectsError(() => (socket.destroy = undefined), errMsg);
4543
common.expectsError(() => (socket.emit = undefined), errMsg);
4644
common.expectsError(() => (socket.end = undefined), errMsg);
47-
common.expectsError(() => (socket.once = undefined), errMsg);
48-
common.expectsError(() => (socket.on = undefined), errMsg);
4945
common.expectsError(() => (socket.pause = undefined), errMsg);
5046
common.expectsError(() => (socket.read = undefined), errMsg);
5147
common.expectsError(() => (socket.resume = undefined), errMsg);
5248
common.expectsError(() => (socket.write = undefined), errMsg);
5349

50+
assert.doesNotThrow(() => (socket.on = socket.on));
51+
assert.doesNotThrow(() => (socket.once = socket.once));
52+
5453
stream.respond();
5554

5655
socket.writable = 0;

0 commit comments

Comments
 (0)