| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3e5b07a commit 9a4be4a
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -328,16 +328,12 @@ class Http2ServerResponse extends Stream { | |||
| 328 | 328 | addTrailers(headers) { | |
| 329 | 329 | let trailers = this[kTrailers]; | |
| 330 | 330 | const keys = Object.keys(headers); | |
| 331 | - let key = ''; | ||
| 332 | - if (keys.length > 0) | ||
| 331 | + if (keys.length === 0) | ||
| 333 | 332 | return; | |
| 334 | 333 | if (trailers === undefined) | |
| 335 | 334 | trailers = this[kTrailers] = Object.create(null); | |
| 336 | 335 | for (var i = 0; i < keys.length; i++) { | |
| 337 | - key = String(keys[i]).trim().toLowerCase(); | ||
| 338 | - const value = headers[key]; | ||
| 339 | - assertValidHeader(key, value); | ||
| 340 | - trailers[key] = String(value); | ||
| 336 | + trailers[keys[i]] = String(headers[keys[i]]); | ||
| 341 | 337 | } | |
| 342 | 338 | } | |
| 343 | 339 | ||
@@ -508,12 +504,16 @@ class Http2ServerResponse extends Stream { | |||
| 508 | 504 | ||
| 509 | 505 | [kBeginSend](options) { | |
| 510 | 506 | const stream = this[kStream]; | |
| 507 | + options = options || Object.create(null); | ||
| 511 | 508 | if (stream !== undefined && stream.headersSent === false) { | |
| 512 | 509 | const state = this[kState]; | |
| 513 | 510 | const headers = this[kHeaders] || Object.create(null); | |
| 514 | 511 | headers[constants.HTTP2_HEADER_STATUS] = state.statusCode; | |
| 515 | 512 | if (stream.finished === true) | |
| 516 | 513 | options.endStream = true; | |
| 514 | + options.getTrailers = (trailers) => { | ||
| 515 | + Object.assign(trailers, this[kTrailers]); | ||
| 516 | + }; | ||
| 517 | 517 | if (stream.destroyed === false) { | |
| 518 | 518 | stream.respond(headers, options); | |
| 519 | 519 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,30 @@ | |||
| 1 | + // Flags: --expose-http2 | ||
| 2 | + 'use strict'; | ||
| 3 | + | ||
| 4 | + const common = require('../common'); | ||
| 5 | + const assert = require('assert'); | ||
| 6 | + const http2 = require('http2'); | ||
| 7 | + | ||
| 8 | + const server = http2.createServer(); | ||
| 9 | + server.listen(0, common.mustCall(() => { | ||
| 10 | + const port = server.address().port; | ||
| 11 | + server.once('request', common.mustCall((request, response) => { | ||
| 12 | + response.addTrailers({ | ||
| 13 | + ABC: 123 | ||
| 14 | + }); | ||
| 15 | + response.end('hello'); | ||
| 16 | + })); | ||
| 17 | + | ||
| 18 | + const url = `http://localhost:${port}`; | ||
| 19 | + const client = http2.connect(url, common.mustCall(() => { | ||
| 20 | + const request = client.request(); | ||
| 21 | + request.on('trailers', common.mustCall((headers) => { | ||
| 22 | + assert.strictEqual(headers.abc, '123'); | ||
| 23 | + })); | ||
| 24 | + request.resume(); | ||
| 25 | + request.on('end', common.mustCall(() => { | ||
| 26 | + client.destroy(); | ||
| 27 | + server.close(); | ||
| 28 | + })); | ||
| 29 | + })); | ||
| 30 | + })); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments