Plug Parser (Poison) - Handle `Expect: 100-Continue` requests?


I’m currently using Plug to handle POST requests sent by libcurl with a JSON body. Now libcurl breaks POST requests into multiple HTTP requests with the Expect: 100-Continue header after the body exceeds a certain size (right now the body is 3kb, I expect it to continue growing during development of the project). What then happens is that Plug.Parser throws an error from Poison that the input has ended abruptly (Unexpected end of input at position 2047) which is true.

After some initial research I have discovered that Cowboy has supported such HTTP requests since v0.6.1 (I’m using 1.0) and even explicitly disabling such a header in libcurl does not stop it from splitting the request into multiple requests.

So to my question, is there someway in Plug to have the parser wait until Cowboy stitches the requests together before attempting to parse it? Or is there some other way in which I could somehow assemble the requests together then pass it to Poison manually?


There were two issues with my code.

  1. In the NIF I had written for libcurl I was limiting the body to be 2kb :sweat:, so I increased that limit.
  2. I removed the Expect: 100-continue header and added the Transfer-Encoding: chunked header. So that my request is now chunked and Plug properly glues the chunks together for me.

Now my endpoint properly parses the request body.

1 Like

Awesome, thanks for the follow-up! I was a bit flummoxed at your question. ^.^