Comments (9)
@josevalim I'll look into that. Also, we need to s the non-deprecated functions from cowboy_req
for reading the body. Currently we are using stream_body/2
which will be removed in 1.0
. The new method for this is cowboy_req:body/2
.
https://github.com/extend/cowboy/blob/0.10.0/src/cowboy_req.erl#L99
I'll work on updating this as well.
from plug.
@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 :)
from plug.
After discussing with @josevalim in chat, we've decided to rename this to read_body/2
. The signature is very simple:
def read_body(conn, opts \\ []), do: ... end
@ericmj the method will just delegate to cowboy_req:body/2
which will give you full control over the options passed.
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.
from plug.
Should we just pass the options through directly instead of making them part of the adapter interface?
from plug.
@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 req_body
from the adapters state.
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
from plug.
@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 :read_timeout
uses :timeout
as the name for the timeout option? We should define and document the options in Plug so that they work for all possible adapters.
from plug.
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".
from plug.
@josevalim @scrogson Awesome! 👍
from plug.
I've sent a PR for this work in #44
@josevalim and I have discussed that returning {:error, :already_collected, conn}
is not really necessary.
from plug.
Related Issues (20)
- Let user know when `Plug.Conn.register_before_chunk/2` sends the last chunk HOT 7
- Request paths with suffixes match dynamic segments without suffixes HOT 1
- Add option to decide what to do on invalid UTF-8 urlencoded params HOT 3
- [Bug/compile] can't compile plug in bigger project, pop-os-22.04 HOT 9
- Plug.Conn.Query - decode_init, each,done unknown HOT 7
- Interest in an extension for Plug.Parsers.MULTIPART for FormData? HOT 2
- Mismatch spec for `Plug.Conn.Query.decode` HOT 1
- Plug.RequestId: put the `request_id` in `:private` or `:assigns`? HOT 1
- 1.15 changes decoding behaviour of `[]` HOT 5
- Request: Support MFA tuple for Plug.Session opts HOT 4
- Plug.Upload's random-tempdir generation is not very random HOT 1
- `strip_spaces` fails on `nil` since 1.15.0 HOT 1
- Plug.Conn.Query has changed the way it decodes parameters from 1.14 to 1.15 without warning HOT 1
- More flexible dynamic routes with `:` parameters HOT 2
- Compatibility issue with plug_crypto 2.0.0 HOT 3
- Error: There isn't enough space to open the popup HOT 1
- Docs inconsistency between Plug moduledoc and Plug.run HOT 1
- Plug.Upload: demonitor previous owner when giving away HOT 1
- Compilation issues on Erlang 26.x HOT 3
- html array items are dropped. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from plug.