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)
})
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'])
License
MIT