Split request data from request and add a split method to context to make re-using context easier
Closed this issue · 3 comments
Handlers are currently of the form: (Context) -> _
This is logically equivalent to: (State, Request, Data) -> _
When reading request data, we consume the entire context.
I'd like to see the following be possible:
let (state, request, data) = context.split();
- Rename
Context::body
toContext::data
- Add
shio::Data
(replacingshio::request::Body
) - Extract
shio::State
out ofshio::Context
- Add
Context::split
Context::deconstruct
Perhaps split
or Data
are the wrong words here. Suggestions welcome.
I think we shouldn't rename Context::body
to Context::data
, because we talk about the body of the request.
Also, I think Context::split
should be
let (handle, state, request, body) = context.split();
Note the handle. Futhermore, the body is already into request, so we need to have a Request::split()
that split the body from the remaining (http version, uri, method & headers).
If we have to name this, I propose to follow hyper here, and use Context::deconstruct()
instead of Context::split()
.
I think we shouldn't rename Context::body to Context::data, because we talk about the body of the request.
The argument still works the other way: "request data" vs "request body". The former arguably being more clear to newcomers. As Data
is a universal term to mean, well, data. On the other hand, Body
, is a HTTP specific term that then needs further explanation.
Also, I think Context::split should be [...]
Good catch. I did forget about the poor handle.
Futhermore, the body is already into request [...]
It's in the Request object currently. An example from an existing web framework, Rocket currently separates a Request
from its Data
.
If we have to name this, I propose to follow hyper here, and use Context::deconstruct() instead of Context::split().
Note that deconstruct
is part of Hyper 0.11. Hyper 0.12 will be using http
and will have into_parts
.
My current thoughts are:
shio::Request
should be a wrapper aroundhttp::request::Parts
shio::Data
should be afutures::Stream
that will wraphyper::Body
shio::Context
should have adeconstruct
method that returns:(handle, state, request, data)
.into_parts
seems specifically named forhttp
's naming.
For naming "data" vs "body", you're right. I haven't a preference.
The rest is OK for me.