3

Mochiweb を調べてみたのですが、ソケット経由でリクエストを受信して​​いるときにボディを読み取る方法が見つかりません。

私は Mochiweb に限定されているわけではありません。他の HTTP ライブラリが適していると思います。

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

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

4

1 に答える 1

3

mochiwebでは、を使用してリクエスト本文のチャンクを折りたたむことができますReq:stream_body/3。2番目の引数としてチャンクハンドラー関数が必要です。このハンドラーは {ChunkSize, BinaryData}、ソケットから受信されるときに、すべてのチャンクの状態とともに呼び出されます。

例([反転]チャンクのリストを取得する):

MaxChunkSize = 100,
InitialState = [],
ChunkHandler = fun ({_Size, Bin}, State) -> [Bin | State] end, 
List = Req:stream_body(MaxChunkSize, ChunkHandler, InitialState),
...
于 2010-11-30T13:30:54.733 に答える