-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http2: fix issues with aborted
respondWithFile()
s
PR-URL: #21561 Fixes: #20824 Fixes: #21560 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
- Loading branch information
Showing
4 changed files
with
52 additions
and
9 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
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
37 changes: 37 additions & 0 deletions
37
test/parallel/test-http2-respond-with-file-connection-abort.js
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,37 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
const http2 = require('http2'); | ||
const net = require('net'); | ||
|
||
const { | ||
HTTP2_HEADER_CONTENT_TYPE | ||
} = http2.constants; | ||
|
||
const server = http2.createServer(); | ||
server.on('stream', common.mustCall((stream) => { | ||
stream.respondWithFile(process.execPath, { | ||
[HTTP2_HEADER_CONTENT_TYPE]: 'application/octet-stream' | ||
}); | ||
})); | ||
|
||
server.listen(0, common.mustCall(() => { | ||
const client = http2.connect(`http://localhost:${server.address().port}`); | ||
const req = client.request(); | ||
|
||
req.on('response', common.mustCall(() => {})); | ||
req.on('data', common.mustCall(() => { | ||
net.Socket.prototype.destroy.call(client.socket); | ||
server.close(); | ||
})); | ||
req.end(); | ||
})); | ||
|
||
// TODO(addaleax): This is a *hack*. HTTP/2 needs to have a proper way of | ||
// dealing with this kind of issue. | ||
process.once('uncaughtException', (err) => { | ||
if (err.code === 'ECONNRESET') return; | ||
throw err; | ||
}); |