From 353ec07c9545b120400e0a06ee9b4a2aa92f590f Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Sat, 9 May 2015 22:07:34 -0700 Subject: [PATCH] fix(client): dont call close() inside Request Only call close() in the Response, which should already return a responding `Connection: close`. Closes #519 --- examples/client.rs | 9 +++++---- src/client/request.rs | 6 +----- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/examples/client.rs b/examples/client.rs index b2d32667c0..ba638c66dd 100644 --- a/examples/client.rs +++ b/examples/client.rs @@ -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(); @@ -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); diff --git a/src/client/request.rs b/src/client/request.rs index 33fe724d65..b8dfa4e369 100644 --- a/src/client/request.rs +++ b/src/client/request.rs @@ -1,7 +1,6 @@ //! Client Requests use std::marker::PhantomData; use std::io::{self, Write, BufWriter}; -use std::net::Shutdown; use url::Url; @@ -154,10 +153,7 @@ impl Request { /// /// Consumes the Request. pub fn send(self) -> ::Result { - 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) } }