infer-entity-headers

0.0.3 • Public • Published

infer-entity-headers Build Status Dependency Status

Infers http entity headers from path, entity and existing headers.

Functionality

If any of the following headers are not given:

  • content-type header is set to the type returned by guess-content-type.
  • content-length is set to the length of the entity buffer.
  • last-modified is set to the current time.
  • etag is set the MD5 hash of the entity buffer.

Any given headers are left alone. Header names will be transformed to lowercase.

Usage

The exported function takes three arguments: url, entity and headers.

  • url can be an absolute url or just a relative path. Only the path is used.
  • entity is optional. If it's provided, it must be either a Buffer or a String.
  • headers is optional too. It signifies the current headers for the entity. Headers which are already set will be left alone. Since all headers are converted to lowercase, input is not case-sensitive.
var inferHeaders = require("infer-entity-headers")
var headers = inferHeaders("/somefile.txt", "some contents", {})

The returned headers object contains all existing headers plus any inferred headers.

UTF-8 encoding is assumed for:

  • converting entity string to a Buffer object to determine Content-Length, if not given.
  • setting Content-Type header if not is given. If you have anything else than UTF-8 for text-based formats (including html), be sure to set the Content-Type header yourself.

Credits

The initial structure of this module was generated by Jumpstart, using the Jumpstart Black Coffee template.

License

infer-entity-headers is released under the MIT License.
Copyright (c) 2013 Meryn Stol

Dependents (1)

Package Sidebar

Install

npm i infer-entity-headers

Weekly Downloads

3

Version

0.0.3

License

MIT

Last publish

Collaborators

  • meryn