GeezerVison is showing github.com — http2: don't expose the original socket through the socket proxy · nodejs/node@4cdecc5
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/internal/http2/core.js +12-2Lines changed: 12 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -646,14 +646,19 @@ const proxySocketHandler = { | 646 | 646 | get(session, prop) { | 647 | 647 | switch (prop) { | 648 | 648 | case 'setTimeout': | 649 | | - return session.setTimeout.bind(session); | | 649 | + case 'ref': | | 650 | + case 'unref': | | 651 | + return session[prop].bind(session); | 650 | 652 | case 'destroy': | 651 | 653 | case 'emit': | 652 | 654 | case 'end': | 653 | 655 | case 'pause': | 654 | 656 | case 'read': | 655 | 657 | case 'resume': | 656 | 658 | case 'write': | | 659 | + case 'setEncoding': | | 660 | + case 'setKeepAlive': | | 661 | + case 'setNoDelay': | 657 | 662 | throw new ERR_HTTP2_NO_SOCKET_MANIPULATION(); | 658 | 663 | default: | 659 | 664 | const socket = session[kSocket]; | @@ -672,7 +677,9 @@ const proxySocketHandler = { | 672 | 677 | set(session, prop, value) { | 673 | 678 | switch (prop) { | 674 | 679 | case 'setTimeout': | 675 | | - session.setTimeout = value; | | 680 | + case 'ref': | | 681 | + case 'unref': | | 682 | + session[prop] = value; | 676 | 683 | return true; | 677 | 684 | case 'destroy': | 678 | 685 | case 'emit': | @@ -681,6 +688,9 @@ const proxySocketHandler = { | 681 | 688 | case 'read': | 682 | 689 | case 'resume': | 683 | 690 | case 'write': | | 691 | + case 'setEncoding': | | 692 | + case 'setKeepAlive': | | 693 | + case 'setNoDelay': | 684 | 694 | throw new ERR_HTTP2_NO_SOCKET_MANIPULATION(); | 685 | 695 | default: | 686 | 696 | const socket = session[kSocket]; | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-http2-socket-proxy.js +11Lines changed: 11 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -42,6 +42,9 @@ server.on('stream', common.mustCall(function(stream, headers) { | 42 | 42 | common.expectsError(() => socket.read, errMsg); | 43 | 43 | common.expectsError(() => socket.resume, errMsg); | 44 | 44 | common.expectsError(() => socket.write, errMsg); | | 45 | + common.expectsError(() => socket.setEncoding, errMsg); | | 46 | + common.expectsError(() => socket.setKeepAlive, errMsg); | | 47 | + common.expectsError(() => socket.setNoDelay, errMsg); | 45 | 48 |
| 46 | 49 | common.expectsError(() => (socket.destroy = undefined), errMsg); | 47 | 50 | common.expectsError(() => (socket.emit = undefined), errMsg); | @@ -50,11 +53,19 @@ server.on('stream', common.mustCall(function(stream, headers) { | 50 | 53 | common.expectsError(() => (socket.read = undefined), errMsg); | 51 | 54 | common.expectsError(() => (socket.resume = undefined), errMsg); | 52 | 55 | common.expectsError(() => (socket.write = undefined), errMsg); | | 56 | + common.expectsError(() => (socket.setEncoding = undefined), errMsg); | | 57 | + common.expectsError(() => (socket.setKeepAlive = undefined), errMsg); | | 58 | + common.expectsError(() => (socket.setNoDelay = undefined), errMsg); | 53 | 59 |
| 54 | 60 | // Resetting the socket listeners to their own value should not throw. | 55 | 61 | socket.on = socket.on; // eslint-disable-line no-self-assign | 56 | 62 | socket.once = socket.once; // eslint-disable-line no-self-assign | 57 | 63 |
| | 64 | + socket.unref(); | | 65 | + assert.strictEqual(socket._handle.hasRef(), false); | | 66 | + socket.ref(); | | 67 | + assert.strictEqual(socket._handle.hasRef(), true); | | 68 | + | 58 | 69 | stream.respond(); | 59 | 70 |
| 60 | 71 | socket.writable = 0; | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-http2-unbound-socket-proxy.js -25Lines changed: 0 additions & 25 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -39,31 +39,6 @@ server.listen(0, common.mustCall(() => { | 39 | 39 | }, { | 40 | 40 | code: 'ERR_HTTP2_SOCKET_UNBOUND' | 41 | 41 | }); | 42 | | - common.expectsError(() => { | 43 | | - socket.ref(); | 44 | | - }, { | 45 | | - code: 'ERR_HTTP2_SOCKET_UNBOUND' | 46 | | - }); | 47 | | - common.expectsError(() => { | 48 | | - socket.unref(); | 49 | | - }, { | 50 | | - code: 'ERR_HTTP2_SOCKET_UNBOUND' | 51 | | - }); | 52 | | - common.expectsError(() => { | 53 | | - socket.setEncoding(); | 54 | | - }, { | 55 | | - code: 'ERR_HTTP2_SOCKET_UNBOUND' | 56 | | - }); | 57 | | - common.expectsError(() => { | 58 | | - socket.setKeepAlive(); | 59 | | - }, { | 60 | | - code: 'ERR_HTTP2_SOCKET_UNBOUND' | 61 | | - }); | 62 | | - common.expectsError(() => { | 63 | | - socket.setNoDelay(); | 64 | | - }, { | 65 | | - code: 'ERR_HTTP2_SOCKET_UNBOUND' | 66 | | - }); | 67 | 42 | })); | 68 | 43 | })); | 69 | 44 | })); |
|