CoolFace
Apppublic

opusdev/vector-similarity-api

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes
README.md102 linesDownload Raw Back to vary
1# vary2 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 header10 11## Installation12 13This is a [Node.js](https://nodejs.org/en/) module available through the14[npm registry](https://www.npmjs.com/). Installation is done using the15[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally): 16 17```sh18$ npm install vary19```20 21## API22 23<!-- eslint-disable no-unused-vars -->24 25```js26var vary = require('vary')27```28 29### vary(res, field)30 31Adds the given header `field` to the `Vary` response header of `res`.32This can be a string of a single field, a string of a valid `Vary`33header, or an array of multiple fields.34 35This will append the header if not already listed, otherwise leaves36it listed in the current location.37 38<!-- eslint-disable no-undef -->39 40```js41// Append "Origin" to the Vary header of the response42vary(res, 'Origin')43```44 45### vary.append(header, field)46 47Adds the given header `field` to the `Vary` response header string `header`.48This can be a string of a single field, a string of a valid `Vary` header,49or an array of multiple fields.50 51This will append the header if not already listed, otherwise leaves52it listed in the current location. The new header string is returned.53 54<!-- eslint-disable no-undef -->55 56```js57// Get header string appending "Origin" to "Accept, User-Agent"58vary.append('Accept, User-Agent', 'Origin')59```60 61## Examples62 63### Updating the Vary header when content is based on it64 65```js66var http = require('http')67var vary = require('vary')68 69http.createServer(function onRequest (req, res) {70  // about to user-agent sniff71  vary(res, 'User-Agent')72 73  var ua = req.headers['user-agent'] || ''74  var isMobile = /mobi|android|touch|mini/i.test(ua)75 76  // serve site, depending on isMobile77  res.setHeader('Content-Type', 'text/html')78  res.end('You are (probably) ' + (isMobile ? '' : 'not ') + 'a mobile user')79})80```81 82## Testing83 84```sh85$ npm test86```87 88## License89 90[MIT](LICENSE)91 92[npm-image]: https://img.shields.io/npm/v/vary.svg93[npm-url]: https://npmjs.org/package/vary94[node-version-image]: https://img.shields.io/node/v/vary.svg95[node-version-url]: https://nodejs.org/en/download96[travis-image]: https://img.shields.io/travis/jshttp/vary/master.svg97[travis-url]: https://travis-ci.org/jshttp/vary98[coveralls-image]: https://img.shields.io/coveralls/jshttp/vary/master.svg99[coveralls-url]: https://coveralls.io/r/jshttp/vary100[downloads-image]: https://img.shields.io/npm/dm/vary.svg101[downloads-url]: https://npmjs.org/package/vary102