| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d6ba14e commit f2f391e
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -38,6 +38,7 @@ const { | |||
| 38 | 38 | const { OutgoingMessage } = require('_http_outgoing'); | |
| 39 | 39 | const { outHeadersKey, ondrain } = require('internal/http'); | |
| 40 | 40 | const errors = require('internal/errors'); | |
| 41 | + const Buffer = require('buffer').Buffer; | ||
| 41 | 42 | ||
| 42 | 43 | const STATUS_CODES = { | |
| 43 | 44 | 100: 'Continue', | |
@@ -451,13 +452,21 @@ function onParserExecute(server, socket, parser, state, ret, d) { | |||
| 451 | 452 | onParserExecuteCommon(server, socket, parser, state, ret, undefined); | |
| 452 | 453 | } | |
| 453 | 454 | ||
| 455 | + const badRequestResponse = Buffer.from( | ||
| 456 | + 'HTTP/1.1 400 ' + STATUS_CODES[400] + CRLF + CRLF, 'ascii' | ||
| 457 | + ); | ||
| 454 | 458 | function socketOnError(e) { | |
| 455 | 459 | // Ignore further errors | |
| 456 | 460 | this.removeListener('error', socketOnError); | |
| 457 | 461 | this.on('error', () => {}); | |
| 458 | 462 | ||
| 459 | - if (!this.server.emit('clientError', e, this)) | ||
| 463 | + if (!this.server.emit('clientError', e, this)) { | ||
| 464 | + if (this.writable) { | ||
| 465 | + this.end(badRequestResponse); | ||
| 466 | + return; | ||
| 467 | + } | ||
| 460 | 468 | this.destroy(e); | |
| 469 | + } | ||
| 461 | 470 | } | |
| 462 | 471 | ||
| 463 | 472 | function onParserExecuteCommon(server, socket, parser, state, ret, d) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -38,6 +38,7 @@ const server = http.createServer(common.mustCall((req, res) => { | |||
| 38 | 38 | ||
| 39 | 39 | server.listen(0, common.mustCall(() => { | |
| 40 | 40 | const c = net.createConnection(server.address().port); | |
| 41 | + let received = ''; | ||
| 41 | 42 | ||
| 42 | 43 | c.on('connect', common.mustCall(() => { | |
| 43 | 44 | c.write('GET /blah HTTP/1.1\r\n' + | |
@@ -47,7 +48,12 @@ server.listen(0, common.mustCall(() => { | |||
| 47 | 48 | '\r\n\r\nhello world' | |
| 48 | 49 | ); | |
| 49 | 50 | })); | |
| 50 | - | ||
| 51 | - c.on('end', common.mustCall(() => c.end())); | ||
| 51 | + c.on('data', common.mustCall((data) => { | ||
| 52 | + received += data.toString(); | ||
| 53 | + })); | ||
| 54 | + c.on('end', common.mustCall(() => { | ||
| 55 | + assert.strictEqual('HTTP/1.1 400 Bad Request\r\n\r\n', received); | ||
| 56 | + c.end(); | ||
| 57 | + })); | ||
| 52 | 58 | c.on('close', common.mustCall(() => server.close())); | |
| 53 | 59 | })); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments