2017-01-03 21:16:48 +00: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 11:00:06 +00:00
|
|
|
'use strict';
|
2016-05-29 07:06:56 +00:00
|
|
|
require('../common');
|
2016-12-30 23:38:06 +00:00
|
|
|
const assert = require('assert');
|
|
|
|
const http = require('http');
|
2017-12-06 18:36:28 +00:00
|
|
|
const Countdown = require('../common/countdown');
|
2010-08-21 23:34:38 +00:00
|
|
|
|
2017-12-06 18:36:28 +00:00
|
|
|
const countdown = new Countdown(2, () => server.close());
|
2017-01-08 13:19:00 +00:00
|
|
|
const server = http.createServer(function(req, res) {
|
2016-08-17 23:14:43 +00:00
|
|
|
if (req.url === '/one') {
|
2010-12-05 22:33:52 +00:00
|
|
|
res.writeHead(200, [['set-cookie', 'A'],
|
|
|
|
['content-type', 'text/plain']]);
|
|
|
|
res.end('one\n');
|
2010-08-21 23:34:38 +00:00
|
|
|
} else {
|
2010-12-05 22:33:52 +00:00
|
|
|
res.writeHead(200, [['set-cookie', 'A'],
|
|
|
|
['set-cookie', 'B'],
|
|
|
|
['content-type', 'text/plain']]);
|
|
|
|
res.end('two\n');
|
2010-08-21 23:34:38 +00:00
|
|
|
}
|
|
|
|
});
|
2016-05-29 07:06:56 +00:00
|
|
|
server.listen(0);
|
2010-08-21 23:34:38 +00:00
|
|
|
|
2011-10-14 23:08:36 +00:00
|
|
|
server.on('listening', function() {
|
2010-08-21 23:34:38 +00:00
|
|
|
//
|
|
|
|
// one set-cookie header
|
|
|
|
//
|
2016-05-29 07:06:56 +00:00
|
|
|
http.get({ port: this.address().port, path: '/one' }, function(res) {
|
2010-08-21 23:34:38 +00:00
|
|
|
// set-cookie headers are always return in an array.
|
|
|
|
// even if there is only one.
|
2018-10-12 17:03:58 +00:00
|
|
|
assert.deepStrictEqual(res.headers['set-cookie'], ['A']);
|
|
|
|
assert.strictEqual(res.headers['content-type'], 'text/plain');
|
2010-08-21 23:34:38 +00:00
|
|
|
|
2011-10-14 23:08:36 +00:00
|
|
|
res.on('data', function(chunk) {
|
2010-08-21 23:34:38 +00:00
|
|
|
console.log(chunk.toString());
|
|
|
|
});
|
|
|
|
|
2011-10-14 23:08:36 +00:00
|
|
|
res.on('end', function() {
|
2017-12-06 18:36:28 +00:00
|
|
|
countdown.dec();
|
2010-08-21 23:34:38 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-03-22 02:44:26 +00:00
|
|
|
// Two set-cookie headers
|
2010-08-21 23:34:38 +00:00
|
|
|
|
2016-05-29 07:06:56 +00:00
|
|
|
http.get({ port: this.address().port, path: '/two' }, function(res) {
|
2018-10-12 17:03:58 +00:00
|
|
|
assert.deepStrictEqual(res.headers['set-cookie'], ['A', 'B']);
|
|
|
|
assert.strictEqual(res.headers['content-type'], 'text/plain');
|
2010-08-21 23:34:38 +00:00
|
|
|
|
2011-10-14 23:08:36 +00:00
|
|
|
res.on('data', function(chunk) {
|
2010-08-21 23:34:38 +00:00
|
|
|
console.log(chunk.toString());
|
|
|
|
});
|
|
|
|
|
2011-10-14 23:08:36 +00:00
|
|
|
res.on('end', function() {
|
2017-12-06 18:36:28 +00:00
|
|
|
countdown.dec();
|
2010-08-21 23:34:38 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|