forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make default `clientError` behavior (close socket immediately) overridable. With this APIs it is possible to write a custom error handler, and to send, for example, a 400 HTTP response. http.createServer(...).on('clientError', function(err, socket) { socket.end('HTTP/1.1 400 Bad Request\r\n\r\n'); socket.destroy(); }); Fix: nodejs#4543 PR-URL: nodejs#4557 Reviewed-By: Brian White <mscdex@mscdex.net>
- Loading branch information
Showing
6 changed files
with
56 additions
and
15 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
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,39 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
const http = require('http'); | ||
const net = require('net'); | ||
|
||
const server = http.createServer(common.mustCall(function(req, res) { | ||
res.end(); | ||
})); | ||
|
||
server.on('clientError', common.mustCall(function(err, socket) { | ||
socket.end('HTTP/1.1 400 Bad Request\r\n\r\n'); | ||
|
||
server.close(); | ||
})); | ||
|
||
server.listen(common.PORT, function() { | ||
function next() { | ||
// Invalid request | ||
const client = net.connect(common.PORT); | ||
client.end('Oopsie-doopsie\r\n'); | ||
|
||
var chunks = ''; | ||
client.on('data', function(chunk) { | ||
chunks += chunk; | ||
}); | ||
client.once('end', function() { | ||
assert.equal(chunks, 'HTTP/1.1 400 Bad Request\r\n\r\n'); | ||
}); | ||
} | ||
|
||
// Normal request | ||
http.get({ port: common.PORT, path: '/' }, function(res) { | ||
assert.equal(res.statusCode, 200); | ||
res.resume(); | ||
res.once('end', next); | ||
}); | ||
}); |
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