-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
http: add req.signal to IncomingMessage #62541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
e265c6d
18f6103
b9a1333
bdf63e1
48d116f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| 'use strict'; | ||
|
|
||
| const common = require('../common'); | ||
| const assert = require('assert'); | ||
| const http = require('http'); | ||
|
|
||
| // Test 1: req.signal is an AbortSignal and aborts on 'close' | ||
| { | ||
| const server = http.createServer(common.mustCall((req, res) => { | ||
| assert.ok(req.signal instanceof AbortSignal); | ||
| assert.strictEqual(req.signal.aborted, false); | ||
| req.signal.onabort = common.mustCall(() => { | ||
| assert.strictEqual(req.signal.aborted, true); | ||
| }); | ||
| res.destroy(); | ||
| })); | ||
| server.listen(0, common.mustCall(() => { | ||
| http.get({ port: server.address().port }, () => {}).on('error', () => { | ||
| server.close(); | ||
| }); | ||
| })); | ||
| } | ||
|
|
||
| // Test 2: req.signal is aborted if accessed after destroy | ||
| { | ||
| const req = new http.IncomingMessage(null); | ||
| req.destroy(); | ||
| assert.strictEqual(req.signal.aborted, true); | ||
| } | ||
|
|
||
| // Test 3: Multiple accesses return the same signal | ||
| { | ||
| const req = new http.IncomingMessage(null); | ||
| assert.strictEqual(req.signal, req.signal); | ||
| } | ||
|
|
||
| // Test 4: req.signal aborts when 'abort' event is emitted on req | ||
| { | ||
| const req = new http.IncomingMessage(null); | ||
| const signal = req.signal; | ||
| assert.strictEqual(signal.aborted, false); | ||
| req.emit('abort'); | ||
| assert.strictEqual(signal.aborted, true); | ||
| } | ||
|
|
||
| // Test 5: res.signal on a client-side http.request() response (IncomingMessage). | ||
| { | ||
| const server = http.createServer(common.mustCall((req, res) => { | ||
| res.writeHead(200); | ||
| res.write('partial'); | ||
| })); | ||
|
|
||
| server.listen(0, common.mustCall(() => { | ||
| const clientReq = http.request( | ||
| { port: server.address().port }, | ||
| common.mustCall((res) => { | ||
| assert.ok(res.signal instanceof AbortSignal); | ||
| assert.strictEqual(res.signal.aborted, false); | ||
|
|
||
| res.signal.onabort = common.mustCall(() => { | ||
| assert.strictEqual(res.signal.aborted, true); | ||
| server.close(); | ||
| }); | ||
| clientReq.destroy(); | ||
| }), | ||
| ); | ||
| clientReq.on('error', () => {}); | ||
| clientReq.end(); | ||
| })); | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the most important case here isn't covered: server receives a request & doesn't end the response (stays pending) => client aborts the request while it's incomplete (so the connection closes) => server should see The two full-flow tests here (1 and 5) only cover Looks like it should work, but we need to test to make sure we actually cover that integration.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks,I have added the test in the latest commit |
||
Uh oh!
There was an error while loading. Please reload this page.