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

Server HTTP Method parsing error #652

Closed
fuchsnj opened this issue Sep 10, 2015 · 4 comments
Closed

Server HTTP Method parsing error #652

fuchsnj opened this issue Sep 10, 2015 · 4 comments

Comments

@fuchsnj
Copy link
Contributor

fuchsnj commented Sep 10, 2015

I was able to reproduce an error where an "OPTIONS" request was parsed as "Extension("{}"OPTIONS)"

extern crate hyper;
use hyper::server::{Server, Request, Response};
use hyper::header;

fn hello(req: Request, mut res: Response) {
    println!("method: {:?}", req.method);
    res.headers_mut().set(header::AccessControlAllowOrigin::Any);
    if let Some(requested_headers) = req.headers.get::<header::AccessControlRequestHeaders>()
    .map(|h|h.0.clone()){
        res.headers_mut().set(header::AccessControlAllowHeaders(requested_headers));
    }
}

fn main(){
    Server::http("0.0.0.0:8081").unwrap()
    .handle(hello).unwrap();
}

If you run this code, and access the server from a browser console (something that will trigger a CORS pre-flight OPTIONS request), you will notice the first request is fine, but every other request is parsed incorrectly.

This is the output I get with 5 post requests:

method: Options
method: Post
method: Extension("\"{}\"OPTIONS")
method: Post
method: Extension("\"{}\"OPTIONS")
method: Post
method: Extension("\"{}\"OPTIONS")
method: Post
method: Extension("\"{}\"OPTIONS")
method: Post

I checked the HTTP request using Wireshark, and on the wire each request is identical.

@seanmonstar
Copy link
Member

I imagine this occurs because the string {} is being posted as the request body, and then it's not being read in the hello handler. Hyper then wrongly continues the next request starting from those bytes.

@fuchsnj
Copy link
Contributor Author

fuchsnj commented Sep 10, 2015

That seems to be correct. I am sending "{}" in the POST body

@seanmonstar
Copy link
Member

Yep, just browsed the code, this is the case. See #309

@fuchsnj
Copy link
Contributor Author

fuchsnj commented Sep 10, 2015

Was able to fix this by making sure the request stream was read completely, closing as a duplicate of #309

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

No branches or pull requests

2 participants