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.
1import { } from 'node:zlib'23.(async () => {4 try {5 // Check if the request body is gzip compressed6 const = ..('content-encoding')7 if ( !== 'gzip') {8 return new ('Request body is not gzip compressed', {9 : 400,10 })11 }1213 // Read the compressed body14 const = await .()1516 // Decompress the body17 const = (new ())1819 // Convert the decompressed body to a string20 const = new ().()21 const = .()2223 // Process the decompressed body as needed24 .(`Received: ${.()}`)2526 return new ('ok', {27 : { 'Content-Type': 'text/plain' },28 })29 } catch () {30 .('Error:', )31 return new ('Error processing request', { : 500 })32 }33})Edge functions have a runtime memory limit of 150MB. Overly large compressed payloads may result in an out-of-memory error.