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

Err value: Version when unwrapping a response #753

Closed
rlepidi opened this issue Mar 31, 2016 · 2 comments
Closed

Err value: Version when unwrapping a response #753

rlepidi opened this issue Mar 31, 2016 · 2 comments

Comments

@rlepidi
Copy link

rlepidi commented Mar 31, 2016

The exact error described in #715 still appears to be happening in some cases. I am running v0.8.0 but ran into the same issue on master.

See below for a reduced case that fully reproduces the error. What's interesting is removing the call to request and inlining that logic into main makes the problem go away.

extern crate hyper;

use hyper::Client;
use hyper::client::RequestBuilder;
use hyper::header::{AcceptEncoding, Encoding, qitem};
use std::io::Read;

fn request(builder: RequestBuilder) {
    let mut response = builder
        .header(AcceptEncoding(vec![qitem(Encoding::Gzip), qitem(Encoding::Deflate)]))
        .send()
        .unwrap();

    let mut compressed_body = vec![];
    response.read_to_end(&mut compressed_body).unwrap();
}

fn main() {
    let client = Client::new();
    request(client.get("https://api-fxpractice.oanda.com/v1/candles?instrument=EUR_USD&count=4999&granularity=S5&start=2012-09-07T11%3A32%3A00&includeFirst=false"));
    request(client.get("https://api-fxpractice.oanda.com/v1/candles?instrument=EUR_USD&count=4999&granularity=S5&start=2012-09-09T23%3A09%3A00&includeFirst=false"));
}
@seanmonstar
Copy link
Member

The error is a combination of 2 things:

  1. The Client is reusing the socket, since the server responded with keep-alive. This is not a bug.
  2. The server is sending an extra \n after the end of the first response, and so when the hyper starts to parse the second response, it first sees the stray \n. hyper's parser knows to skip empty lines when handling server requests, but it seems that it was not included in client responses.

I'll fix it in the httparse crate, and since it's a bug fix, you'll be able to just cargo update to receive it.

@seanmonstar
Copy link
Member

Just tried with the latest update of httparse v1.1.2, and it now works properly!

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