decompress-request
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.1 • Public • Published

    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

    Install

    npm i decompress-request

    DownloadsWeekly Downloads

    21

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    4.57 kB

    Total Files

    5

    Last publish

    Collaborators

    • avatar