res.append.js
This file
Path
test/res.append.js
104 lines · 2.6 KiB · JavaScript
Last changed by
Add res.append(field, val) to append headersDouglas Christopher Wilsonbefore adoptionf6f78e5
History of this fileTake it
Add res.append(field, val) to append headersDouglas Christopher Wilsonbefore adoptionf6f78e5
lines 1–104why, one step back12var express = require('..')3var request = require('supertest')4var should = require('should')56describe('res', function () {7 // note about these tests: "Link" and "X-*" are chosen because8 // the common node.js versions white list which _incoming_9 // headers can appear multiple times; there is no such white list10 // for outgoing, though11 describe('.append(field, val)', function () {12 it('should append multiple headers', function (done) {13 var app = express()1415 app.use(function (req, res, next) {16 res.append('Link', '<http://localhost/>')17 next()18 })1920 app.use(function (req, res) {21 res.append('Link', '<http://localhost:80/>')22 res.end()23 })2425 request(app)26 .get('/')27 .expect('Link', '<http://localhost/>, <http://localhost:80/>', done)28 })2930 it('should accept array of values', function (done) {31 var app = express()3233 app.use(function (req, res, next) {34 res.append('Set-Cookie', ['foo=bar', 'fizz=buzz'])35 res.end()36 })3738 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 })4546 it('should get reset by res.set(field, val)', function (done) {47 var app = express()4849 app.use(function (req, res, next) {50 res.append('Link', '<http://localhost/>')51 res.append('Link', '<http://localhost:80/>')52 next()53 })5455 app.use(function (req, res) {56 res.set('Link', '<http://127.0.0.1/>')57 res.end()58 });5960 request(app)61 .get('/')62 .expect('Link', '<http://127.0.0.1/>', done)63 })6465 it('should work with res.set(field, val) first', function (done) {66 var app = express()6768 app.use(function (req, res, next) {69 res.set('Link', '<http://localhost/>')70 next()71 })7273 app.use(function(req, res){74 res.append('Link', '<http://localhost:80/>')75 res.end()76 })7778 request(app)79 .get('/')80 .expect('Link', '<http://localhost/>, <http://localhost:80/>', done)81 })8283 it('should work with cookies', function (done) {84 var app = express()8586 app.use(function (req, res, next) {87 res.cookie('foo', 'bar')88 next()89 })9091 app.use(function (req, res) {92 res.append('Set-Cookie', 'bar=baz')93 res.end()94 })9596 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})