1// Copyright Joyent, Inc. and other Node contributors. 2// 3// Permission is hereby granted, free of charge, to any person obtaining a 4// copy of this software and associated documentation files (the 5// "Software"), to deal in the Software without restriction, including 6// without limitation the rights to use, copy, modify, merge, publish, 7// distribute, sublicense, and/or sell copies of the Software, and to permit 8// persons to whom the Software is furnished to do so, subject to the 9// following conditions: 10// 11// The above copyright notice and this permission notice shall be included 12// in all copies or substantial portions of the Software. 13// 14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 17// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 20// USE OR OTHER DEALINGS IN THE SOFTWARE. 21 22'use strict'; 23// I hate HTTP. One way of terminating an HTTP response is to not send 24// a content-length header, not send a transfer-encoding: chunked header, 25// and simply terminate the TCP connection. That is identity 26// transfer-encoding. 27// 28// This test is to be sure that the https client is handling this case 29// correctly. 30 31const common = require('../common'); 32if (!common.hasCrypto) 33 common.skip('missing crypto'); 34 35const assert = require('assert'); 36const https = require('https'); 37const tls = require('tls'); 38const fixtures = require('../common/fixtures'); 39 40const options = { 41 key: fixtures.readKey('agent1-key.pem'), 42 cert: fixtures.readKey('agent1-cert.pem') 43}; 44 45 46const server = tls.Server(options, function(socket) { 47 console.log('2) Server got request'); 48 socket.write('HTTP/1.1 200 OK\r\n' + 49 'Date: Tue, 15 Feb 2011 22:14:54 GMT\r\n' + 50 'Expires: -1\r\n' + 51 'Cache-Control: private, max-age=0\r\n' + 52 'Set-Cookie: xyz\r\n' + 53 'Set-Cookie: abc\r\n' + 54 'Server: gws\r\n' + 55 'X-XSS-Protection: 1; mode=block\r\n' + 56 'Connection: close\r\n' + 57 '\r\n'); 58 59 socket.write('hello world\n'); 60 61 setTimeout(function() { 62 socket.end('hello world\n'); 63 console.log('4) Server finished response'); 64 }, 100); 65}); 66 67server.listen(0, common.mustCall(function() { 68 console.log('1) Making Request'); 69 https.get({ 70 port: this.address().port, 71 rejectUnauthorized: false 72 }, common.mustCall(function(res) { 73 let bodyBuffer = ''; 74 75 server.close(); 76 console.log('3) Client got response headers.'); 77 78 assert.strictEqual(res.headers.server, 'gws'); 79 80 res.setEncoding('utf8'); 81 res.on('data', function(s) { 82 bodyBuffer += s; 83 }); 84 85 res.on('end', common.mustCall(function() { 86 console.log('5) Client got "end" event.'); 87 assert.strictEqual(bodyBuffer, 'hello world\nhello world\n'); 88 })); 89 })); 90})); 91