|
| 1 | + |
| 2 | +var express = require('..') |
| 3 | +var request = require('supertest') |
| 4 | +var should = require('should') |
| 5 | + |
| 6 | +describe('res', function () { |
| 7 | + // note about these tests: "Link" and "X-*" are chosen because |
| 8 | + // the common node.js versions white list which _incoming_ |
| 9 | + // headers can appear multiple times; there is no such white list |
| 10 | + // for outgoing, though |
| 11 | + describe('.append(field, val)', function () { |
| 12 | + it('should append multiple headers', function (done) { |
| 13 | + var app = express() |
| 14 | + |
| 15 | + app.use(function (req, res, next) { |
| 16 | + res.append('Link', '<http://localhost/>') |
| 17 | + next() |
| 18 | + }) |
| 19 | + |
| 20 | + app.use(function (req, res) { |
| 21 | + res.append('Link', '<http://localhost:80/>') |
| 22 | + res.end() |
| 23 | + }) |
| 24 | + |
| 25 | + request(app) |
| 26 | + .get('/') |
| 27 | + .expect('Link', '<http://localhost/>, <http://localhost:80/>', done) |
| 28 | + }) |
| 29 | + |
| 30 | + it('should accept array of values', function (done) { |
| 31 | + var app = express() |
| 32 | + |
| 33 | + app.use(function (req, res, next) { |
| 34 | + res.append('Set-Cookie', ['foo=bar', 'fizz=buzz']) |
| 35 | + res.end() |
| 36 | + }) |
| 37 | + |
| 38 | + request(app) |
| 39 | + .get('/') |
| 40 | + .expect(function (res) { |
| 41 | + should(res.headers['set-cookie']).eql(['foo=bar', 'fizz=buzz']) |
| 42 | + }) |
| 43 | + .expect(200, done) |
| 44 | + }) |
| 45 | + |
| 46 | + it('should get reset by res.set(field, val)', function (done) { |
| 47 | + var app = express() |
| 48 | + |
| 49 | + app.use(function (req, res, next) { |
| 50 | + res.append('Link', '<http://localhost/>') |
| 51 | + res.append('Link', '<http://localhost:80/>') |
| 52 | + next() |
| 53 | + }) |
| 54 | + |
| 55 | + app.use(function (req, res) { |
| 56 | + res.set('Link', '<http://127.0.0.1/>') |
| 57 | + res.end() |
| 58 | + }); |
| 59 | + |
| 60 | + request(app) |
| 61 | + .get('/') |
| 62 | + .expect('Link', '<http://127.0.0.1/>', done) |
| 63 | + }) |
| 64 | + |
| 65 | + it('should work with res.set(field, val) first', function (done) { |
| 66 | + var app = express() |
| 67 | + |
| 68 | + app.use(function (req, res, next) { |
| 69 | + res.set('Link', '<http://localhost/>') |
| 70 | + next() |
| 71 | + }) |
| 72 | + |
| 73 | + app.use(function(req, res){ |
| 74 | + res.append('Link', '<http://localhost:80/>') |
| 75 | + res.end() |
| 76 | + }) |
| 77 | + |
| 78 | + request(app) |
| 79 | + .get('/') |
| 80 | + .expect('Link', '<http://localhost/>, <http://localhost:80/>', done) |
| 81 | + }) |
| 82 | + |
| 83 | + it('should work with cookies', function (done) { |
| 84 | + var app = express() |
| 85 | + |
| 86 | + app.use(function (req, res, next) { |
| 87 | + res.cookie('foo', 'bar') |
| 88 | + next() |
| 89 | + }) |
| 90 | + |
| 91 | + app.use(function (req, res) { |
| 92 | + res.append('Set-Cookie', 'bar=baz') |
| 93 | + res.end() |
| 94 | + }) |
| 95 | + |
| 96 | + request(app) |
| 97 | + .get('/') |
| 98 | + .expect(function (res) { |
| 99 | + should(res.headers['set-cookie']).eql(['foo=bar; Path=/', 'bar=baz']) |
| 100 | + }) |
| 101 | + .expect(200, done) |
| 102 | + }) |
| 103 | + }) |
| 104 | +}) |
0 commit comments