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