Skip to content

Commit

Permalink
fix(client): dont call close() inside Request
Browse files Browse the repository at this point in the history
Only call close() in the Response, which should already return a
responding `Connection: close`.

Closes #519
  • Loading branch information
seanmonstar committed May 10, 2015
1 parent 38f40c7 commit 353ec07
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
9 changes: 5 additions & 4 deletions examples/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use std::env;
use std::io;

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

fn main() {
env_logger::init().unwrap();
Expand All @@ -21,10 +23,9 @@ fn main() {

let mut client = Client::new();

let mut res = match client.get(&*url).send() {
Ok(res) => res,
Err(err) => panic!("Failed to connect: {:?}", err)
};
let mut res = client.get(&*url)
.header(Connection(vec![Close]))
.send().unwrap();

println!("Response: {}", res.status);
println!("Headers:\n{}", res.headers);
Expand Down
6 changes: 1 addition & 5 deletions src/client/request.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Client Requests
use std::marker::PhantomData;
use std::io::{self, Write, BufWriter};
use std::net::Shutdown;

use url::Url;

Expand Down Expand Up @@ -154,10 +153,7 @@ impl Request<Streaming> {
///
/// Consumes the Request.
pub fn send(self) -> ::Result<Response> {
let mut raw = try!(self.body.end()).into_inner().unwrap(); // end() already flushes
if !http::should_keep_alive(self.version, &self.headers) {
try!(raw.close(Shutdown::Write));
}
let raw = try!(self.body.end()).into_inner().unwrap(); // end() already flushes
Response::new(raw)
}
}
Expand Down

0 comments on commit 353ec07

Please sign in to comment.