diff --git a/docs/api/response.md b/docs/api/response.md index 86458f6..2283aa0 100644 --- a/docs/api/response.md +++ b/docs/api/response.md @@ -243,12 +243,6 @@ this.response.lastModified = new Date(); this.response.etag = crypto.createHash('md5').update(this.body).digest('hex'); ``` -### res.append(field, val) - - Append `val` to header `field`. - ### res.vary(field) Vary on `field`. - - diff --git a/lib/response.js b/lib/response.js index 892f430..93b3ec3 100644 --- a/lib/response.js +++ b/lib/response.js @@ -12,6 +12,7 @@ var status = require('statuses'); var destroy = require('dethroy'); var http = require('http'); var path = require('path'); +var vary = require('vary'); var basename = path.basename; var extname = path.extname; @@ -201,7 +202,7 @@ module.exports = { */ vary: function(field){ - this.append('Vary', field); + vary(this.res, field); }, /** @@ -393,28 +394,6 @@ module.exports = { this.res.removeHeader(field); }, - /** - * Append `val` to header `field`. - * - * @param {String} field - * @param {String} val - * @api public - */ - - append: function(field, val){ - field = field.toLowerCase(); - var header = this.header; - var list = header[field]; - - // not set - if (!list) return this.set(field, val); - - // append - list = list.split(/ *, */); - if (!~list.indexOf(val)) list.push(val); - this.set(field, list.join(', ')); - }, - /** * Checks if the request is writable. * Tests for the existence of the socket diff --git a/package.json b/package.json index d30399e..2c9e6a2 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "delegates": "0.0.3", "dethroy": "~1.0.0", "error-inject": "~1.0.0", + "vary": "~0.1.0", "only": "0.0.2" }, "devDependencies": { diff --git a/test/context.js b/test/context.js index bf2e6ce..176b6f1 100644 --- a/test/context.js +++ b/test/context.js @@ -8,6 +8,7 @@ var koa = require('..'); exports = module.exports = function(req, res){ req = req || { headers: {}, socket: new ReadableStream() }; res = res || { _headers: {} }; + res.getHeader = function(k){ return res._headers[k.toLowerCase()] }; res.setHeader = function(k, v){ res._headers[k.toLowerCase()] = v }; res.removeHeader = function(k, v){ delete res._headers[k.toLowerCase()] }; return koa().createContext(req, res);