2017-01-03 13:16:48 -08:00
|
|
|
// Copyright Joyent, Inc. and other Node contributors.
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
// copy of this software and associated documentation files (the
|
|
|
|
// "Software"), to deal in the Software without restriction, including
|
|
|
|
// without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
|
|
// persons to whom the Software is furnished to do so, subject to the
|
|
|
|
// following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included
|
|
|
|
// in all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
|
|
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
|
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
|
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2018-03-26 21:08:24 -07:00
|
|
|
const common = require('../common');
|
2016-12-30 18:38:06 -05:00
|
|
|
const assert = require('assert');
|
|
|
|
const http = require('http');
|
2010-09-10 11:56:35 +10:00
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
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 11:56:35 +10:00
|
|
|
|
2018-03-26 21:08:24 -07:00
|
|
|
const handler = common.mustCall((req, res) => {
|
|
|
|
assert.ok(sent_continue, 'Full response sent before 100 Continue');
|
2015-09-26 15:49:04 -07:00
|
|
|
console.error('Server sending full response...');
|
2010-09-10 11:56:35 +10:00
|
|
|
res.writeHead(200, {
|
2016-05-04 22:20:27 -07:00
|
|
|
'Content-Type': 'text/plain',
|
|
|
|
'ABCD': '1'
|
2010-09-10 11:56:35 +10:00
|
|
|
});
|
|
|
|
res.end(test_res_body);
|
2018-03-26 21:08:24 -07:00
|
|
|
});
|
2010-09-10 11:56:35 +10:00
|
|
|
|
2018-03-28 21:24:50 -07:00
|
|
|
const server = http.createServer(common.mustNotCall());
|
2018-03-26 21:08:24 -07:00
|
|
|
server.on('checkContinue', common.mustCall((req, res) => {
|
2015-09-26 15:49:04 -07:00
|
|
|
console.error('Server got Expect: 100-continue...');
|
2010-12-06 01:33:52 +03:00
|
|
|
res.writeContinue();
|
|
|
|
sent_continue = true;
|
2012-01-31 00:16:01 +09:00
|
|
|
setTimeout(function() {
|
|
|
|
handler(req, res);
|
|
|
|
}, 100);
|
2018-03-26 21:08:24 -07:00
|
|
|
}));
|
2016-05-29 03:06:56 -04:00
|
|
|
server.listen(0);
|
2010-09-10 11:56:35 +10:00
|
|
|
|
|
|
|
|
2018-03-26 21:08:24 -07:00
|
|
|
server.on('listening', common.mustCall(() => {
|
2017-01-08 13:19:00 +00:00
|
|
|
const req = http.request({
|
2018-03-26 21:08:24 -07:00
|
|
|
port: server.address().port,
|
2011-10-04 18:08:18 -04:00
|
|
|
method: 'POST',
|
|
|
|
path: '/world',
|
2011-08-14 15:02:14 +09:00
|
|
|
headers: { 'Expect': '100-continue' }
|
2010-09-10 11:56:35 +10:00
|
|
|
});
|
2015-09-26 15:49:04 -07:00
|
|
|
console.error('Client sending request...');
|
2017-01-08 13:19:00 +00:00
|
|
|
let body = '';
|
2018-03-26 21:08:24 -07:00
|
|
|
req.on('continue', common.mustCall(() => {
|
2015-09-26 15:49:04 -07:00
|
|
|
console.error('Client got 100 Continue...');
|
2010-12-06 01:33:52 +03:00
|
|
|
got_continue = true;
|
|
|
|
req.end(test_req_body);
|
2018-03-26 21:08:24 -07:00
|
|
|
}));
|
|
|
|
req.on('response', common.mustCall((res) => {
|
|
|
|
assert.ok(got_continue, 'Full response received before 100 Continue');
|
2018-11-06 14:29:34 +00:00
|
|
|
assert.strictEqual(res.statusCode, 200,
|
2017-04-28 04:06:42 +03:00
|
|
|
`Final status code was ${res.statusCode}, not 200.`);
|
2010-12-06 01:33:52 +03:00
|
|
|
res.setEncoding('utf8');
|
2011-10-15 01:08:36 +02:00
|
|
|
res.on('data', function(chunk) { body += chunk; });
|
2018-03-26 21:08:24 -07:00
|
|
|
res.on('end', common.mustCall(() => {
|
2015-09-26 15:49:04 -07:00
|
|
|
console.error('Got full response.');
|
2018-03-26 21:08:24 -07:00
|
|
|
assert.strictEqual(body, test_res_body);
|
2010-12-06 01:33:52 +03:00
|
|
|
assert.ok('abcd' in res.headers, 'Response headers missing.');
|
2018-03-26 21:08:24 -07:00
|
|
|
server.close();
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
}));
|