# consume-http-header

> Consume an HTTP request or response stream until all headers have been read

Latest version **1.0.0** (published 2016-04-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install consume-http-header
pnpm add consume-http-header
yarn add consume-http-header
bun add consume-http-header
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2016-04-28 |
| First published | 2016-04-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Thomas Watson Steen |
| Maintainers | watson |
| Keywords | http, header, headers, stream, socket, tcp, parse, parser |

## Links

- npm: https://www.npmjs.com/package/consume-http-header
- Repository: https://github.com/watson/consume-http-header
- Homepage: https://github.com/watson/consume-http-header#readme
- Issues: https://github.com/watson/consume-http-header/issues
- npm.io page: https://npm.io/package/consume-http-header

## Dependencies (2)

- [http-headers](https://npm.io/package/http-headers.md) ^3.0.1
- [consume-until](https://npm.io/package/consume-until.md) ^1.0.0

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2016-04-28

## README

# consume-http-header

Consume an HTTP request or response stream until all headers have been
read.

Leaves the stream ready to be consumed from the start of the HTTP body.

[![Build status](https://travis-ci.org/watson/consume-http-header.svg?branch=master)](https://travis-ci.org/watson/consume-http-header)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard)

## Installation

```
npm install consume-http-header --save
```

## Usage

```js
var net = require('net')
var consume = require('consume-http-header')

var socket = net.connect({ host: 'example.com', port: 80 })

socket.write('GET / HTTP/1.1\r\n')
socket.write('Host: example.com\r\n')
socket.write('\r\n')

consume(socket, function (err, req) {
  if (err) throw err

  console.log('New HTTP response:', req.method, req.url)

  console.log('Headers:')
  consooe.log(req.headers)

  console.log('Body:')
  socket.pipe(process.stdout)
})
```

## API

### `consume(stream, callback)`

The module exposes a single function which takes 3 arguments:

- `stream` - The stream to consume
- `callback` - The callback will be called when a complete set of HTTP
  headers have been read from the `stream`. The headers will be given as
  the second argument. An error is given as the first argument if the
  `stream` either ends before all the headers have been read or if the
  `stream` emits an error

#### Consuming the HTTP body

When the `callback` is called, continue consuming the `stream` to get
the body of the request. But be aware of the following gotchas:

- If the `stream` is reused for multiple requests and responses, be
  aware of when the body ends
- If `req.headers['transfer-encoding'] === 'chunked'`, be aware that the
  body is using Chunked Transfer Coding and you have to decode it
  accordingly. Decoding Chunked Transfer Coding is outside the scope of
  this module

## License

MIT

---
_Source: https://npm.io/package/consume-http-header · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
