| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent af977db commit c0d6945
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1714,6 +1714,14 @@ changes: | |||
| 1714 | 1714 | * `Http1ServerResponse` {http.ServerResponse} Specifies the ServerResponse | |
| 1715 | 1715 | class to used for HTTP/1 fallback. Useful for extending the original | |
| 1716 | 1716 | `http.ServerResponse`. **Default:** `http.ServerResponse` | |
| 1717 | + * `Http2ServerRequest` {http2.Http2ServerRequest} Specifies the | ||
| 1718 | + Http2ServerRequest class to use. | ||
| 1719 | + Useful for extending the original `Http2ServerRequest`. | ||
| 1720 | + **Default:** `Http2ServerRequest` | ||
| 1721 | + * `Http2ServerResponse` {htt2.Http2ServerResponse} Specifies the | ||
| 1722 | + Http2ServerResponse class to use. | ||
| 1723 | + Useful for extending the original `Http2ServerResponse`. | ||
| 1724 | + **Default:** `Http2ServerResponse` | ||
| 1717 | 1725 | * `onRequestHandler` {Function} See [Compatibility API][] | |
| 1718 | 1726 | * Returns: {Http2Server} | |
| 1719 | 1727 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -661,11 +661,11 @@ class Http2ServerResponse extends Stream { | |||
| 661 | 661 | } | |
| 662 | 662 | } | |
| 663 | 663 | ||
| 664 | - function onServerStream(stream, headers, flags, rawHeaders) { | ||
| 664 | + function onServerStream(ServerRequest, ServerResponse, | ||
| 665 | + stream, headers, flags, rawHeaders) { | ||
| 665 | 666 | const server = this; | |
| 666 | - const request = new Http2ServerRequest(stream, headers, undefined, | ||
| 667 | - rawHeaders); | ||
| 668 | - const response = new Http2ServerResponse(stream); | ||
| 667 | + const request = new ServerRequest(stream, headers, undefined, rawHeaders); | ||
| 668 | + const response = new ServerResponse(stream); | ||
| 669 | 669 | ||
| 670 | 670 | // Check for the CONNECT method | |
| 671 | 671 | const method = headers[HTTP2_HEADER_METHOD]; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2487,6 +2487,10 @@ function initializeOptions(options) { | |||
| 2487 | 2487 | options.Http1ServerResponse = options.Http1ServerResponse || | |
| 2488 | 2488 | http.ServerResponse; | |
| 2489 | 2489 | ||
| 2490 | + options.Http2ServerRequest = options.Http2ServerRequest || | ||
| 2491 | + Http2ServerRequest; | ||
| 2492 | + options.Http2ServerResponse = options.Http2ServerResponse || | ||
| 2493 | + Http2ServerResponse; | ||
| 2490 | 2494 | return options; | |
| 2491 | 2495 | } | |
| 2492 | 2496 | ||
@@ -2552,7 +2556,11 @@ class Http2Server extends NETServer { | |||
| 2552 | 2556 | function setupCompat(ev) { | |
| 2553 | 2557 | if (ev === 'request') { | |
| 2554 | 2558 | this.removeListener('newListener', setupCompat); | |
| 2555 | - this.on('stream', onServerStream); | ||
| 2559 | + this.on('stream', onServerStream.bind( | ||
| 2560 | + this, | ||
| 2561 | + this[kOptions].Http2ServerRequest, | ||
| 2562 | + this[kOptions].Http2ServerResponse) | ||
| 2563 | + ); | ||
| 2556 | 2564 | } | |
| 2557 | 2565 | } | |
| 2558 | 2566 | ||
| 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 | + class MyServerRequest extends h2.Http2ServerRequest { | ||
| 10 | + getUserAgent() { | ||
| 11 | + return this.headers['user-agent'] || 'unknown'; | ||
| 12 | + } | ||
| 13 | + } | ||
| 14 | + | ||
| 15 | + const server = h2.createServer({ | ||
| 16 | + Http2ServerRequest: MyServerRequest | ||
| 17 | + }, (req, res) => { | ||
| 18 | + assert.strictEqual(req.getUserAgent(), 'node-test'); | ||
| 19 | + | ||
| 20 | + res.writeHead(200, { 'Content-Type': 'text/plain' }); | ||
| 21 | + res.end(); | ||
| 22 | + }); | ||
| 23 | + server.listen(0); | ||
| 24 | + | ||
| 25 | + server.on('listening', common.mustCall(() => { | ||
| 26 | + | ||
| 27 | + const client = h2.connect(`http://localhost:${server.address().port}`); | ||
| 28 | + const req = client.request({ | ||
| 29 | + ':path': '/', | ||
| 30 | + 'User-Agent': 'node-test' | ||
| 31 | + }); | ||
| 32 | + | ||
| 33 | + req.on('response', common.mustCall()); | ||
| 34 | + | ||
| 35 | + req.resume(); | ||
| 36 | + req.on('end', common.mustCall(() => { | ||
| 37 | + server.close(); | ||
| 38 | + client.destroy(); | ||
| 39 | + })); | ||
| 40 | + })); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,34 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common'); | ||
| 4 | + if (!common.hasCrypto) | ||
| 5 | + common.skip('missing crypto'); | ||
| 6 | + const h2 = require('http2'); | ||
| 7 | + | ||
| 8 | + class MyServerResponse extends h2.Http2ServerResponse { | ||
| 9 | + status(code) { | ||
| 10 | + return this.writeHead(code, { 'Content-Type': 'text/plain' }); | ||
| 11 | + } | ||
| 12 | + } | ||
| 13 | + | ||
| 14 | + const server = h2.createServer({ | ||
| 15 | + Http2ServerResponse: MyServerResponse | ||
| 16 | + }, (req, res) => { | ||
| 17 | + res.status(200); | ||
| 18 | + res.end(); | ||
| 19 | + }); | ||
| 20 | + server.listen(0); | ||
| 21 | + | ||
| 22 | + server.on('listening', common.mustCall(() => { | ||
| 23 | + | ||
| 24 | + const client = h2.connect(`http://localhost:${server.address().port}`); | ||
| 25 | + const req = client.request({ ':path': '/' }); | ||
| 26 | + | ||
| 27 | + req.on('response', common.mustCall()); | ||
| 28 | + | ||
| 29 | + req.resume(); | ||
| 30 | + req.on('end', common.mustCall(() => { | ||
| 31 | + server.close(); | ||
| 32 | + client.destroy(); | ||
| 33 | + })); | ||
| 34 | + })); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments