-
Notifications
You must be signed in to change notification settings - Fork 577
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow collect_body/3 to be called just once #43
Comments
collect_body
to be called just once
@josevalim I'll look into that. Also, we need to s the non-deprecated functions from https://github.com/extend/cowboy/blob/0.10.0/src/cowboy_req.erl#L99 I'll work on updating this as well. |
@scrogson When you are adding support for cowboy 0.10.0 can you make the timeout configurable when collecting the body? Timeouts were added to the new functions for reading the body in cowboy. We really need that feature in hex :) |
After discussing with @josevalim in chat, we've decided to rename this to def read_body(conn, opts \\ []), do: ... end @ericmj the method will just delegate to Cowboy allows: length, read_length, read_timeout, transfer_decode (fn), and content_decode (fn) as options. I'm currently working through a test failure and should have this in a PR in the next couple of days. |
Should we just pass the options through directly instead of making them part of the adapter interface? |
@ericmj not sure I understand what you mean. I'm passing the options directly into the adapter. As I understand it, we are reading the def read_body(%Conn{adapter: {adapter, state}} = conn, opts \\ []) do
case adapter.read_req_body(state, opts) do
{:ok, data, state} ->
{:ok, data, %{conn | adapter: {adapter, state}}}
{:more, data, state} ->
{:more, data, %{conn | adapter: {adapter, state}}}
end
end |
@scrogson Plug is supposed to be generic for any adapter. Today we only have cowboy so the issue won't come up. But what if we add another webserver adapter that instead of |
Yeah, I was talking to @scrogson and we have decided exactly that. We are going to use the same names as cowboy, but all supported options should be explicitly documented. We should never say "accepts the same options as cowboy". |
@josevalim @scrogson Awesome! 👍 |
I've sent a PR for this work in #44 @josevalim and I have discussed that returning |
Today if you call
collect_body
multiple times, you will get the body the first time and an empty body in the following ones. It would be nice ifcollect_body/3
instead returned{:error, :already_collected, conn}
instead. In order for this to work, we will probably need to store this data or in the connect or in the adapter.In the adapter is preferable although I am not sure if possible. Does cowboy gives us this information in the new API?
@scrogson, could you please take a look at this? :D After we get this in, we can release v0.5.0 with
collect_body/3
.The text was updated successfully, but these errors were encountered: