get-headers
Retrieve all HTTP(s) headers as an object with original casing
Last updated 9 years ago by blakeembrey .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install get-headers 
SYNC missed versions from official npm registry.

Get Headers

NPM version NPM downloads Build status Test coverage

Retrieve all HTTP(s) headers as an object with original casing.

Installation

npm install get-headers --save

Usage

Parse

Parse a headers string. Useful for XMLHttpRequest instances.

import { parse } from 'get-headers'

parse(xhr.getAllResponseHeaders()) //=> {}

HTTP

Parse headers from http responses. Works properly with node >= 0.12 (when the rawHeaders property was released) and falls back to normal headers on lower versions.

import { get } from 'http'
import { http } from 'get-headers'

get('http://example.com', (res) => {
  http(res) //=> { 'Accept-Ranges': 'bytes', 'Cache-Control': 'max-age=604800', 'Content-Type': 'text/html', Date: 'Mon, 17 Aug 2015 19:53:03 GMT', Etag: '"359670651"', Expires: 'Mon, 24 Aug 2015 19:53:03 GMT', 'Last-Modified': 'Fri, 09 Aug 2013 23:54:35 GMT', Server: 'ECS (rhv/818F)', 'X-Cache': 'HIT', 'x-ec-custom-error': '1', 'Content-Length': '1270', Connection: 'close' }
})

Array

Parse an array of headers (E.g. rawHeaders). Every odd must be the header name and evens the header value.

import { array } from 'get-headers'

array(['Content-Type', 'application/json']) //=> { 'Content-Type': 'application/json' }

License

MIT

Current Tags

  • 1.0.5                                ...           latest (9 years ago)

6 Versions

  • 1.0.5                                ...           9 years ago
  • 1.0.4                                ...           10 years ago
  • 1.0.3                                ...           10 years ago
  • 1.0.2                                ...           11 years ago
  • 1.0.1                                ...           11 years ago
  • 1.0.0                                ...           11 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (0)
None
Dev Dependencies (7)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |