1.0.1 • Published 4 years ago

decompress-request v1.0.1

Weekly downloads
7
License
MIT
Repository
github
Last release
4 years ago

decompress-request

Decompress an incoming HTTP request if needed.

NPM Build Status JavaScript Style Guide

Decompresses an incoming http request if it's gzipped, deflated or compressed with Brotli, otherwise just passes it through.

Install

npm install --save decompress-request

Usage

const http = require('http')
const raw = require('raw-body')
const decompressRequest = require('decompress-request')

const server = http.createServer(async (req, res) => {
  req = decompressRequest(req)

  // The request stream is now guaranteed to be inflated / decompressed.
  // You can use it as you would in any http handler.

  // rawBody is an uncompressed Buffer containing the raw request body
  const rawBody = await raw(req, opts)

  // body would contain the request body as a JSON object assuming it was application/json
  const body = JSON.parse(rawBody.toString('utf8'))
})

server.listen(3000)

API

decompressRequest

Decompresses an incoming HTTP request body stream if needed.

Type: function (request): IncomingMessage

  • request IncomingMessage

Related

License

MIT © Travis Fischer