{"id":19019383,"url":"https://github.com/jshttp/on-headers","last_synced_at":"2025-04-08T04:15:13.552Z","repository":{"id":16998905,"uuid":"19762040","full_name":"jshttp/on-headers","owner":"jshttp","description":"Execute a listener when a response is about to write headers.","archived":false,"fork":false,"pushed_at":"2024-05-14T17:13:19.000Z","size":67,"stargazers_count":157,"open_issues_count":3,"forks_count":21,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-03-31T14:37:12.677Z","etag":null,"topics":["event","headers","http","javascript","nodejs"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jshttp.png","metadata":{"files":{"readme":"README.md","changelog":"HISTORY.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-05-14T01:30:01.000Z","updated_at":"2025-03-18T02:12:32.000Z","dependencies_parsed_at":"2024-06-18T12:28:11.004Z","dependency_job_id":"f7f18006-4816-4990-8947-bbe95580ae8a","html_url":"https://github.com/jshttp/on-headers","commit_stats":{"total_commits":182,"total_committers":2,"mean_commits":91.0,"dds":0.005494505494505475,"last_synced_commit":"34ef1bad7f5fff187bce0a635aca91892b220d2f"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jshttp%2Fon-headers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jshttp%2Fon-headers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jshttp%2Fon-headers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jshttp%2Fon-headers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jshttp","download_url":"https://codeload.github.com/jshttp/on-headers/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247194097,"owners_count":20899430,"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":["event","headers","http","javascript","nodejs"],"created_at":"2024-11-08T20:12:14.315Z","updated_at":"2025-04-08T04:15:13.530Z","avatar_url":"https://github.com/jshttp.png","language":"JavaScript","readme":"# on-headers\n\n[![NPM Version][npm-version-image]][npm-url]\n[![NPM Downloads][npm-downloads-image]][npm-url]\n[![Node.js Version][node-image]][node-url]\n[![Build Status][ci-image]][ci-url]\n[![Coverage Status][coveralls-image]][coveralls-url]\n\nExecute a listener when a response is about to write headers.\n\n## Installation\n\nThis is a [Node.js](https://nodejs.org/en/) module available through the\n[npm registry](https://www.npmjs.com/). Installation is done using the\n[`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally):\n\n```sh\n$ npm install on-headers\n```\n\n## API\n\n\u003c!-- eslint-disable no-unused-vars --\u003e\n\n```js\nvar onHeaders = require('on-headers')\n```\n\n### onHeaders(res, listener)\n\nThis will add the listener `listener` to fire when headers are emitted for `res`.\nThe listener is passed the `response` object as it's context (`this`). Headers are\nconsidered to be emitted only once, right before they are sent to the client.\n\nWhen this is called multiple times on the same `res`, the `listener`s are fired\nin the reverse order they were added.\n\n## Examples\n\n```js\nvar http = require('http')\nvar onHeaders = require('on-headers')\n\nhttp\n  .createServer(onRequest)\n  .listen(3000)\n\nfunction addPoweredBy () {\n  // set if not set by end of request\n  if (!this.getHeader('X-Powered-By')) {\n    this.setHeader('X-Powered-By', 'Node.js')\n  }\n}\n\nfunction onRequest (req, res) {\n  onHeaders(res, addPoweredBy)\n\n  res.setHeader('Content-Type', 'text/plain')\n  res.end('hello!')\n}\n```\n\n## Testing\n\n```sh\n$ npm test\n```\n\n## License\n\n[MIT](LICENSE)\n\n[ci-image]: https://badgen.net/github/checks/jshttp/on-headers/master?label=ci\n[ci-url]: https://github.com/jshttp/on-headers/actions/workflows/ci.yml\n[coveralls-image]: https://badgen.net/coveralls/c/github/jshttp/on-headers/master\n[coveralls-url]: https://coveralls.io/r/jshttp/on-headers?branch=master\n[node-image]: https://badgen.net/npm/node/on-headers\n[node-url]: https://nodejs.org/en/download\n[npm-downloads-image]: https://badgen.net/npm/dm/on-headers\n[npm-url]: https://npmjs.org/package/on-headers\n[npm-version-image]: https://badgen.net/npm/v/on-headers\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjshttp%2Fon-headers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjshttp%2Fon-headers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjshttp%2Fon-headers/lists"}