-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http2: emit close event if request aborted
Fix Http2ServerRequest and Http2ServerResponse to emit close event if the request is aborted before response.end can be called. Fixes: #15385 PR-URL: #15415 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]>
- Loading branch information
1 parent
f0e411d
commit 2ea2725
Showing
2 changed files
with
51 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Flags: --expose-http2 --expose-internals | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
const h2 = require('http2'); | ||
|
||
// Server request and response should receive close event | ||
// if the connection was terminated before response.end | ||
// could be called or flushed | ||
|
||
const server = h2.createServer(common.mustCall((req, res) => { | ||
res.writeHead(200); | ||
res.write('a'); | ||
|
||
req.on('close', common.mustCall()); | ||
res.on('close', common.mustCall()); | ||
})); | ||
server.listen(0); | ||
|
||
server.on('listening', function() { | ||
const port = server.address().port; | ||
|
||
const url = `http://localhost:${port}`; | ||
const client = h2.connect(url, common.mustCall(function() { | ||
const headers = { | ||
':path': '/foobar', | ||
':method': 'GET', | ||
':scheme': 'http', | ||
':authority': `localhost:${port}`, | ||
}; | ||
const request = client.request(headers); | ||
request.on('data', common.mustCall(function(chunk) { | ||
// cause an error on the server side | ||
client.destroy(); | ||
server.close(); | ||
})); | ||
request.end(); | ||
})); | ||
}); |