2015-12-30 21:31:25 -07:00
|
|
|
// 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;
|
|
|
|
|
2018-11-17 17:36:44 +05:30
|
|
|
const s = http.createServer((req, res) => {
|
2015-12-30 21:31:25 -07:00
|
|
|
throw new Error('this should never be executed');
|
|
|
|
});
|
|
|
|
|
2016-05-29 03:06:56 -04:00
|
|
|
s.listen(0, nextTest);
|
2015-12-30 21:31:25 -07:00
|
|
|
|
|
|
|
function nextTest() {
|
|
|
|
const options = {
|
2016-05-29 03:06:56 -04:00
|
|
|
port: s.address().port,
|
2015-12-30 21:31:25 -07:00
|
|
|
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();
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2018-11-17 17:36:44 +05:30
|
|
|
http.get(options, (response) => {
|
2017-04-28 04:06:42 +03:00
|
|
|
console.log(`client: expected status: ${test}`);
|
|
|
|
console.log(`client: statusCode: ${response.statusCode}`);
|
2017-01-08 15:36:25 +00:00
|
|
|
assert.strictEqual(response.statusCode, test);
|
|
|
|
assert.strictEqual(response.statusMessage, 'Expectation Failed');
|
2015-12-30 21:31:25 -07:00
|
|
|
|
2018-11-17 17:36:44 +05:30
|
|
|
response.on('end', () => {
|
2015-12-30 21:31:25 -07:00
|
|
|
testsComplete++;
|
|
|
|
testIdx++;
|
|
|
|
nextTest();
|
|
|
|
});
|
|
|
|
response.resume();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-17 17:36:44 +05:30
|
|
|
process.on('exit', () => {
|
2018-10-12 09:33:32 -07:00
|
|
|
assert.strictEqual(testsComplete, 2);
|
2015-12-30 21:31:25 -07:00
|
|
|
});
|