-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http: improves expect header handling
Now returns a 417 error status or allows for an event listener on the `checkExpectation` event. Before we were ignoring requests that had misspelled `100-continue` values for expect headers. This is a quick port of the work done here: nodejs/node-v0.x-archive#7132 by alFReD-NSH with surrounding discussion here: nodejs/node-v0.x-archive#4651 Also updates all the instances of the deprecated EventEmitter.listenerCount to the current self.listenerCount. Most of these were in the new code ported over but there was another legacy instance. Refs: #2403 PR-URL: #4501 Reviewed-By: James M Snell <[email protected]>
- Loading branch information
1 parent
4383acd
commit d755432
Showing
3 changed files
with
83 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Spec documentation http://httpwg.github.io/specs/rfc7231.html#header.expect | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const http = require('http'); | ||
|
||
const tests = [417, 417]; | ||
|
||
let testsComplete = 0; | ||
let testIdx = 0; | ||
|
||
const s = http.createServer(function(req, res) { | ||
throw new Error('this should never be executed'); | ||
}); | ||
|
||
s.listen(common.PORT, nextTest); | ||
|
||
function nextTest() { | ||
const options = { | ||
port: common.PORT, | ||
headers: { 'Expect': 'meoww' } | ||
}; | ||
|
||
if (testIdx === tests.length) { | ||
return s.close(); | ||
} | ||
|
||
const test = tests[testIdx]; | ||
|
||
if (testIdx > 0) { | ||
s.on('checkExpectation', common.mustCall((req, res) => { | ||
res.statusCode = 417; | ||
res.end(); | ||
})); | ||
} | ||
|
||
http.get(options, function(response) { | ||
console.log('client: expected status: ' + test); | ||
console.log('client: statusCode: ' + response.statusCode); | ||
assert.equal(response.statusCode, test); | ||
assert.equal(response.statusMessage, 'Expectation Failed'); | ||
|
||
response.on('end', function() { | ||
testsComplete++; | ||
testIdx++; | ||
nextTest(); | ||
}); | ||
response.resume(); | ||
}); | ||
} | ||
|
||
|
||
process.on('exit', function() { | ||
assert.equal(2, testsComplete); | ||
}); |