Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 36.5k
http: fix just-merged change that could silently truncate responses#64507
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
base:main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| 'use strict'; | ||
| const common = require('../common'); | ||
| const assert = require('assert'); | ||
| const http = require('http'); | ||
| const BODY = Buffer.alloc(1024 * 1024); | ||
| const server = http.createServer(common.mustCall((request, response) => { | ||
| response.writeHead(202, { 'content-length': 0 }); | ||
| response.end(); | ||
| request.once('data', common.mustCall(() => { | ||
| request.socket.resetAndDestroy(); | ||
| })); | ||
| })); | ||
| server.on('clientError', common.mustNotCall()); | ||
| server.listen(0, common.mustCall(() => { | ||
| let response; | ||
| const req = http.request({ | ||
| method: 'POST', | ||
| port: server.address().port, | ||
| headers: { 'content-length': BODY.length }, | ||
| }, common.mustCall((res) => { | ||
| response = res; | ||
| assert.strictEqual(res.statusCode, 202); | ||
| assert.strictEqual(req.writableEnded, false); | ||
| req.write(BODY); | ||
| })); | ||
| req.on('error', common.mustCall((err) => { | ||
| assert(response); | ||
| assert.strictEqual(response.complete, true); | ||
| assert.strictEqual(req.writableFinished, false); | ||
| assert.strictEqual(err.code, 'ECONNRESET'); | ||
Check failure on line 37 in test/parallel/test-http-client-complete-response-open-request-reset.js
| ||
This comment was marked as spam.Sorry, something went wrong. Uh oh!There was an error while loading. Please reload this page. | ||
| })); | ||
| req.on('close', common.mustCall(() => server.close())); | ||
| req.flushHeaders(); | ||
| })); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| 'use strict'; | ||
| const common = require('../common'); | ||
| const assert = require('assert'); | ||
| const http = require('http'); | ||
| // A response that is cut short by a connection reset must still surface the | ||
| // socket error on the request. The response exists, but it is not complete, so | ||
| // swallowing the error would leave the application with a silently truncated | ||
| // body it believes is intact. | ||
| const LENGTH = 1024; | ||
| let serverSocket; | ||
| const server = http.createServer(common.mustCall((request, response) => { | ||
| serverSocket = request.socket; | ||
| // Promise more body than is ever sent. | ||
| response.writeHead(200, { 'content-length': LENGTH }); | ||
| response.write('hello'); | ||
| })); | ||
| server.on('clientError', common.mustNotCall()); | ||
| server.listen(0, common.mustCall(() => { | ||
| const req = http.request({ port: server.address().port }, common.mustCall((res) => { | ||
| assert.strictEqual(res.statusCode, 200); | ||
| let received = 0; | ||
| let reset = false; | ||
| res.on('data', common.mustCallAtLeast((chunk) => { | ||
| received += chunk.length; | ||
| if (reset) return; | ||
| reset = true; | ||
| // The headers and part of the body have arrived. Reset from the server | ||
| // side so the client sees a genuine inbound RST mid-body. | ||
| serverSocket.resetAndDestroy(); | ||
| }, 1)); | ||
| res.on('end', common.mustNotCall()); | ||
| res.on('close', common.mustCall(() => { | ||
| assert.strictEqual(res.complete, false); | ||
| assert.strictEqual(res.errored.code, 'ECONNRESET'); | ||
| assert.strictEqual(res.errored.message, 'aborted'); | ||
| assert.ok(received > 0 && received < LENGTH, | ||
| `expected a truncated body, got ${received} of ${LENGTH}`); | ||
| server.close(); | ||
| })); | ||
| })); | ||
| req.on('error', common.mustCall((err) => { | ||
| assert.strictEqual(err.code, 'ECONNRESET'); | ||
| })); | ||
| req.end(); | ||
| })); |
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.