Skip to content

Prompt responses#207

Merged
bradfier merged 7 commits into
tiny-http:masterfrom
JRoush:prompt-responses
Jun 30, 2021
Merged

Prompt responses#207
bradfier merged 7 commits into
tiny-http:masterfrom
JRoush:prompt-responses

Conversation

@JRoush

@JRoush JRoush commented Jun 22, 2021

Copy link
Copy Markdown
Contributor

Allows the server to send responses immediately, without waiting for the full request body to arrive.

The trade-off is that the server author must explicitly read the full request body before responding if they want the next request in the pipeline to start parsing concurrently while the response is being sent.

This is intended to resolve issue #206.

@bradfier

Copy link
Copy Markdown
Member

Thanks for putting this together @JRoush, I hope you'll forgive me if I take some time to make sure it gets a thorough review.

Can I ask for a couple of annoying procedural tweaks first of all, while I actually review the code?

  1. Could you run cargo fmt and then rebase the PR, I don't mind if this is just a Run cargo fmt commit on the end, or if you prefer to be neat and want to meld the formatting changes back into the commits that introduce them.
  2. Your commits have broken Git authorship (From: jroush <@>), it would be good for this to be accurate so we can correctly credit you with them.

JRoush added 5 commits June 28, 2021 17:54
These test the desired behavior of the library;
they do not all currently pass.
On reflection, this its not really possible for this test to pass.
The server can't (or rather, shouldn't) read the request body until it
has sent a `100 continue` response.  But it cant send a continue
response until it has finished sending the _full_ response to the
previous request in the pipeline, because responses have to be sent in
the correct order.  This forced interleaving of reads and writes prevents
prompt request handling.
The server must parse all pipelined requests (sent over a single connection)
sequentially.  Dropping the internal reader when it has reached the end
of the request signals that the next request can begin parsing.
This can happen concurrently while a response to the first request is
being sent.

Dropping a request reader _before_ it has been fully read will still
consume the rest of the request, blocking if necessary until all of the
data arrives.  This ensures that the body of a request is always read
eventually, unless the connection is closed by the client.

However, request readers are no longer forcibly dropped before sending
a response (they are instead dropped _after_ sending a response).
This reverts 091ce80.  Responses can now be sent without reading the
full request body, which is very useful for e.g. "413 Payload too large"
errors.  Server authors should be advised to fully read the request body themselves before sending lengthy responses.
@JRoush JRoush force-pushed the prompt-responses branch from fe84095 to 55bb5d1 Compare June 28, 2021 21:56

@bradfier bradfier left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me barring the one line in the test suite that breaks under our MSRV. Can we swap that out for a clunkier alternative and I'll get this merged?

Comment thread tests/promptness.rs Outdated
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
sleep(Duration::from_millis(100));
let l = self.len.min(buf.len()).min(1000);
buf[..l].fill(self.val);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate this is just inside test code but it breaks under 1.41.1 because .fill() wasn't yet implemented for [u8].

https://github.com/tiny-http/tiny-http/pull/207/checks?check_run_id=2940126934

@JRoush

JRoush commented Jun 29, 2021

Copy link
Copy Markdown
Contributor Author

OK, hopefully the CI tests will pass now. Thanks for your patience @bradfier. I haven't used github workflows before and it took a while to figure out how to run them on my fork.

@bradfier

Copy link
Copy Markdown
Member

OK, hopefully the CI tests will pass now. Thanks for your patience @bradfier. I haven't used github workflows before and it took a while to figure out how to run them on my fork.

Thanks! It looks good now, however it appears Travis CI have finally thrown open source under the bus like they said they would, and stopped travis-ci.org builds from running at all.

I've asked Tomaka and Frewsxcv to remove the Travis CI gate from the project via EMail as they probably have notifications from this repo turned off.

@bradfier bradfier merged commit 1ca75c3 into tiny-http:master Jun 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants