Skip to content

Commit

Permalink
DO NOT COMMIT
Browse files Browse the repository at this point in the history
  • Loading branch information
posix4e committed Aug 21, 2015
1 parent 09b2f43 commit 544a5b7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
22 changes: 15 additions & 7 deletions src/ffi/easy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ impl Easy {

pub fn perform(&mut self,
body: Option<&mut Body>,
progress: Option<Box<ProgressCb>>)
progress: Option<Box<ProgressCb>>,
null_response_body: bool)
-> Result<Response, err::ErrCode> {
let mut builder = ResponseBuilder::new();
let mut builder = ResponseBuilder::new(null_response_body);

unsafe {
let resp_p: usize = mem::transmute(&builder);
Expand Down Expand Up @@ -141,15 +142,17 @@ impl Drop for Easy {
struct ResponseBuilder {
code: u32,
hdrs: HashMap<String,Vec<String>>,
body: Option<Vec<u8>>
none_body: bool,
body: Vec<u8>
}

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
}
}

Expand All @@ -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))
}

}
}

Expand Down
9 changes: 7 additions & 2 deletions src/http/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ impl<'a, 'b> Request<'a, 'b> {
}

pub fn exec(self) -> Result<Response, ErrCode> {

let mut null_body = false;
// Deconstruct the struct
let Request {
err,
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 544a5b7

Please sign in to comment.