3 [![NPM Version][npm-image]][npm-url]
4 [![NPM Downloads][downloads-image]][downloads-url]
5 [![Node.js Version][node-version-image]][node-version-url]
6 [![Build Status][travis-image]][travis-url]
7 [![Test Coverage][coveralls-image]][coveralls-url]
9 Manipulate the HTTP Vary header
20 var vary = require('vary')
25 Adds the given header `field` to the `Vary` response header of `res`.
26 This can be a string of a single field, a string of a valid `Vary`
27 header, or an array of multiple fields.
29 This will append the header if not already listed, otherwise leaves
30 it listed in the current location.
33 // Append "Origin" to the Vary header of the response
37 ### vary.append(header, field)
39 Adds the given header `field` to the `Vary` response header string `header`.
40 This can be a string of a single field, a string of a valid `Vary` header,
41 or an array of multiple fields.
43 This will append the header if not already listed, otherwise leaves
44 it listed in the current location. The new header string is returned.
47 // Get header string appending "Origin" to "Accept, User-Agent"
48 vary.append('Accept, User-Agent', 'Origin')
53 ### Updating the Vary header when content is based on it
56 var http = require('http')
57 var vary = require('vary')
59 http.createServer(function onRequest(req, res) {
60 // about to user-agent sniff
61 vary(res, 'User-Agent')
63 var ua = req.headers['user-agent'] || ''
64 var isMobile = /mobi|android|touch|mini/i.test(ua)
66 // serve site, depending on isMobile
67 res.setHeader('Content-Type', 'text/html')
68 res.end('You are (probably) ' + (isMobile ? '' : 'not ') + 'a mobile user')
82 [npm-image]: https://img.shields.io/npm/v/vary.svg
83 [npm-url]: https://npmjs.org/package/vary
84 [node-version-image]: https://img.shields.io/node/v/vary.svg
85 [node-version-url]: http://nodejs.org/download/
86 [travis-image]: https://img.shields.io/travis/jshttp/vary/master.svg
87 [travis-url]: https://travis-ci.org/jshttp/vary
88 [coveralls-image]: https://img.shields.io/coveralls/jshttp/vary/master.svg
89 [coveralls-url]: https://coveralls.io/r/jshttp/vary
90 [downloads-image]: https://img.shields.io/npm/dm/vary.svg
91 [downloads-url]: https://npmjs.org/package/vary