Skip to content
This repository has been archived by the owner on Jul 6, 2018. It is now read-only.

Commit

Permalink
http2: request.socket|connection
Browse files Browse the repository at this point in the history
Support the socket/connection getter like require('http') does.

PR-URL: #130
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
sebdeckers authored and mcollina committed May 18, 2017
1 parent 2061154 commit 3904d7c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/internal/http2/compat.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,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) {
Expand Down
5 changes: 5 additions & 0 deletions test/parallel/test-http2-compat-serverrequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -22,6 +23,10 @@ server.listen(0, common.mustCall(function() {
assert.strictEqual(request.httpVersionMajor, expected.httpVersionMajor);
assert.strictEqual(request.httpVersionMinor, expected.httpVersionMinor);

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() {
server.close();
}));
Expand Down

0 comments on commit 3904d7c

Please sign in to comment.