arnaucube
arnaucube/socketioMEANseedPublic Self-hosted repository
socketioMEANseed/server/node_modules/vary/README.md
server/node_modules/vary/README.mdRaw
 1# vary
 2
 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]
 8
 9Manipulate the HTTP Vary header
10
11## Installation
12
13```sh
14$ npm install vary
15```
16
17## API
18
19```js
20var vary = require('vary')
21```
22
23### vary(res, field)
24
25Adds the given header `field` to the `Vary` response header of `res`.
26This can be a string of a single field, a string of a valid `Vary`
27header, or an array of multiple fields.
28
29This will append the header if not already listed, otherwise leaves
30it listed in the current location.
31
32```js
33// Append "Origin" to the Vary header of the response
34vary(res, 'Origin')
35```
36
37### vary.append(header, field)
38
39Adds the given header `field` to the `Vary` response header string `header`.
40This can be a string of a single field, a string of a valid `Vary` header,
41or an array of multiple fields.
42
43This will append the header if not already listed, otherwise leaves
44it listed in the current location. The new header string is returned.
45
46```js
47// Get header string appending "Origin" to "Accept, User-Agent"
48vary.append('Accept, User-Agent', 'Origin')
49```
50
51## Examples
52
53### Updating the Vary header when content is based on it
54
55```js
56var http = require('http')
57var vary = require('vary')
58
59http.createServer(function onRequest(req, res) {
60  // about to user-agent sniff
61  vary(res, 'User-Agent')
62
63  var ua = req.headers['user-agent'] || ''
64  var isMobile = /mobi|android|touch|mini/i.test(ua)
65
66  // serve site, depending on isMobile
67  res.setHeader('Content-Type', 'text/html')
68  res.end('You are (probably) ' + (isMobile ? '' : 'not ') + 'a mobile user')
69})
70```
71
72## Testing
73
74```sh
75$ npm test
76```
77
78## License
79
80[MIT](LICENSE)
81
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