mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.5 KiB
64 lines
1.5 KiB
14 years ago
|
var common = require('../common');
|
||
14 years ago
|
var assert = require('assert');
|
||
14 years ago
|
var http = require('http');
|
||
15 years ago
|
|
||
14 years ago
|
var nresponses = 0;
|
||
15 years ago
|
|
||
|
var server = http.createServer(function(req, res) {
|
||
|
if (req.url == '/one') {
|
||
14 years ago
|
res.writeHead(200, [['set-cookie', 'A'],
|
||
|
['content-type', 'text/plain']]);
|
||
|
res.end('one\n');
|
||
15 years ago
|
} else {
|
||
14 years ago
|
res.writeHead(200, [['set-cookie', 'A'],
|
||
|
['set-cookie', 'B'],
|
||
|
['content-type', 'text/plain']]);
|
||
|
res.end('two\n');
|
||
15 years ago
|
}
|
||
|
});
|
||
|
server.listen(common.PORT);
|
||
|
|
||
13 years ago
|
server.on('listening', function() {
|
||
15 years ago
|
//
|
||
|
// one set-cookie header
|
||
|
//
|
||
14 years ago
|
http.get({ port: common.PORT, path: '/one' }, function(res) {
|
||
15 years ago
|
// set-cookie headers are always return in an array.
|
||
|
// even if there is only one.
|
||
|
assert.deepEqual(['A'], res.headers['set-cookie']);
|
||
|
assert.equal('text/plain', res.headers['content-type']);
|
||
|
|
||
13 years ago
|
res.on('data', function(chunk) {
|
||
15 years ago
|
console.log(chunk.toString());
|
||
|
});
|
||
|
|
||
13 years ago
|
res.on('end', function() {
|
||
15 years ago
|
if (++nresponses == 2) {
|
||
|
server.close();
|
||
|
}
|
||
|
});
|
||
|
});
|
||
|
|
||
|
// two set-cookie headers
|
||
|
|
||
14 years ago
|
http.get({ port: common.PORT, path: '/two' }, function(res) {
|
||
15 years ago
|
assert.deepEqual(['A', 'B'], res.headers['set-cookie']);
|
||
|
assert.equal('text/plain', res.headers['content-type']);
|
||
|
|
||
13 years ago
|
res.on('data', function(chunk) {
|
||
15 years ago
|
console.log(chunk.toString());
|
||
|
});
|
||
|
|
||
13 years ago
|
res.on('end', function() {
|
||
15 years ago
|
if (++nresponses == 2) {
|
||
|
server.close();
|
||
|
}
|
||
|
});
|
||
|
});
|
||
|
|
||
|
});
|
||
|
|
||
13 years ago
|
process.on('exit', function() {
|
||
15 years ago
|
assert.equal(2, nresponses);
|
||
|
});
|