Handling Compressed Requests
Handling Gzip compressed requests.
To decompress Gzip bodies, you can use gunzipSync
from the node:zlib
API to decompress and then read the body.
123456789101112131415161718192021222324252627282930313233import { } from 'node:zlib'.(async () => { try { // Check if the request body is gzip compressed const = ..('content-encoding') if ( !== 'gzip') { return new ('Request body is not gzip compressed', { : 400, }) } // Read the compressed body const = await .() // Decompress the body const = (new ()) // Convert the decompressed body to a string const = new ().() const = .() // Process the decompressed body as needed .(`Received: ${.()}`) return new ('ok', { : { 'Content-Type': 'text/plain' }, }) } catch () { .('Error:', ) return new ('Error processing request', { : 500 }) }})
Edge functions have a runtime memory limit of 150MB. Overly large compressed payloads may result in an out-of-memory error.