Skip to content
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

100 Continue is sent even though Content-Length is not OK #383

Closed
janderholm opened this issue Jan 17, 2020 · 3 comments
Closed

100 Continue is sent even though Content-Length is not OK #383

janderholm opened this issue Jan 17, 2020 · 3 comments
Labels
bug Something isn't working

Comments

@janderholm
Copy link

The following example which is a multipart upload with a maximum length set behaves in a way that I think is incorrect. I use commit a9fb5d6eb00ded502b021672779dd76c777680cd of warp which is recent on master

use warp::multipart::*;
use warp::Filter;

#[tokio::main]
async fn main() {
    let routes = warp::post()
        .and(warp::path("upload"))
        .and(warp::filters::path::full())
        .and(warp::multipart::form().max_length(1024 * 1024 * 10))
        .map(
            |full_path: warp::filters::path::FullPath,
             form_data: FormData| {
                 "Hello!"
             }
        );

    warp::serve(routes).run(([127, 0, 0, 1], 3030)).await;
}

Using this CURL command:
curl -vvv http://localhost:3030/upload/blergh.img -F file=@toolarge.bin

where toolarge.bin is larger than 1024 * 1024 * 10, I receive a "100 Continue" even though the header is not OK (content-length is too large).

> POST /upload/blergh.img HTTP/1.1
> Host: localhost:3030
> User-Agent: curl/7.52.1
> Accept: */*
> Content-Length: 11534536
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=------------------------808fc7c117e269f5
>
< HTTP/1.1 100 Continue
< HTTP/1.1 413 Payload Too Large
< content-type: text/plain; charset=utf-8
< content-length: 32
< date: Fri, 17 Jan 2020 12:53:41 GMT
* HTTP error before end of send, stop sending
<
* Curl_http_done: called premature == 0
* Closing connection 0
The request payload is too large

This confuses clients making them believe they should start sending data. And it causes issues when warp is placed behind a reverse proxy as the closed connection will make at least Apache respond with a 502 gateway error and swallow the error message passed by warp. Curl, and other clients, set the header Expect: 100-continue which indicate they want Content-Length to be verified before sending more data:

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Expect

@janderholm
Copy link
Author

I'm not sure my understanding of the behavior is entirely correct. What I do know is that placing a Warp server behind Apache as a reverse proxy will result in a 502 and a generic Apache error instead of the error returned by Warp.

@seanmonstar
Copy link
Owner

You're understanding is correct, this behavior happens in hyper due to it automatically responding with a 100 Continue no matter what. There's this issue regarding fixing that to only send the 100 Continue if the user tries to read from the body.

@seanmonstar seanmonstar added the bug Something isn't working label Jan 24, 2020
@seanmonstar
Copy link
Owner

This has been fixed in hyper v0.13.2, a cargo update should be all that's needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants