decompress-request
v1.0.1
Published
Decompress an incoming HTTP request if needed.
Downloads
109
Maintainers
Readme
decompress-request
Decompress an incoming HTTP request if needed.
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
- decompress-response - Same as this module but for handling http responses.
- inflation - Same as this module but doesn't handle Brotli.
License
MIT © Travis Fischer