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

fix(client): dont call close() inside Request #520

Merged
merged 1 commit into from
May 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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