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 3334fca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 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
8 changes: 2 additions & 6 deletions src/client/request.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
//! Client Requests
use std::marker::PhantomData;
use std::io::{self, Write, BufWriter};
use std::net::Shutdown;

use url::Url;

use method::{self, Method};
use header::Headers;
use header::{self, Host};
use net::{NetworkStream, NetworkConnector, HttpConnector, Fresh, Streaming};
use http::{self, HttpWriter, LINE_ENDING};
use http::{HttpWriter, LINE_ENDING};
use http::HttpWriter::{ThroughWriter, ChunkedWriter, SizedWriter, EmptyWriter};
use version;
use client::{Response, get_host_and_port};
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 3334fca

Please sign in to comment.