kartikk221 / hyper-express

High performance Node.js webserver with a simple-to-use API powered by uWebsockets.js under the hood.
MIT License
1.73k stars 89 forks source link

Read JSON as raw #235

Closed GnApollo closed 6 months ago

GnApollo commented 7 months ago

Is there a way to read JSON from post request with headers Transfer-Encoding : chunked?

Like from uwebsockets.js

kartikk221 commented 7 months ago

The Request.json() method is an optimized version of the uWebsockets.js implementation.

You can also consume the raw data using Request.on() since Request is a ReadableStream.

GnApollo commented 7 months ago

thanks for the reply. actually with headers Transfer-Encoding : chunked, the Request.json(), Request.text(), Request.buffer() , Request.raw() returns null .

i end up using new Server().uws_instance.post() and then read the json data their.

kartikk221 commented 7 months ago

Ohhh I see what you are talking about now. Yeah, currently hyper-express looks for a content-length to pre-allocate a body Buffer for performance reasons. I didn't know Transfer-Encoding chunked is supported now by uWS, should certainly be a feature worth adding to support in future.

kartikk221 commented 6 months ago

Hey, support for chunked transfer requests has been added in the recent v6.15.2 versison.