| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 468cb99 commit 3fc8d22
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -177,6 +177,7 @@ const { | |||
| 177 | 177 | kUpdateTimer, | |
| 178 | 178 | kHandle, | |
| 179 | 179 | kSession, | |
| 180 | + kBoundSession, | ||
| 180 | 181 | setStreamTimeout, | |
| 181 | 182 | } = require('internal/stream_base_commons'); | |
| 182 | 183 | const { kTimeout } = require('internal/timers'); | |
@@ -1121,7 +1122,7 @@ function cleanupSession(session) { | |||
| 1121 | 1122 | if (handle) | |
| 1122 | 1123 | handle.ondone = null; | |
| 1123 | 1124 | if (socket) { | |
| 1124 | - socket[kSession] = undefined; | ||
| 1125 | + socket[kBoundSession] = undefined; | ||
| 1125 | 1126 | socket[kServer] = undefined; | |
| 1126 | 1127 | } | |
| 1127 | 1128 | } | |
@@ -1235,10 +1236,10 @@ class Http2Session extends EventEmitter { | |||
| 1235 | 1236 | // If the session property already exists on the socket, | |
| 1236 | 1237 | // then it has already been bound to an Http2Session instance | |
| 1237 | 1238 | // and cannot be attached again. | |
| 1238 | - if (socket[kSession] !== undefined) | ||
| 1239 | + if (socket[kBoundSession] !== undefined) | ||
| 1239 | 1240 | throw new ERR_HTTP2_SOCKET_BOUND(); | |
| 1240 | 1241 | ||
| 1241 | - socket[kSession] = this; | ||
| 1242 | + socket[kBoundSession] = this; | ||
| 1242 | 1243 | ||
| 1243 | 1244 | if (!socket._handle || !socket._handle.isStreamBase) { | |
| 1244 | 1245 | socket = new JSStreamSocket(socket); | |
@@ -1617,7 +1618,7 @@ class Http2Session extends EventEmitter { | |||
| 1617 | 1618 | } | |
| 1618 | 1619 | ||
| 1619 | 1620 | _onTimeout() { | |
| 1620 | - callTimeout(this); | ||
| 1621 | + callTimeout(this, this); | ||
| 1621 | 1622 | } | |
| 1622 | 1623 | ||
| 1623 | 1624 | ref() { | |
@@ -2093,7 +2094,7 @@ class Http2Stream extends Duplex { | |||
| 2093 | 2094 | } | |
| 2094 | 2095 | ||
| 2095 | 2096 | _onTimeout() { | |
| 2096 | - callTimeout(this, kSession); | ||
| 2097 | + callTimeout(this, this[kSession]); | ||
| 2097 | 2098 | } | |
| 2098 | 2099 | ||
| 2099 | 2100 | // True if the HEADERS frame has been sent | |
@@ -2419,7 +2420,7 @@ class Http2Stream extends Duplex { | |||
| 2419 | 2420 | } | |
| 2420 | 2421 | } | |
| 2421 | 2422 | ||
| 2422 | - function callTimeout(self, kSession) { | ||
| 2423 | + function callTimeout(self, session) { | ||
| 2423 | 2424 | // If the session is destroyed, this should never actually be invoked, | |
| 2424 | 2425 | // but just in case... | |
| 2425 | 2426 | if (self.destroyed) | |
@@ -2430,7 +2431,7 @@ function callTimeout(self, kSession) { | |||
| 2430 | 2431 | // happens, meaning that if a write is ongoing it should never equal the | |
| 2431 | 2432 | // newly fetched, updated value. | |
| 2432 | 2433 | if (self[kState].writeQueueSize > 0) { | |
| 2433 | - const handle = kSession ? self[kSession][kHandle] : self[kHandle]; | ||
| 2434 | + const handle = session[kHandle]; | ||
| 2434 | 2435 | const chunksSentSinceLastWrite = handle !== undefined ? | |
| 2435 | 2436 | handle.chunksSentSinceLastWrite : null; | |
| 2436 | 2437 | if (chunksSentSinceLastWrite !== null && | |
@@ -3017,7 +3018,7 @@ ObjectDefineProperty(Http2Session.prototype, 'setTimeout', setTimeoutValue); | |||
| 3017 | 3018 | // When the socket emits an error, destroy the associated Http2Session and | |
| 3018 | 3019 | // forward it the same error. | |
| 3019 | 3020 | function socketOnError(error) { | |
| 3020 | - const session = this[kSession]; | ||
| 3021 | + const session = this[kBoundSession]; | ||
| 3021 | 3022 | if (session !== undefined) { | |
| 3022 | 3023 | // We can ignore ECONNRESET after GOAWAY was received as there's nothing | |
| 3023 | 3024 | // we can do and the other side is fully within its rights to do so. | |
@@ -3300,7 +3301,7 @@ function setupCompat(ev) { | |||
| 3300 | 3301 | } | |
| 3301 | 3302 | ||
| 3302 | 3303 | function socketOnClose() { | |
| 3303 | - const session = this[kSession]; | ||
| 3304 | + const session = this[kBoundSession]; | ||
| 3304 | 3305 | if (session !== undefined) { | |
| 3305 | 3306 | debugSessionObj(session, 'socket closed'); | |
| 3306 | 3307 | const err = session.connecting ? new ERR_SOCKET_CLOSED() : null; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,7 +17,7 @@ let debug = require('internal/util/debuglog').debuglog( | |||
| 17 | 17 | ); | |
| 18 | 18 | const { owner_symbol } = require('internal/async_hooks').symbols; | |
| 19 | 19 | const { ERR_STREAM_WRAP } = require('internal/errors').codes; | |
| 20 | - const { kSession } = require('internal/stream_base_commons'); | ||
| 20 | + const { kBoundSession } = require('internal/stream_base_commons'); | ||
| 21 | 21 | ||
| 22 | 22 | const kCurrentWriteRequest = Symbol('kCurrentWriteRequest'); | |
| 23 | 23 | const kCurrentShutdownRequest = Symbol('kCurrentShutdownRequest'); | |
@@ -265,12 +265,12 @@ class JSStreamSocket extends Socket { | |||
| 265 | 265 | }); | |
| 266 | 266 | } | |
| 267 | 267 | ||
| 268 | - get [kSession]() { | ||
| 269 | - return this.stream[kSession]; | ||
| 268 | + get [kBoundSession]() { | ||
| 269 | + return this.stream[kBoundSession]; | ||
| 270 | 270 | } | |
| 271 | 271 | ||
| 272 | - set [kSession](session) { | ||
| 273 | - this.stream[kSession] = session; | ||
| 272 | + set [kBoundSession](session) { | ||
| 273 | + this.stream[kBoundSession] = session; | ||
| 274 | 274 | } | |
| 275 | 275 | } | |
| 276 | 276 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -33,6 +33,7 @@ const kMaybeDestroy = Symbol('kMaybeDestroy'); | |||
| 33 | 33 | const kUpdateTimer = Symbol('kUpdateTimer'); | |
| 34 | 34 | const kAfterAsyncWrite = Symbol('kAfterAsyncWrite'); | |
| 35 | 35 | const kHandle = Symbol('kHandle'); | |
| 36 | + const kBoundSession = Symbol('kBoundSession'); | ||
| 36 | 37 | const kSession = Symbol('kSession'); | |
| 37 | 38 | ||
| 38 | 39 | let debug = require('internal/util/debuglog').debuglog('stream', (fn) => { | |
@@ -255,6 +256,7 @@ function setStreamTimeout(msecs, callback) { | |||
| 255 | 256 | } else { | |
| 256 | 257 | this[kTimeout] = setUnrefTimeout(this._onTimeout.bind(this), msecs); | |
| 257 | 258 | if (this[kSession]) this[kSession][kUpdateTimer](); | |
| 259 | + if (this[kBoundSession]) this[kBoundSession][kUpdateTimer](); | ||
| 258 | 260 | ||
| 259 | 261 | if (callback !== undefined) { | |
| 260 | 262 | validateFunction(callback, 'callback'); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,50 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common'); | ||
| 4 | + if (!common.hasCrypto) | ||
| 5 | + common.skip('missing crypto'); | ||
| 6 | + const assert = require('assert'); | ||
| 7 | + const h2 = require('http2'); | ||
| 8 | + | ||
| 9 | + const server = h2.createServer(); | ||
| 10 | + | ||
| 11 | + server.listen(0, common.mustCall(function() { | ||
| 12 | + const proxyClient = h2.connect(`http://localhost:${server.address().port}`); | ||
| 13 | + | ||
| 14 | + const request = proxyClient.request({ | ||
| 15 | + ':method': 'CONNECT', | ||
| 16 | + ':authority': 'example.com:80' | ||
| 17 | + }); | ||
| 18 | + | ||
| 19 | + request.on('response', common.mustCall((connectResponse) => { | ||
| 20 | + assert.strictEqual(connectResponse[':status'], 200); | ||
| 21 | + | ||
| 22 | + const proxiedClient = h2.connect('http://example.com', { | ||
| 23 | + createConnection: () => request // Tunnel via first request stream | ||
| 24 | + }); | ||
| 25 | + | ||
| 26 | + const proxiedRequest = proxiedClient.request(); | ||
| 27 | + proxiedRequest.on('response', common.mustCall((proxiedResponse) => { | ||
| 28 | + assert.strictEqual(proxiedResponse[':status'], 204); | ||
| 29 | + | ||
| 30 | + proxiedClient.close(); | ||
| 31 | + proxyClient.close(); | ||
| 32 | + server.close(); | ||
| 33 | + })); | ||
| 34 | + })); | ||
| 35 | + })); | ||
| 36 | + | ||
| 37 | + server.once('connect', common.mustCall((req, res) => { | ||
| 38 | + assert.strictEqual(req.headers[':method'], 'CONNECT'); | ||
| 39 | + res.writeHead(200); // Accept the CONNECT tunnel | ||
| 40 | + | ||
| 41 | + // Handle this stream as a new 'proxied' connection (pretend to forward | ||
| 42 | + // but actually just unwrap the tunnel ourselves): | ||
| 43 | + server.emit('connection', res.stream); | ||
| 44 | + })); | ||
| 45 | + | ||
| 46 | + // Handle the 'proxied' request itself: | ||
| 47 | + server.once('request', common.mustCall((req, res) => { | ||
| 48 | + res.writeHead(204); | ||
| 49 | + res.end(); | ||
| 50 | + })); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments