2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2016-05-29 09:06:56 +02:00
|
|
|
require('../common');
|
2016-12-31 00:38:06 +01:00
|
|
|
const assert = require('assert');
|
|
|
|
const http = require('http');
|
2010-09-10 03:56:35 +02:00
|
|
|
|
2017-01-08 14:19:00 +01:00
|
|
|
let outstanding_reqs = 0;
|
|
|
|
const test_req_body = 'some stuff...\n';
|
|
|
|
const test_res_body = 'other stuff!\n';
|
|
|
|
let sent_continue = false;
|
|
|
|
let got_continue = false;
|
2010-09-10 03:56:35 +02:00
|
|
|
|
|
|
|
function handler(req, res) {
|
2017-01-08 16:36:25 +01:00
|
|
|
assert.strictEqual(sent_continue, true, 'Full response sent before ' +
|
|
|
|
'100 Continue');
|
2015-09-27 00:49:04 +02:00
|
|
|
console.error('Server sending full response...');
|
2010-09-10 03:56:35 +02:00
|
|
|
res.writeHead(200, {
|
2016-05-05 07:20:27 +02:00
|
|
|
'Content-Type': 'text/plain',
|
|
|
|
'ABCD': '1'
|
2010-09-10 03:56:35 +02:00
|
|
|
});
|
|
|
|
res.end(test_res_body);
|
|
|
|
}
|
|
|
|
|
2017-01-08 14:19:00 +01:00
|
|
|
const server = http.createServer(handler);
|
2011-10-15 01:08:36 +02:00
|
|
|
server.on('checkContinue', function(req, res) {
|
2015-09-27 00:49:04 +02:00
|
|
|
console.error('Server got Expect: 100-continue...');
|
2010-12-05 23:33:52 +01:00
|
|
|
res.writeContinue();
|
|
|
|
sent_continue = true;
|
2012-01-30 16:16:01 +01:00
|
|
|
setTimeout(function() {
|
|
|
|
handler(req, res);
|
|
|
|
}, 100);
|
2010-12-05 23:33:52 +01:00
|
|
|
});
|
2016-05-29 09:06:56 +02:00
|
|
|
server.listen(0);
|
2010-09-10 03:56:35 +02:00
|
|
|
|
|
|
|
|
2011-10-15 01:08:36 +02:00
|
|
|
server.on('listening', function() {
|
2017-01-08 14:19:00 +01:00
|
|
|
const req = http.request({
|
2016-05-29 09:06:56 +02:00
|
|
|
port: this.address().port,
|
2011-10-05 00:08:18 +02:00
|
|
|
method: 'POST',
|
|
|
|
path: '/world',
|
2011-08-14 08:02:14 +02:00
|
|
|
headers: { 'Expect': '100-continue' }
|
2010-09-10 03:56:35 +02:00
|
|
|
});
|
2015-09-27 00:49:04 +02:00
|
|
|
console.error('Client sending request...');
|
2010-09-10 03:56:35 +02:00
|
|
|
outstanding_reqs++;
|
2017-01-08 14:19:00 +01:00
|
|
|
let body = '';
|
2011-10-15 01:08:36 +02:00
|
|
|
req.on('continue', function() {
|
2015-09-27 00:49:04 +02:00
|
|
|
console.error('Client got 100 Continue...');
|
2010-12-05 23:33:52 +01:00
|
|
|
got_continue = true;
|
|
|
|
req.end(test_req_body);
|
2010-09-10 03:56:35 +02:00
|
|
|
});
|
2011-10-15 01:08:36 +02:00
|
|
|
req.on('response', function(res) {
|
2017-01-08 16:36:25 +01:00
|
|
|
assert.strictEqual(got_continue, true,
|
|
|
|
'Full response received before 100 Continue');
|
|
|
|
assert.strictEqual(200, res.statusCode, 'Final status code was ' +
|
|
|
|
res.statusCode + ', not 200.');
|
2010-12-05 23:33:52 +01:00
|
|
|
res.setEncoding('utf8');
|
2011-10-15 01:08:36 +02:00
|
|
|
res.on('data', function(chunk) { body += chunk; });
|
|
|
|
res.on('end', function() {
|
2015-09-27 00:49:04 +02:00
|
|
|
console.error('Got full response.');
|
2017-01-08 16:36:25 +01:00
|
|
|
assert.strictEqual(body, test_res_body, 'Response body doesn\'t match.');
|
2010-12-05 23:33:52 +01:00
|
|
|
assert.ok('abcd' in res.headers, 'Response headers missing.');
|
2010-09-10 03:56:35 +02:00
|
|
|
outstanding_reqs--;
|
2016-08-18 01:14:43 +02:00
|
|
|
if (outstanding_reqs === 0) {
|
2010-09-10 03:56:35 +02:00
|
|
|
server.close();
|
|
|
|
process.exit();
|
2010-12-05 23:33:52 +01:00
|
|
|
}
|
2010-09-10 03:56:35 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|