| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b778838 commit 7824fa0
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2402,7 +2402,7 @@ buffer. Returns `false` if all or part of the data was queued in user memory. | |||
| 2402 | 2402 | added: REPLACEME | |
| 2403 | 2403 | --> | |
| 2404 | 2404 | ||
| 2405 | - Does nothing. Added for parity with [HTTP/1](). | ||
| 2405 | + Throws an error as the `'continue'` flow is not current implemented. Added for parity with [HTTP/1](). | ||
| 2406 | 2406 | ||
| 2407 | 2407 | ### response.writeHead(statusCode[, statusMessage][, headers]) | |
| 2408 | 2408 | <!-- YAML | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -386,11 +386,6 @@ class Http2ServerResponse extends Stream { | |||
| 386 | 386 | headers[name] = String(value); | |
| 387 | 387 | } | |
| 388 | 388 | ||
| 389 | - flushHeaders() { | ||
| 390 | - if (this[kStream].headersSent === false) | ||
| 391 | - this[kBeginSend](); | ||
| 392 | - } | ||
| 393 | - | ||
| 394 | 389 | get statusMessage() { | |
| 395 | 390 | if (statusMessageWarned === false) { | |
| 396 | 391 | process.emitWarning( | |
@@ -403,6 +398,11 @@ class Http2ServerResponse extends Stream { | |||
| 403 | 398 | return ''; | |
| 404 | 399 | } | |
| 405 | 400 | ||
| 401 | + flushHeaders() { | ||
| 402 | + if (this[kStream].headersSent === false) | ||
| 403 | + this[kBeginSend](); | ||
| 404 | + } | ||
| 405 | + | ||
| 406 | 406 | writeHead(statusCode, statusMessage, headers) { | |
| 407 | 407 | if (typeof statusMessage === 'string' && statusMessageWarned === false) { | |
| 408 | 408 | process.emitWarning( | |
@@ -414,6 +414,12 @@ class Http2ServerResponse extends Stream { | |||
| 414 | 414 | if (headers === undefined && typeof statusMessage === 'object') { | |
| 415 | 415 | headers = statusMessage; | |
| 416 | 416 | } | |
| 417 | + | ||
| 418 | + const stream = this[kStream]; | ||
| 419 | + if (stream.headersSent === true) { | ||
| 420 | + throw new errors.Error('ERR_HTTP2_INFO_HEADERS_AFTER_RESPOND'); | ||
| 421 | + } | ||
| 422 | + | ||
| 417 | 423 | if (headers) { | |
| 418 | 424 | const keys = Object.keys(headers); | |
| 419 | 425 | let key = ''; | |
@@ -422,8 +428,9 @@ class Http2ServerResponse extends Stream { | |||
| 422 | 428 | this.setHeader(key, headers[key]); | |
| 423 | 429 | } | |
| 424 | 430 | } | |
| 431 | + | ||
| 425 | 432 | this.statusCode = statusCode; | |
| 426 | - // TODO mcollina this should probably call sendInfo | ||
| 433 | + this[kBeginSend](); | ||
| 427 | 434 | } | |
| 428 | 435 | ||
| 429 | 436 | write(chunk, encoding, cb) { | |
@@ -487,26 +494,6 @@ class Http2ServerResponse extends Stream { | |||
| 487 | 494 | stream.setTimeout(msecs, callback); | |
| 488 | 495 | } | |
| 489 | 496 | ||
| 490 | - sendContinue(headers) { | ||
| 491 | - this.sendInfo(100, headers); | ||
| 492 | - } | ||
| 493 | - | ||
| 494 | - sendInfo(code, headers) { | ||
| 495 | - const stream = this[kStream]; | ||
| 496 | - if (stream.headersSent === true) { | ||
| 497 | - throw new errors.Error('ERR_HTTP2_INFO_HEADERS_AFTER_RESPOND'); | ||
| 498 | - } | ||
| 499 | - if (headers && typeof headers !== 'object') | ||
| 500 | - throw new errors.TypeError('ERR_HTTP2_HEADERS_OBJECT'); | ||
| 501 | - if (stream === undefined) return; | ||
| 502 | - code |= 0; | ||
| 503 | - if (code < 100 || code >= 200) | ||
| 504 | - throw new errors.RangeError('ERR_HTTP2_INVALID_INFO_STATUS', code); | ||
| 505 | - | ||
| 506 | - headers[constants.HTTP2_HEADER_STATUS] = code; | ||
| 507 | - stream.respond(headers); | ||
| 508 | - } | ||
| 509 | - | ||
| 510 | 497 | createPushResponse(headers, callback) { | |
| 511 | 498 | const stream = this[kStream]; | |
| 512 | 499 | if (stream === undefined) { | |
@@ -544,9 +531,9 @@ class Http2ServerResponse extends Stream { | |||
| 544 | 531 | this.emit('finish'); | |
| 545 | 532 | } | |
| 546 | 533 | ||
| 547 | - // added for parity with HTTP/1 | ||
| 548 | 534 | writeContinue() { | |
| 549 | - // TODO mcollina this should probably be sendContinue | ||
| 535 | + // TODO mcollina check what is the continue flow | ||
| 536 | + throw new Error('not implemented yet'); | ||
| 550 | 537 | } | |
| 551 | 538 | } | |
| 552 | 539 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -46,7 +46,6 @@ const { | |||
| 46 | 46 | const server = createServer(mustCall((request, response) => { | |
| 47 | 47 | strictEqual(response.finished, true); | |
| 48 | 48 | response.writeHead(HTTP_STATUS_OK, { foo: 'bar' }); | |
| 49 | - response.flushHeaders(); | ||
| 50 | 49 | response.end(mustNotCall()); | |
| 51 | 50 | })); | |
| 52 | 51 | server.listen(0, mustCall(() => { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,18 +7,24 @@ const h2 = require('http2'); | |||
| 7 | 7 | ||
| 8 | 8 | // Http2ServerResponse.flushHeaders | |
| 9 | 9 | ||
| 10 | + let serverResponse; | ||
| 11 | + | ||
| 10 | 12 | const server = h2.createServer(); | |
| 11 | 13 | server.listen(0, common.mustCall(function() { | |
| 12 | 14 | const port = server.address().port; | |
| 13 | 15 | server.once('request', common.mustCall(function(request, response) { | |
| 14 | 16 | response.flushHeaders(); | |
| 15 | 17 | response.flushHeaders(); // Idempotent | |
| 16 | - response.writeHead(400, { 'foo-bar': 'abc123' }); // Ignored | ||
| 18 | + common.expectsError(() => { | ||
| 19 | + response.writeHead(400, { 'foo-bar': 'abc123' }); | ||
| 20 | + }, { | ||
| 21 | + code: 'ERR_HTTP2_INFO_HEADERS_AFTER_RESPOND' | ||
| 22 | + }); | ||
| 17 | 23 | ||
| 18 | 24 | response.on('finish', common.mustCall(function() { | |
| 19 | 25 | server.close(); | |
| 20 | 26 | })); | |
| 21 | - response.end(); | ||
| 27 | + serverResponse = response; | ||
| 22 | 28 | })); | |
| 23 | 29 | ||
| 24 | 30 | const url = `http://localhost:${port}`; | |
@@ -33,6 +39,7 @@ server.listen(0, common.mustCall(function() { | |||
| 33 | 39 | request.on('response', common.mustCall(function(headers, flags) { | |
| 34 | 40 | assert.strictEqual(headers['foo-bar'], undefined); | |
| 35 | 41 | assert.strictEqual(headers[':status'], 200); | |
| 42 | + serverResponse.end(); | ||
| 36 | 43 | }, 1)); | |
| 37 | 44 | request.on('end', common.mustCall(function() { | |
| 38 | 45 | client.destroy(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,11 +12,13 @@ server.listen(0, common.mustCall(function() { | |||
| 12 | 12 | const port = server.address().port; | |
| 13 | 13 | server.once('request', common.mustCall(function(request, response) { | |
| 14 | 14 | response.setHeader('foo-bar', 'def456'); | |
| 15 | - response.writeHead(500); | ||
| 16 | 15 | response.writeHead(418, { 'foo-bar': 'abc123' }); // Override | |
| 17 | 16 | ||
| 17 | + common.expectsError(() => { response.writeHead(300); }, { | ||
| 18 | + code: 'ERR_HTTP2_INFO_HEADERS_AFTER_RESPOND' | ||
| 19 | + }); | ||
| 20 | + | ||
| 18 | 21 | response.on('finish', common.mustCall(function() { | |
| 19 | - assert.doesNotThrow(() => { response.writeHead(300); }); | ||
| 20 | 22 | server.close(); | |
| 21 | 23 | })); | |
| 22 | 24 | response.end(); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments