Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bigpipe/trailers
Automatic Trailer headers for your Node.js
https://github.com/bigpipe/trailers
Last synced: 1 day ago
JSON representation
Automatic Trailer headers for your Node.js
- Host: GitHub
- URL: https://github.com/bigpipe/trailers
- Owner: bigpipe
- License: mit
- Created: 2014-01-11T13:23:51.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2016-11-16T20:46:19.000Z (almost 8 years ago)
- Last Synced: 2024-04-24T17:41:22.183Z (7 months ago)
- Language: JavaScript
- Size: 7.81 KB
- Stars: 3
- Watchers: 7
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Trailers
[![Build Status](https://travis-ci.org/bigpipe/trailers.png?branch=master)](https://travis-ci.org/bigpipe/trailers)
HTTP is amazing, it has amazing features that most of us aren't using. One of
these features are trailing headers. These are headers that can be send after
you've already written your initial HTTP headers. The only caveat is that they
only work with `transfer-encoding: chunked`, luckly, this is enabled by default
in Nodejs.## Installation
The module can be downloaded from the npm registry:
```
npm install --save trailers
```The `--save` tells `npm` to automatically add the installed version to your
`package.json`## Usage
When using this module, nothing changes how you and program your Node.js
applications. The only difference is that you can write headers AFTER you've
written the headers of your response. You can still use `res.setHeaders` just
like you would normally do.To run this module simply include it in your application:
```js
require('trailers');
```That's it. Everything is magically fixed.
## The magic
The module overrides the prototypes of the `OutgoingMessage` class in Node.js
which is what you get a `Response` object in a HTTP server. The `setHeader`
method is overridden method to check if the headers are already flushed to the
client and queues the headers in a new `trailers` object when they are already
written. We override the `end` method so we can flush these headers using the
`addTrailers` method.## License
MIT