From 674d237fe335d6a91b9605effdfe1dbca38bdd0b Mon Sep 17 00:00:00 2001 From: Sebastiaan Deckers Date: Wed, 17 May 2017 17:47:18 +0800 Subject: [PATCH 1/4] http2: request.socket|connection --- lib/internal/http2/compat.js | 8 ++++++++ test/parallel/test-http2-compat-serverrequest.js | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/lib/internal/http2/compat.js b/lib/internal/http2/compat.js index 9b77ba3f1a..ac9c6154a4 100644 --- a/lib/internal/http2/compat.js +++ b/lib/internal/http2/compat.js @@ -181,6 +181,14 @@ class Http2ServerRequest extends Readable { return '2.0'; } + get socket() { + return this.stream.session.socket; + } + + get connection() { + return this.socket; + } + _read(nread) { var stream = this[kStream]; if (stream) { diff --git a/test/parallel/test-http2-compat-serverrequest.js b/test/parallel/test-http2-compat-serverrequest.js index cd93c1c596..4596ccb601 100644 --- a/test/parallel/test-http2-compat-serverrequest.js +++ b/test/parallel/test-http2-compat-serverrequest.js @@ -22,6 +22,10 @@ server.listen(0, common.mustCall(function() { assert.strictEqual(request.httpVersionMajor, expected.httpVersionMajor); assert.strictEqual(request.httpVersionMinor, expected.httpVersionMinor); + assert.ok(request.socket); + assert.ok(request.connection); + assert.strictEqual(request.socket, request.connection); + response.stream.on('finish', common.mustCall(function() { server.close(); })); From 360c27aa7275ef5ed9190f5ad1fca3314be7c3b5 Mon Sep 17 00:00:00 2001 From: Sebastiaan Deckers Date: Wed, 17 May 2017 19:02:01 +0800 Subject: [PATCH 2/4] http2: Validate the returned value type (Squash) --- test/parallel/test-http2-compat-serverrequest.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-http2-compat-serverrequest.js b/test/parallel/test-http2-compat-serverrequest.js index 4596ccb601..5d9a1a1c96 100644 --- a/test/parallel/test-http2-compat-serverrequest.js +++ b/test/parallel/test-http2-compat-serverrequest.js @@ -3,6 +3,7 @@ const common = require('../common'); const assert = require('assert'); const h2 = require('http2'); +const net = require('net'); // Http2ServerRequest should expose convenience properties @@ -22,8 +23,8 @@ server.listen(0, common.mustCall(function() { assert.strictEqual(request.httpVersionMajor, expected.httpVersionMajor); assert.strictEqual(request.httpVersionMinor, expected.httpVersionMinor); - assert.ok(request.socket); - assert.ok(request.connection); + assert.ok(request.socket instanceof net.Socket); + assert.ok(request.connection instanceof net.Socket); assert.strictEqual(request.socket, request.connection); response.stream.on('finish', common.mustCall(function() { From 9f3e375189acda19e29cb1470e1bf4d4f3373e35 Mon Sep 17 00:00:00 2001 From: Sebastiaan Deckers Date: Thu, 18 May 2017 00:07:01 +0800 Subject: [PATCH 3/4] http2: Docs warning against direct socket access (Squash) --- doc/api/http2.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/api/http2.md b/doc/api/http2.md index 04ff7e56bd..792bad7188 100755 --- a/doc/api/http2.md +++ b/doc/api/http2.md @@ -227,6 +227,8 @@ process has completed. A reference to the [`net.Socket`][] or [`tls.TLSSocket`][] to which this `Http2Session` instance is bound. +Directly reading from and writing to the socket is strongly discouraged. + #### http2session.state * Value: {Object} From dc1f350e6d139a1dee034639b31bbcc0d65f61cd Mon Sep 17 00:00:00 2001 From: Sebastiaan Deckers Date: Thu, 18 May 2017 08:31:20 +0800 Subject: [PATCH 4/4] http2: Prefer the language in #132 (Squash) --- doc/api/http2.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/doc/api/http2.md b/doc/api/http2.md index 792bad7188..04ff7e56bd 100755 --- a/doc/api/http2.md +++ b/doc/api/http2.md @@ -227,8 +227,6 @@ process has completed. A reference to the [`net.Socket`][] or [`tls.TLSSocket`][] to which this `Http2Session` instance is bound. -Directly reading from and writing to the socket is strongly discouraged. - #### http2session.state * Value: {Object}