GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — http2: make compat writeHead not crash if the stream is destroyed · nodejs/node@f4aed8c

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal/http2
    • compat.js
  • test/parallel
    • test-http2-compat-write-head-destroyed.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/http2/compat.js‎

Copy file name to clipboardExpand all lines: lib/internal/http2/compat.js
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,11 @@ class Http2ServerResponse extends Stream {
568568
if (this[kStream].headersSent)
569569
throw new ERR_HTTP2_HEADERS_SENT();
570570

571+
// If the stream is destroyed, we return false,
572+
// like require('http').
573+
if (this.stream.destroyed)
574+
return false;
575+
571576
if (typeof statusMessage === 'string')
572577
statusMessageWarn();
573578

Collapse file

‎test/parallel/test-http2-compat-write-head-destroyed.js‎

Copy file name to clipboard
+29Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
if (!common.hasCrypto)
5+
common.skip('missing crypto');
6+
const http2 = require('http2');
7+
8+
// Check that writeHead, write and end do not crash in compatibility mode
9+
10+
const server = http2.createServer(common.mustCall((req, res) => {
11+
// destroy the stream first
12+
req.stream.destroy();
13+
14+
res.writeHead(200);
15+
res.write('hello ');
16+
res.end('world');
17+
}));
18+
19+
server.listen(0, common.mustCall(() => {
20+
const client = http2.connect(`http://localhost:${server.address().port}`);
21+
22+
const req = client.request();
23+
req.on('response', common.mustNotCall());
24+
req.on('close', common.mustCall((arg) => {
25+
client.close();
26+
server.close();
27+
}));
28+
req.resume();
29+
}));

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.