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');
|
|
|
|
const assert = require('assert');
|
2015-03-04 02:11:21 +01:00
|
|
|
|
|
|
|
if (!common.hasCrypto) {
|
2016-05-11 21:34:52 +02:00
|
|
|
common.skip('missing crypto');
|
2015-07-07 17:25:55 +02:00
|
|
|
return;
|
2015-03-04 02:11:21 +01:00
|
|
|
}
|
2016-12-31 00:38:06 +01:00
|
|
|
const https = require('https');
|
|
|
|
const tls = require('tls');
|
2015-03-04 02:11:21 +01:00
|
|
|
|
2016-12-31 00:38:06 +01:00
|
|
|
const fs = require('fs');
|
2011-02-16 01:45:54 +01:00
|
|
|
|
2017-01-08 14:19:00 +01:00
|
|
|
const options = {
|
2011-02-16 01:45:54 +01:00
|
|
|
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
|
|
|
|
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem')
|
|
|
|
};
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
}));
|