Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

consume-http-header

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

consume-http-header

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

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
249
increased by12.67%
Maintainers
1
Weekly downloads
 
Created
Source

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 js-standard-style

Installation

npm install consume-http-header --save

Usage

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

Keywords

FAQs

Package last updated on 28 Apr 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc