2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2016-05-29 03:06:56 -04:00
|
|
|
require('../common');
|
2010-12-06 01:33:52 +03:00
|
|
|
var assert = require('assert');
|
2010-12-04 15:20:34 -08:00
|
|
|
var http = require('http');
|
2010-08-21 16:34:38 -07:00
|
|
|
|
2010-12-04 15:20:34 -08:00
|
|
|
var nresponses = 0;
|
2010-08-21 16:34:38 -07:00
|
|
|
|
|
|
|
var server = http.createServer(function(req, res) {
|
|
|
|
if (req.url == '/one') {
|
2010-12-06 01:33:52 +03:00
|
|
|
res.writeHead(200, [['set-cookie', 'A'],
|
|
|
|
['content-type', 'text/plain']]);
|
|
|
|
res.end('one\n');
|
2010-08-21 16:34:38 -07:00
|
|
|
} else {
|
2010-12-06 01:33:52 +03:00
|
|
|
res.writeHead(200, [['set-cookie', 'A'],
|
|
|
|
['set-cookie', 'B'],
|
|
|
|
['content-type', 'text/plain']]);
|
|
|
|
res.end('two\n');
|
2010-08-21 16:34:38 -07:00
|
|
|
}
|
|
|
|
});
|
2016-05-29 03:06:56 -04:00
|
|
|
server.listen(0);
|
2010-08-21 16:34:38 -07:00
|
|
|
|
2011-10-15 01:08:36 +02:00
|
|
|
server.on('listening', function() {
|
2010-08-21 16:34:38 -07:00
|
|
|
//
|
|
|
|
// one set-cookie header
|
|
|
|
//
|
2016-05-29 03:06:56 -04:00
|
|
|
http.get({ port: this.address().port, path: '/one' }, function(res) {
|
2010-08-21 16:34:38 -07:00
|
|
|
// set-cookie headers are always return in an array.
|
|
|
|
// even if there is only one.
|
2016-04-19 15:37:45 -07:00
|
|
|
assert.deepStrictEqual(['A'], res.headers['set-cookie']);
|
2010-08-21 16:34:38 -07:00
|
|
|
assert.equal('text/plain', res.headers['content-type']);
|
|
|
|
|
2011-10-15 01:08:36 +02:00
|
|
|
res.on('data', function(chunk) {
|
2010-08-21 16:34:38 -07:00
|
|
|
console.log(chunk.toString());
|
|
|
|
});
|
|
|
|
|
2011-10-15 01:08:36 +02:00
|
|
|
res.on('end', function() {
|
2010-08-21 16:34:38 -07:00
|
|
|
if (++nresponses == 2) {
|
|
|
|
server.close();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// two set-cookie headers
|
|
|
|
|
2016-05-29 03:06:56 -04:00
|
|
|
http.get({ port: this.address().port, path: '/two' }, function(res) {
|
2016-04-19 15:37:45 -07:00
|
|
|
assert.deepStrictEqual(['A', 'B'], res.headers['set-cookie']);
|
2010-08-21 16:34:38 -07:00
|
|
|
assert.equal('text/plain', res.headers['content-type']);
|
|
|
|
|
2011-10-15 01:08:36 +02:00
|
|
|
res.on('data', function(chunk) {
|
2010-08-21 16:34:38 -07:00
|
|
|
console.log(chunk.toString());
|
|
|
|
});
|
|
|
|
|
2011-10-15 01:08:36 +02:00
|
|
|
res.on('end', function() {
|
2010-08-21 16:34:38 -07:00
|
|
|
if (++nresponses == 2) {
|
|
|
|
server.close();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2011-10-15 01:08:36 +02:00
|
|
|
process.on('exit', function() {
|
2010-08-21 16:34:38 -07:00
|
|
|
assert.equal(2, nresponses);
|
|
|
|
});
|