{"name":"http-headers","version":"3.0.1","description":"Parse http headers","main":"index.js","scripts":{"test":"standard && tape test.js"},"repository":{"type":"git","url":"git://github.com/watson/http-headers.git"},"dependencies":{"next-line":"^1.0.0"},"devDependencies":{"standard":"^5.1.1","tape":"^4.2.0"},"keywords":["http","https","header","headers","parse","parsing","ServerResponse","response"],"author":{"name":"Thomas Watson Steen","email":"w@tson.dk","url":"https://twitter.com/wa7son"},"license":"MIT","bugs":{"url":"https://github.com/watson/http-headers/issues"},"homepage":"https://github.com/watson/http-headers","coordinates":[55.687709,12.5955128],"gitHead":"04621dcc39ea153238f498d8bac59531b34f3e96","_id":"http-headers@3.0.1","_shasum":"1cbc691c45cdf6d6c1dc63bf368b2505f56ef839","_from":".","_npmVersion":"2.14.7","_nodeVersion":"4.2.2","_npmUser":{"name":"watson","email":"w@tson.dk"},"maintainers":[{"name":"watson","email":"w@tson.dk"}],"dist":{"shasum":"1cbc691c45cdf6d6c1dc63bf368b2505f56ef839","tarball":"http://registry-npm.ywwl.com/http-headers/download/http-headers-3.0.1.tgz","integrity":"sha512-id3sVqn5P6pE5UEwVy5G886UaeOGkDfg7V7ajF0H+C8eybnUBMyvkFe77NUSs8P7R9ntgKBqR8/iYJzjCQ5MGw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIATUnXfq2mqvlytKrwvUMEPjDNTKgCAFV5Ja5q5Lsn7xAiEAn3sdjB/9ZlHwGMjZw0QX0jswx5YauaW5fxBExfdOJgA="}],"size":4872,"noattachment":false,"key":"/http-headers/-/http-headers-3.0.1.tgz"},"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/http-headers-3.0.1.tgz_1461655241531_0.09670431981794536"},"directories":{},"readme":"# http-headers\n\n[![Build status](https://travis-ci.org/watson/http-headers.svg?branch=master)](https://travis-ci.org/watson/http-headers)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard)\n\nParse the start-line and headers from an HTTP request or reponse.\n\nConverts:\n\n```http\nHTTP/1.1 200 OK\nDate: Tue, 10 Jun 2014 07:19:27 GMT\nConnection: keep-alive\nTransfer-Encoding: chunked\n\nHello World\n```\n\nTo this:\n\n```js\n{\n  version: { major: 1, minor: 1 },\n  statusCode: 200,\n  statusMessage: 'OK',\n  headers: {\n    date: 'Tue, 10 Jun 2014 07:19:27 GMT',\n    connection: 'keep-alive',\n    'transfer-encoding': 'chunked'\n  }\n}\n```\n\n**Features:**\n\n- Auto-detects and ignores body if present\n- Fully [RFC 2068](http://www.rfc-base.org/txt/rfc-2068.txt) compliant\n  (please [open an issue](https://github.com/watson/http-headers/issues)\n  if you find a discrepancy)\n- Support multi-line headers (lines will be joined with a space)\n- Support repeating headers\n\n## Installation\n\n```\nnpm install http-headers --save\n```\n\n## Usage\n\n```js\nvar net = require('net')\nvar httpHeaders = require('http-headers')\n\n// create TCP server\nnet.createServer(function (c) {\n  var buffers = []\n  c.on('data', buffers.push.bind(buffers))\n  c.on('end', function () {\n    var data = Buffer.concat(buffers)\n\n    // parse incoming data as an HTTP request and extra HTTP headers\n    console.log(httpHeaders(data))\n  })\n}).listen(8080)\n```\n\n### `http.ServerReponse` support\n\nIf given an instance of `http.ServerResponse`, the reponse headers is\nautomatically extracted, parsed and returned:\n\n```js\nvar http = require('http')\nvar httpHeaders = require('http-headers')\n\nhttp.createServer(function (req, res) {\n  res.end('Hello World')\n  console.log(httpHeaders(res))\n}).listen(8080)\n```\n\n#### Why?\n\nIf you've ever needed to log or in another way access the headers sent\nto the client on a `http.ServerResponse` in Node.js, you know it's not\nas easy as with the `http.IncomingMessage` headers (which you just\naccess via `request.headers['content-type']`).\n\nResponse headers are not directly available on the `response` object.\nInstead all headers are preprocessed as a string on the private\n`response._header` property and needs to be processed in order to be\navailable as an object.\n\nThis module makes the task super simple.\n\n## API\n\nThe http-headers module exposes a single parser function:\n\n```js\nhttpHeaders(data[, onlyHeaders])\n```\n\nArguments:\n\n- `data` - A string, buffer or instance of `http.ServerReponse`\n- `onlyHeaders` - An optional boolean. If `true`, only the headers\n  object will be returned. Defaults to `false`\n\n### Request example\n\nIf given a request as input:\n\n```http\nGET /foo HTTP/1.1\nDate: Tue, 10 Jun 2014 07:19:27 GMT\nConnection: keep-alive\nTransfer-Encoding: chunked\n\nHello World\n```\n\nReturns:\n\n```js\n{\n  method: 'GET',\n  url: '/foo',\n  version: { major: 1, minor: 1 },\n  headers: {\n    date: 'Tue, 10 Jun 2014 07:19:27 GMT',\n    connection: 'keep-alive',\n    'transfer-encoding': 'chunked'\n  }\n}\n```\n\n### Response example\n\nIf given a request as input:\n\n```http\nHTTP/1.1 200 OK\nDate: Tue, 10 Jun 2014 07:19:27 GMT\nConnection: keep-alive\nTransfer-Encoding: chunked\n\nHello World\n```\n\nReturns:\n\n```js\n{\n  version: { major: 1, minor: 1 },\n  statusCode: 200,\n  statusMessage: 'OK',\n  headers: {\n    date: 'Tue, 10 Jun 2014 07:19:27 GMT',\n    connection: 'keep-alive',\n    'transfer-encoding': 'chunked'\n  }\n}\n```\n\n### `onlyHeaders` example\n\nIf the optional second argument is set to `true`, only headers are\nreturned no matter the type of input:\n\n```js\n{\n  date: 'Tue, 10 Jun 2014 07:19:27 GMT',\n  connection: 'keep-alive',\n  'transfer-encoding': 'chunked'\n}\n```\n\n### No Start-Line\n\nIf the `data` given does not contain an HTTP Start-Line, only the\nheaders are returned, even if the `onlyHeaders` argument is `false`:\n\n```http\nDate: Tue, 10 Jun 2014 07:19:27 GMT\nConnection: keep-alive\nTransfer-Encoding: chunked\n\nHello World\n```\n\nReturns:\n\n```js\n{\n  date: 'Tue, 10 Jun 2014 07:19:27 GMT',\n  connection: 'keep-alive',\n  'transfer-encoding': 'chunked'\n}\n```\n\n## License\n\nMIT\n","publish_time":1461655243492,"_cnpm_publish_time":1461655243492,"dist-tags":{"latest":"3.0.2"}}