| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9254791 commit 0ee168c
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1584,6 +1584,15 @@ Removes a header that's queued for implicit sending. | |||
| 1584 | 1584 | response.removeHeader('Content-Encoding'); | |
| 1585 | 1585 | ``` | |
| 1586 | 1586 | ||
| 1587 | + ### `response.req` | ||
| 1588 | + <!-- YAML | ||
| 1589 | + added: REPLACEME | ||
| 1590 | + --> | ||
| 1591 | + | ||
| 1592 | + * {http.IncomingMessage} | ||
| 1593 | + | ||
| 1594 | + A reference to the original HTTP `request` object. | ||
| 1595 | + | ||
| 1587 | 1596 | ### `response.sendDate` | |
| 1588 | 1597 | <!-- YAML | |
| 1589 | 1598 | added: v0.7.5 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3437,6 +3437,15 @@ Removes a header that has been queued for implicit sending. | |||
| 3437 | 3437 | response.removeHeader('Content-Encoding'); | |
| 3438 | 3438 | ``` | |
| 3439 | 3439 | ||
| 3440 | + ### `response.req` | ||
| 3441 | + <!-- YAML | ||
| 3442 | + added: REPLACEME | ||
| 3443 | + --> | ||
| 3444 | + | ||
| 3445 | + * {http2.Http2ServerRequest} | ||
| 3446 | + | ||
| 3447 | + A reference to the original HTTP2 `request` object. | ||
| 3448 | + | ||
| 3440 | 3449 | #### `response.sendDate` | |
| 3441 | 3450 | <!-- YAML | |
| 3442 | 3451 | added: v8.4.0 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -181,6 +181,7 @@ function ServerResponse(req) { | |||
| 181 | 181 | ||
| 182 | 182 | if (req.method === 'HEAD') this._hasBody = false; | |
| 183 | 183 | ||
| 184 | + this.req = req; | ||
| 184 | 185 | this.sendDate = true; | |
| 185 | 186 | this._sent100 = false; | |
| 186 | 187 | this._expect_continue = false; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -529,6 +529,10 @@ class Http2ServerResponse extends Stream { | |||
| 529 | 529 | return this[kStream].headersSent; | |
| 530 | 530 | } | |
| 531 | 531 | ||
| 532 | + get req() { | ||
| 533 | + return this[kStream][kRequest]; | ||
| 534 | + } | ||
| 535 | + | ||
| 532 | 536 | get sendDate() { | |
| 533 | 537 | return this[kState].sendDate; | |
| 534 | 538 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -49,6 +49,8 @@ const server = http.createServer(function(req, res) { | |||
| 49 | 49 | res.id = request_number; | |
| 50 | 50 | req.id = request_number++; | |
| 51 | 51 | ||
| 52 | + assert.strictEqual(res.req, req); | ||
| 53 | + | ||
| 52 | 54 | if (req.id === 0) { | |
| 53 | 55 | assert.strictEqual(req.method, 'GET'); | |
| 54 | 56 | assert.strictEqual(url.parse(req.url).pathname, '/hello'); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,40 @@ | |||
| 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 | + // Http2ServerResponse should expose convenience properties | ||
| 10 | + | ||
| 11 | + const server = h2.createServer(); | ||
| 12 | + server.listen(0, common.mustCall(function() { | ||
| 13 | + const port = server.address().port; | ||
| 14 | + server.once('request', common.mustCall(function(request, response) { | ||
| 15 | + assert.strictEqual(response.req, request); | ||
| 16 | + | ||
| 17 | + response.on('finish', common.mustCall(function() { | ||
| 18 | + process.nextTick(() => { | ||
| 19 | + server.close(); | ||
| 20 | + }); | ||
| 21 | + })); | ||
| 22 | + response.end(); | ||
| 23 | + })); | ||
| 24 | + | ||
| 25 | + const url = `http://localhost:${port}`; | ||
| 26 | + const client = h2.connect(url, common.mustCall(function() { | ||
| 27 | + const headers = { | ||
| 28 | + ':path': '/foobar', | ||
| 29 | + ':method': 'GET', | ||
| 30 | + ':scheme': 'http', | ||
| 31 | + ':authority': `localhost:${port}` | ||
| 32 | + }; | ||
| 33 | + const request = client.request(headers); | ||
| 34 | + request.on('end', common.mustCall(function() { | ||
| 35 | + client.close(); | ||
| 36 | + })); | ||
| 37 | + request.end(); | ||
| 38 | + request.resume(); | ||
| 39 | + })); | ||
| 40 | + })); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments