0.0.0 • Published 3 years ago

get-response-headers v0.0.0

Weekly downloads
-
License
CC0-1.0
Repository
github
Last release
3 years ago

get-response-headers

Get the Response Headers for a URL

Features

  • Avoids downloading the whole file
  • Works with HTTP and HTTPS
  • Zero Dependencies
  • Follows 301 Redirects
  • Works even when HEAD requests are blocked (because it uses GET)
  • Normalizes Response Headers (as camel-cased keys)

Limitations

  • Only works in NodeJS

Install

npm install get-response-headers

Usage

const { getResponseHeaders } = require('get-response-headers');

const url = "https://s3-us-west-2.amazonaws.com/planet-disaster-data/hurricane-harvey/SkySat_Freeport_s03_20170831T162740Z3.tif";
const { headers } = await getResponseHeaders({ url });
/*
headers is {
  acceptRanges: 'bytes',
  connection: 'close',
  contentLength: '722512509',
  contentType: 'image/tiff',
  date: 'Wed, 03 Mar 2021 05:53:28 GMT',
  ...
}
*/

Advanced Usage

Modifying High Water Mark

The High Water Mark is how many bytes to read before returning the result. The default is 1024.

const { headers } = await getResponseHeaders({ highWaterMark: 512, url });