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

Hyper client after v0.3.15 can't connect to some nginx servers with ConnectionOption::Close #519

Closed
amoskvin opened this issue May 9, 2015 · 0 comments · Fixed by #520
Closed

Comments

@amoskvin
Copy link

amoskvin commented May 9, 2015

Starting with commit 1e72a8a, Hyper errors out when trying to connect to some servers with ConnectionOption::Close header set. A common pattern seems to be that they're running nginx.

Here's a modified version of the example client:

extern crate hyper;

use std::io::Read;

use hyper::Client;
use hyper::header::Connection;
use hyper::header::ConnectionOption;

fn main() {
    for url in vec![
            "http://doc.rust-lang.org",
            "http://www.linode.com",
            "http://digitalocean.com",
            "http://www.reddit.com",
            "http://www.kernel.org",
            "http://www.gooogle.com",
        ]
    {
        run(url);
    }
}

fn run(url: &str) {
    println!("Retrieve {}:", url);
    let mut client = Client::new();
    let result = client.get(url)
        .header(Connection(vec![ConnectionOption::Close]))
        .send();

    match result {
        Ok(mut res) => {
                let mut body = String::new();
                res.read_to_string(&mut body).unwrap();
                println!("Success: {} bytes", body.len());
            },
        Err(_) => {
                println!("Failed: {:?}", result);
            },
    }
    println!("");
}
$ cargo update; cargo run
    Updating registry `https://github.com/rust-lang/crates.io-index`
   Compiling hyper v0.4.0 (file:///home/alec/test1)
   Compiling test1 v0.1.0 (file:///home/alec/test1)
     Running `target/debug/test1`
Retrieve http://doc.rust-lang.org:
Failed: Err(Io(Error { repr: Custom(Custom { kind: ConnectionAborted, error: StringError("Connection closed") }) }))

Retrieve http://www.linode.com:
Failed: Err(Io(Error { repr: Custom(Custom { kind: ConnectionAborted, error: StringError("Connection closed") }) }))

Retrieve http://digitalocean.com:
Failed: Err(Io(Error { repr: Custom(Custom { kind: ConnectionAborted, error: StringError("Connection closed") }) }))

Retrieve http://www.reddit.com:
Failed: Err(Io(Error { repr: Custom(Custom { kind: ConnectionAborted, error: StringError("Connection closed") }) }))

Retrieve http://www.kernel.org:
Failed: Err(Io(Error { repr: Custom(Custom { kind: ConnectionAborted, error: StringError("Connection closed") }) }))

Retrieve http://www.gooogle.com:
Success: 52184 bytes

$ cargo update; cargo run
    Updating registry `https://github.com/rust-lang/crates.io-index`
   Compiling hyper v0.3.15 (file:///home/alec/test1)
   Compiling test1 v0.1.0 (file:///home/alec/test1)
     Running `target/debug/test1`
Retrieve http://doc.rust-lang.org:
Success: 6414 bytes

Retrieve http://www.linode.com:
Success: 19898 bytes

Retrieve http://digitalocean.com:
Success: 19559 bytes

Retrieve http://www.reddit.com:
Success: 114095 bytes

Retrieve http://www.kernel.org:
Success: 19090 bytes

Retrieve http://www.gooogle.com:
Success: 52216 bytes

$ rustc --version
rustc 1.0.0-beta.4 (built 2015-05-09)
seanmonstar added a commit that referenced this issue May 10, 2015
Only call close() in the Response, which should already return a
responding `Connection: close`.

Closes #519
seanmonstar added a commit that referenced this issue May 10, 2015
Only call close() in the Response, which should already return a
responding `Connection: close`.

Closes #519
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 a pull request may close this issue.

1 participant