express-extractheaders

4.0.1 • Public • Published

express-extractheaders

NPM version Build Status Coverage Status Dependency Status

Express middleware that allows you to specify your HTTP response headers inside the <head> of your HTML as <meta http-equiv="..." content="..."> tags. The primary use case is static HTML, but the middleware works no matter what's actually generating the response body, so it'll also work with template engines, http proxies etc.

Usage

require('express')()
  .use(require('express-extractheaders')(options))
  .use(express.static('/path/to/static/files/'));

Example:

require('express')()
  .use(require('express-extractheaders')())
  .use(function (req, res, next) {
    res.end(
      '<html>' +
        '<head>' +
        '<meta http-equiv="X-Frame-Options" content="SAMEORIGIN">' +
        '</head>' +
        '<body>foo</body>' +
        '</html>'
    );
  })
  .listen(1337);
$ curl --dump-header - localhost:1337
HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: text/html; charset=utf-8
Content-Length: 98
X-Frame-Options: SAMEORIGIN
Date: Sun, 27 Jul 2014 12:16:51 GMT
Connection: keep-alive

<html><head><meta http-equiv="X-Frame-Options" content="SAMEORIGIN"></head><body>foo</body></html>

Installation

npm install express-extractheaders

Options

memoize: Only extract the response headers once per url. You will probably want to use this option in production as there's a performance hit to parsing all the outgoing HTML.

Security considerations

Only use this when you trust the downstream middleware. If you proxy to an untrusted host, it will gain the ability to set response headers on the behalf of your server.

Releases

Changelog

License

express-extractheaders is licensed under a standard 3-clause BSD license -- see the LICENSE file for details.

Package Sidebar

Install

npm i express-extractheaders

Weekly Downloads

185

Version

4.0.1

License

BSD-3-Clause

Unpacked Size

67.5 kB

Total Files

17

Last publish

Collaborators

  • papandreou
  • gustavnikolaj