2017-01-03 22:16:48 +01: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';
|
2011-02-16 01:45:54 +01:00
|
|
|
// I hate HTTP. One way of terminating an HTTP response is to not send
|
|
|
|
// a content-length header, not send a transfer-encoding: chunked header,
|
|
|
|
// and simply terminate the TCP connection. That is identity
|
|
|
|
// transfer-encoding.
|
|
|
|
//
|
|
|
|
// This test is to be sure that the https client is handling this case
|
|
|
|
// correctly.
|
|
|
|
|
2016-12-31 00:38:06 +01:00
|
|
|
const common = require('../common');
|
2017-07-01 01:29:09 +02:00
|
|
|
if (!common.hasCrypto)
|
2016-05-11 21:34:52 +02:00
|
|
|
common.skip('missing crypto');
|
2017-07-01 01:29:09 +02:00
|
|
|
|
|
|
|
const assert = require('assert');
|
2016-12-31 00:38:06 +01:00
|
|
|
const https = require('https');
|
|
|
|
const tls = require('tls');
|
2017-10-06 18:52:28 +02:00
|
|
|
const fixtures = require('../common/fixtures');
|
2011-02-16 01:45:54 +01:00
|
|
|
|
2017-01-08 14:19:00 +01:00
|
|
|
const options = {
|
2017-10-06 18:52:28 +02:00
|
|
|
key: fixtures.readKey('agent1-key.pem'),
|
|
|
|
cert: fixtures.readKey('agent1-cert.pem')
|
2011-02-16 01:45:54 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-01-08 14:19:00 +01:00
|
|
|
const server = tls.Server(options, function(socket) {
|
2011-02-16 01:45:54 +01:00
|
|
|
console.log('2) Server got request');
|
|
|
|
socket.write('HTTP/1.1 200 OK\r\n' +
|
|
|
|
'Date: Tue, 15 Feb 2011 22:14:54 GMT\r\n' +
|
|
|
|
'Expires: -1\r\n' +
|
|
|
|
'Cache-Control: private, max-age=0\r\n' +
|
|
|
|
'Set-Cookie: xyz\r\n' +
|
|
|
|
'Set-Cookie: abc\r\n' +
|
|
|
|
'Server: gws\r\n' +
|
|
|
|
'X-XSS-Protection: 1; mode=block\r\n' +
|
|
|
|
'Connection: close\r\n' +
|
|
|
|
'\r\n');
|
|
|
|
|
|
|
|
socket.write('hello world\n');
|
|
|
|
|
|
|
|
setTimeout(function() {
|
|
|
|
socket.end('hello world\n');
|
|
|
|
console.log('4) Server finished response');
|
|
|
|
}, 100);
|
|
|
|
});
|
|
|
|
|
2016-07-15 21:43:24 +02:00
|
|
|
server.listen(0, common.mustCall(function() {
|
2011-10-05 00:08:18 +02:00
|
|
|
console.log('1) Making Request');
|
2015-12-26 07:00:10 +01:00
|
|
|
https.get({
|
2016-05-29 09:06:56 +02:00
|
|
|
port: this.address().port,
|
2012-08-30 16:43:20 +02:00
|
|
|
rejectUnauthorized: false
|
2016-07-15 21:43:24 +02:00
|
|
|
}, common.mustCall(function(res) {
|
2017-01-08 14:19:00 +01:00
|
|
|
let bodyBuffer = '';
|
2016-07-15 21:43:24 +02:00
|
|
|
|
2011-02-16 01:45:54 +01:00
|
|
|
server.close();
|
|
|
|
console.log('3) Client got response headers.');
|
|
|
|
|
2017-01-08 16:36:25 +01:00
|
|
|
assert.strictEqual('gws', res.headers.server);
|
2011-02-16 01:45:54 +01:00
|
|
|
|
|
|
|
res.setEncoding('utf8');
|
|
|
|
res.on('data', function(s) {
|
|
|
|
bodyBuffer += s;
|
|
|
|
});
|
|
|
|
|
2016-07-15 21:43:24 +02:00
|
|
|
res.on('end', common.mustCall(function() {
|
2011-02-16 01:45:54 +01:00
|
|
|
console.log('5) Client got "end" event.');
|
2016-07-15 21:43:24 +02:00
|
|
|
assert.strictEqual('hello world\nhello world\n', bodyBuffer);
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
}));
|