{"id":18317883,"url":"https://github.com/idiocc/vary","last_synced_at":"2025-04-09T13:51:16.834Z","repository":{"id":57113711,"uuid":"182393390","full_name":"idiocc/vary","owner":"idiocc","description":"[fork] Manipulate the HTTP Vary header","archived":false,"fork":false,"pushed_at":"2019-04-20T12:00:33.000Z","size":36,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-03T13:13:29.147Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://idio.cc","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/idiocc.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-04-20T10:43:41.000Z","updated_at":"2019-04-20T12:00:34.000Z","dependencies_parsed_at":"2022-08-22T02:31:12.716Z","dependency_job_id":null,"html_url":"https://github.com/idiocc/vary","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idiocc%2Fvary","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idiocc%2Fvary/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idiocc%2Fvary/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idiocc%2Fvary/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/idiocc","download_url":"https://codeload.github.com/idiocc/vary/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248054218,"owners_count":21039951,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-05T18:07:46.747Z","updated_at":"2025-04-09T13:51:16.811Z","avatar_url":"https://github.com/idiocc.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @goa/vary\n\n[![npm version](https://badge.fury.io/js/%40goa%2Fvary.svg)](https://npmjs.org/package/@goa/vary)\n\n`@goa/vary` is a [fork](https://github.com/jshttp/vary) of Manipulate the HTTP Vary header rewritten in ES6 Modules.\n\n```sh\nyarn add @goa/vary\n```\n\nThe original module has been updated to be used in [`@goa/koa`](https://artdecocode.com/goa/): _Koa_ web server compiled with _Google Closure Compiler_ using [**Depack**](https://artdecocode.com/depack/) into a single file library (0 dependencies).\n\n## Table Of Contents\n\n- [Table Of Contents](#table-of-contents)\n- [API](#api)\n- [`vary(res: http.ServerResponse, field: string|Array\u003cstring\u003e)`](#varyres-httpserverresponsefield-stringarraystring-void)\n- [`append(header: string, field: string|Array\u003cstring\u003e): string`](#appendheader-stringfield-stringarraystring-string)\n- [Copyright](#copyright)\n\n\u003cp align=\"center\"\u003e\u003ca href=\"#table-of-contents\"\u003e\u003cimg src=\".documentary/section-breaks/0.svg?sanitize=true\"\u003e\u003c/a\u003e\u003c/p\u003e\n\n## API\n\nThe package is available by importing its default and named functions:\n\n```js\nimport vary, { append } from '@goa/vary'\n```\n\n\u003cp align=\"center\"\u003e\u003ca href=\"#table-of-contents\"\u003e\u003cimg src=\".documentary/section-breaks/1.svg?sanitize=true\"\u003e\u003c/a\u003e\u003c/p\u003e\n\n## `vary(`\u003cbr/\u003e\u0026nbsp;\u0026nbsp;`res: http.ServerResponse,`\u003cbr/\u003e\u0026nbsp;\u0026nbsp;`field: string|Array\u003cstring\u003e,`\u003cbr/\u003e`): void`\n\nAdds the given header `field` to the _Vary_ response header of `res`. This can be a string of a single field, a string of a valid _Vary_ header, or an array of multiple fields.\n\nThis will append the header if not already listed, otherwise leaves it listed in the current location.\n\n```js\n/* alanode example/ */\nimport vary from '@goa/vary'\nimport aqt from '@rqt/aqt'\nimport { createServer } from 'http'\n\nconst server = createServer((req, res) =\u003e {\n  // about to user-agent sniff\n  vary(res, 'User-Agent')\n\n  var ua = req.headers['user-agent'] || ''\n  var isMobile = /mobi|android|touch|mini/i.test(ua)\n\n  // serve site, depending on isMobile\n  res.setHeader('Content-Type', 'text/html')\n  res.end('You are (probably) ' + (isMobile ? '' : 'not ') + 'a mobile user')\n})\n\nserver.listen(async () =\u003e {\n  const url = `http://localhost:${server.address().port}`\n  const { headers } = await aqt(url)\n  console.log(headers)\n  server.close()\n})\n```\n```js\n{ vary: 'User-Agent',\n  'content-type': 'text/html',\n  date: 'Sat, 20 Apr 2019 11:57:51 GMT',\n  connection: 'close',\n  'content-length': '36' }\n```\n\n\u003cp align=\"center\"\u003e\u003ca href=\"#table-of-contents\"\u003e\u003cimg src=\".documentary/section-breaks/2.svg?sanitize=true\"\u003e\u003c/a\u003e\u003c/p\u003e\n\n## `append(`\u003cbr/\u003e\u0026nbsp;\u0026nbsp;`header: string,`\u003cbr/\u003e\u0026nbsp;\u0026nbsp;`field: string|Array\u003cstring\u003e,`\u003cbr/\u003e`): string`\n\nAdds the given header `field` to the _Vary_ response header string `header`. This can be a string of a single field, a string of a valid _Vary_ header, or an array of multiple fields.\n\nThis will append the header if not already listed, otherwise leaves it listed in the current location. The new header string is returned.\n\n```js\n\nappend('Accept, User-Agent', 'Origin')\n```\n\n```js\nimport { append } from '@goa/vary'\n\n// Get header string appending \"Origin\" to \"Accept, User-Agent\"\nconsole.log(append('Accept, User-Agent', 'Origin'))\nconsole.log(append('Accept-Encoding, Accept', '*'))\nconsole.log(append('Accept-Encoding, Accept, *', 'Origin'))\n```\n```\nAccept, User-Agent, Origin\n*\n*\n```\n\n\u003cp align=\"center\"\u003e\u003ca href=\"#table-of-contents\"\u003e\u003cimg src=\".documentary/section-breaks/3.svg?sanitize=true\"\u003e\u003c/a\u003e\u003c/p\u003e\n\n## Copyright\n\nOriginal Author: [Douglas Wilson](https://github.com/dougwilson)\n\n---\n\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003cth\u003e\n      \u003ca href=\"https://artd.eco\"\u003e\n        \u003cimg src=\"https://raw.githubusercontent.com/wrote/wrote/master/images/artdeco.png\" alt=\"Art Deco\" /\u003e\n      \u003c/a\u003e\n    \u003c/th\u003e\n    \u003cth\u003e© \u003ca href=\"https://artd.eco\"\u003eArt Deco\u003c/a\u003e for \u003ca href=\"https://idio.cc\"\u003eIdio\u003c/a\u003e 2019\u003c/th\u003e\n    \u003cth\u003e\n      \u003ca href=\"https://idio.cc\"\u003e\n        \u003cimg src=\"https://avatars3.githubusercontent.com/u/40834161?s=100\" width=\"100\" alt=\"Idio\" /\u003e\n      \u003c/a\u003e\n    \u003c/th\u003e\n    \u003cth\u003e\n      \u003ca href=\"https://www.technation.sucks\" title=\"Tech Nation Visa\"\u003e\n        \u003cimg src=\"https://raw.githubusercontent.com/artdecoweb/www.technation.sucks/master/anim.gif\"\n          alt=\"Tech Nation Visa\" /\u003e\n      \u003c/a\u003e\n    \u003c/th\u003e\n    \u003cth\u003e\u003ca href=\"https://www.technation.sucks\"\u003eTech Nation Visa Sucks\u003c/a\u003e\u003c/th\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n\u003cp align=\"center\"\u003e\u003ca href=\"#table-of-contents\"\u003e\u003cimg src=\".documentary/section-breaks/-1.svg?sanitize=true\"\u003e\u003c/a\u003e\u003c/p\u003e","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fidiocc%2Fvary","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fidiocc%2Fvary","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fidiocc%2Fvary/lists"}