Reading the body of an HTTP request in Erlang as it is received

I looked in Mochiweb, but I cannot find a way to read the body while I receive the request through the socket.

I'm not limited to Mochiweb, any other HTTP library would be good for me.

I also tried gen_tcp:listen(Port, [{packet, http}]), so I can read the body / headers while I receive the HTTP request, but I have to handle the responses manually and keep the socket open for more requests, so I prefer not to use this solution.

My intention is to receive a request with large bodies and not wait to get a full body to start reading / processing them.

+3
source share
1 answer

mochiweb Req:stream_body/3. , . {ChunkSize, BinaryData} , .

( [] ):

MaxChunkSize = 100,
InitialState = [],
ChunkHandler = fun ({_Size, Bin}, State) -> [Bin | State] end, 
List = Req:stream_body(MaxChunkSize, ChunkHandler, InitialState),
...
+3

Source: https://habr.com/ru/post/1777644/


All Articles