2015-01-25 17:53:55 +00:00
|
|
|
|
2015-10-11 22:59:51 +00:00
|
|
|
'use strict';
|
|
|
|
|
2017-05-11 03:30:32 +00:00
|
|
|
const assert = require('assert');
|
2015-10-12 04:59:30 +00:00
|
|
|
const context = require('../helpers/context');
|
2015-01-25 17:53:55 +00:00
|
|
|
|
2015-10-25 07:54:57 +00:00
|
|
|
describe('ctx.append(name, val)', () => {
|
|
|
|
it('should append multiple headers', () => {
|
2015-10-05 18:23:47 +00:00
|
|
|
const ctx = context();
|
2015-01-25 17:53:55 +00:00
|
|
|
ctx.append('x-foo', 'bar1');
|
|
|
|
ctx.append('x-foo', 'bar2');
|
2017-05-11 03:30:32 +00:00
|
|
|
assert.deepEqual(ctx.response.header['x-foo'], ['bar1', 'bar2']);
|
2015-10-12 20:36:41 +00:00
|
|
|
});
|
2015-01-25 17:53:55 +00:00
|
|
|
|
2015-10-25 07:54:57 +00:00
|
|
|
it('should accept array of values', () => {
|
2015-10-05 18:23:47 +00:00
|
|
|
const ctx = context();
|
2015-01-25 17:53:55 +00:00
|
|
|
|
|
|
|
ctx.append('Set-Cookie', ['foo=bar', 'fizz=buzz']);
|
2015-03-29 03:25:28 +00:00
|
|
|
ctx.append('Set-Cookie', 'hi=again');
|
2017-05-11 03:30:32 +00:00
|
|
|
assert.deepEqual(ctx.response.header['set-cookie'], ['foo=bar', 'fizz=buzz', 'hi=again']);
|
2015-10-12 20:36:41 +00:00
|
|
|
});
|
2015-01-25 17:53:55 +00:00
|
|
|
|
2015-10-25 07:54:57 +00:00
|
|
|
it('should get reset by res.set(field, val)', () => {
|
2015-10-05 18:23:47 +00:00
|
|
|
const ctx = context();
|
2015-01-25 17:53:55 +00:00
|
|
|
|
|
|
|
ctx.append('Link', '<http://localhost/>');
|
|
|
|
ctx.append('Link', '<http://localhost:80/>');
|
|
|
|
|
|
|
|
ctx.set('Link', '<http://127.0.0.1/>');
|
|
|
|
|
2017-05-11 03:30:32 +00:00
|
|
|
assert.equal(ctx.response.header.link, '<http://127.0.0.1/>');
|
2015-10-12 20:36:41 +00:00
|
|
|
});
|
2015-01-25 17:53:55 +00:00
|
|
|
|
2015-10-25 07:54:57 +00:00
|
|
|
it('should work with res.set(field, val) first', () => {
|
2015-10-05 18:23:47 +00:00
|
|
|
const ctx = context();
|
2015-01-25 17:53:55 +00:00
|
|
|
|
|
|
|
ctx.set('Link', '<http://localhost/>');
|
|
|
|
ctx.append('Link', '<http://localhost:80/>');
|
|
|
|
|
2017-05-11 03:30:32 +00:00
|
|
|
assert.deepEqual(ctx.response.header.link, ['<http://localhost/>', '<http://localhost:80/>']);
|
2015-10-12 20:36:41 +00:00
|
|
|
});
|
|
|
|
});
|