diff --git a/src/ffi/easy.rs b/src/ffi/easy.rs index 1e319d31d7..d5a6eda851 100644 --- a/src/ffi/easy.rs +++ b/src/ffi/easy.rs @@ -48,9 +48,10 @@ impl Easy { pub fn perform(&mut self, body: Option<&mut Body>, - progress: Option>) + progress: Option>, + null_response_body: bool) -> Result { - let mut builder = ResponseBuilder::new(); + let mut builder = ResponseBuilder::new(null_response_body); unsafe { let resp_p: usize = mem::transmute(&builder); @@ -141,15 +142,17 @@ impl Drop for Easy { struct ResponseBuilder { code: u32, hdrs: HashMap>, - body: Option> + none_body: bool, + body: Vec } impl ResponseBuilder { - fn new() -> ResponseBuilder { + fn new(body_none: bool) -> ResponseBuilder { ResponseBuilder { code: 0, hdrs: HashMap::new(), - body: None + body: Vec::new(), + none_body: body_none } } @@ -172,8 +175,13 @@ impl ResponseBuilder { } fn build(self) -> Response { - let ResponseBuilder { code, hdrs, body } = self; - Response::new(code, hdrs, body) + let ResponseBuilder { code, hdrs, body , none_body} = self; + if none_body { + Response::new(code, hdrs, None) + } else { + Response::new(code, hdrs, Some(body)) + } + } } diff --git a/src/http/handle.rs b/src/http/handle.rs index 7e0148fda5..2a229aa06c 100644 --- a/src/http/handle.rs +++ b/src/http/handle.rs @@ -273,6 +273,8 @@ impl<'a, 'b> Request<'a, 'b> { } pub fn exec(self) -> Result { + + let mut null_body = false; // Deconstruct the struct let Request { err, @@ -302,7 +304,10 @@ impl<'a, 'b> Request<'a, 'b> { match method { Get => try!(handle.easy.setopt(opt::HTTPGET, 1)), - Head => try!(handle.easy.setopt(opt::NOBODY, 1)), + Head => { + null_body = true; + try!(handle.easy.setopt(opt::NOBODY, 1)) + } Post => try!(handle.easy.setopt(opt::POST, 1)), Put => try!(handle.easy.setopt(opt::UPLOAD, 1)), Patch => { @@ -377,7 +382,7 @@ impl<'a, 'b> Request<'a, 'b> { try!(handle.easy.setopt(opt::HTTPHEADER, &ffi_headers)); } - handle.easy.perform(body.as_mut(), progress) + handle.easy.perform(body.as_mut(), progress, null_body) } pub fn nullBody(mut self) -> Request<'a, 'b> { self.body = None;