Repository navigation
Description
Use of the 100 (Continue) Status (https://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html#sec8.2.3):
The purpose of the 100 (Continue) status (see section 10.1.1) is to allow a client that is sending a request message with a request body to determine if the origin server is willing to accept the request (based on the request headers) before the client sends the request body. In some cases, it might either be inappropriate or highly inefficient for the client to send the body if the server will reject the message without looking at the body.
In my case, for example, I can upload file or reject already uploaded file in one atomic request.
Current state:
- 0.9.x - handler can make desigion and allow/reject client request by additional
check_continuemethod. This method is not supported by https://github.com/iron/iron and https://github.com/nickel-org/nickel.rs. Also this method require duplicate logic (it not called on HTTP/1.0) for routing and check permissions; - master - looks like this feature is forgotten.
I think, much better to send "100 Continue" status on first Body::read() call (similar logic implemented by https://github.com/frewsxcv/tiny-http project).
In this case no additional logic/callback needed for make desigion about "100 Continue":
- If you call Body::read() method, then you needs to request body and hyper send to client "100 Continue";
- If you have anought information to send final status without body, then hyper send status without "100 Continue".
I try to change logic on 0.9.x branch by send "100 Continue" status of first read call, but I failed :(
Activity
seanmonstar commentedon Jun 20, 2016
Not so much forgotten, I just wanted to come up with a better design. What you outline here seems like it should work on master:
bozaro commentedon Jun 21, 2016
Yes, about this behavior and I had in mind.
I'm sorry if offended. Loss (sometimes temporary) features on full code redesign is a normal and I did not mean anything bad. On the contrary, from my point of view this is a very good time to remind about corner cases :)
seanmonstar commentedon Jun 21, 2016
Not offended at all! Thanks for helping think this issue through.
On Mon, Jun 20, 2016, 11:42 PM Artem V. Navrotskiy [email protected]
wrote:
[-]Hyper and "Expect: 100-continue" issue[/-][+]Handle Expect: 100-continue in Server[/+]martell commentedon Jan 29, 2017
Hey all,
I'm looking at implementing this on master with the tokio integration.
I've literally only been using rust a few days so it is hard for me to follow through the code with inferred type assignments and generics mixed together.
Anyway, Here is what I have so far.
The function I added to
http/mod.rsseems correct and withRUST_LOG=traceI getIgnoring the changes I made to
conn.rsjust for testing.@seanmonstar can you give me some direction here?
I can gather that we would be using
Sinkand not aStreamfor this but I am not sure about what would be the best way to go about integrating this into the code base.Where should I be piping the data back etc.
I'm am assuming this is a good time for api breakages.
seanmonstar commentedon Jan 29, 2017
@martell You've only been using Rust a couple days? That makes this work even more impressive! I'd suggest opening a Pull Request with your work, it makes it easier to discuss changes.
As for your current diff, it definitely looks like the right direction. I imagine we would want to add some new states, of which I'm not entirely certain the best combination at the moment. I'll think more, but I can describe the expected behavior.
We would need to save somehow that the request would like a 100-continue response. We would also need a way to know whether we should respond with it, and also to know that we already have. A way we could decide to write
100-continueis if the user decides that they wish to keep reading from the body, we should flush that response. If the user decides they don't want to read from the body, they'll just return aResponse, and we can just write that.In the above example, if the request didn't have a
Content-Lengthheader, the server wants to reject it immediately. In this case, hyper should not have responded with100-continue. We can do this becauseConn::poll()will be called again if the user tries to poll on the request body (thereq.body().for_each).So, we can record that an expectation exists, and then in
Conn::poll(), if were in thisexpectingstate, we can write (and it needs to be flushed immediately) the100-continueresponse (record that we've since written that), and then try to keep reading the body. IfConn::start_send()is called to write a response, we can just remove the expectation state, since it no longer matters.Does this all make sense?
martell commentedon Jan 29, 2017
Thanks for taking the time to look.
Most of that makes sense to me.
I have setup a WIP PR for this
We have to be compliant with the rfc spec to only send the
100-continuewhen we get theContent-Lengthmakes sense to me.Where does the above code go in the code base however?
The use case for this is typically for a REST API server and we only really want to send the body after
Authhas happened based on the header data, probably an oauth2 bearer token etc.So when the user requests the body is an ideal time to send the
100-continueI see the
Conn::poll()inconn.rsI'm just not sure what states yet either but can play around with that to achieve the goal and refactor, from initial reading I see
I think we want a state like
Reading::Headbecause we are beyond the init stage but are not onto reading the body yet.My biggest problem is I can't find where I can write to the
SINK, this is probably a combination of my lack of rust knowledge and the fact that this is not my own code base :)seanmonstar commentedon Jan 31, 2017
I've gone back and forth whether it should be
Reading::ExpectorWriting::Expect. It kind of affects both. Whichever is chosen, we'd want to updateread_bodyto check that we've written the100-continue, andwrite_headwould want to update the state that that there is no need to send a100-continue, since some other response is already being sent.The content is written via
self.io.buffer(bytes)and then flushed withself.io.flush().Handle Expect: 100-continue on the server side
feat(server): Handle 100-continue
feat(server): Handle 100-continue
sfackler commentedon Jun 25, 2017
I have a PR open to implement this: #1232.
feat(server): Handle 100-continue
feat(server): Handle 100-continue
feat(server): Handle 100-continue
feat(server): Handle 100-continue
feat(server): Handle 100-continue
martell commentedon Jun 26, 2017
@sfackler Added support for immediately replying with
100-continueThis is a good short term fix for getting support in tree.
Ideally we would only send this on the attempted read of the body.
Discussions on IRC lead to some work being done in tokio which needed a new future Sink to support this. rust-lang/futures-rs#414
This was then dropped afterwards.
It is still up in the air about how we are going to best solve this.
I wanted to get some context into this thread so we can proceed.
@seanmonstar did mention he might have an idea about how to help this in hyper?
This thread might give the best context on what is needed.
rust-lang/futures-rs#409
seanmonstar commentedon Apr 11, 2018
This should no longer be blocked on any dependencies, on master. We have our own dispatcher, and use a custom channel for the body.
I think it wouldn't be too hard to tie
wantinto the body channel, to know when and if the user has polled for data on the body.[-]Handle Expect: 100-continue in Server[/-][+]Change 100-continue behavior to send when Body has been polled[/+]AlexDvorak commentedon Oct 8, 2018
@seanmonstar was this not fixed by 26417fc?
seanmonstar commentedon Oct 8, 2018
@AlexDvorak no, that's adding the
100 Continueresponse to the write buffer immediately, right after parsing. This issue is describing that it shouldn't add it immediately, but instead only if the user polls theBody. That way, if the user rejects the request for some reason, the client doesn't see a weirdHTTP/1.1 100 Continue\r\n\r\nHTTP/1.1 400 Bad Request.AlexDvorak commentedon Oct 8, 2018
So, would modification to the
Bodystruct like so be fine?Or should the modification be happenning elsewhere?
If that's ok then how would one access the
Bodyfrom theproto/h1/conn.rs?seanmonstar commentedon Oct 8, 2018
That wouldn't work, since the
Connno longer has theBodyside. When there's a request body, a channel is made (Body::channel). The channel implementation could be where this information is stored. Theclient::dispatcheralready has a concept of knowing when the receiver side has been polled, by making use ofwant.AlexDvorak commentedon Oct 8, 2018
what are you reffering to by channel implementation? I assume your're not reffering to
mpsc::channel