pub fn send(self) -> HttpResult<Response> {
        let RequestBuilder { client, method, url, headers, body } = self;
        let mut url = try!(url.into_url());
        debug!("client.request {} {}", method, url);

        let can_have_body = match &method {
            &Method::Get | &Method::Head => false,
            _ => true
        };

        let mut body = if can_have_body {
            body.map(|b| b.into_body())
        } else {
             None
        };

        loop {
            let mut req = try!(Request::with_connector(method.clone(), url.clone(), &mut client.connector));
            headers.as_ref().map(|headers| req.headers_mut().extend(headers.iter()));

            match (can_have_body, body.as_ref()) {
                (true, Some(ref body)) => match body.size() {
                    Some(size) => req.headers_mut().set(ContentLength(size)),
                    None => (), // chunked, Request will add it automatically
                },
                (true, None) => req.headers_mut().set(ContentLength(0)),
                _ => () // neither
            }
            let mut streaming = try!(req.start());
            body.take().map(|mut rdr| copy(&mut rdr, &mut streaming));
            let res = try!(streaming.send());
            if res.status.class() != Redirection {
                return Ok(res)
            }
            debug!("redirect code {} for {}", res.status, url);

            let loc = {
                // punching borrowck here
                let loc = match res.headers.get::<Location>() {
                    Some(&Location(ref loc)) => {
                        Some(UrlParser::new().base_url(&url).parse(loc[]))
                    }
                    None => {
                        debug!("no Location header");
                        // could be 304 Not Modified?
                        None
                    }
                };
                match loc {
                    Some(r) => r,
                    None => return Ok(res)
                }
            };
            url = match loc {
                Ok(u) => {
                    inspect!("Location", u)
                },
                Err(e) => {
                    debug!("Location header had invalid URI: {}", e);
                    return Ok(res);
                }
            };
            match client.redirect_policy {
                // separate branches because they cant be one
                RedirectPolicy::FollowAll => (), //continue
                RedirectPolicy::FollowIf(cond) if cond(&url) => (), //continue
                _ => return Ok(res),
            }
        }
    }
/// Execute this request and receive a Response back.
Execute this request and receive a Response back.
Execute this request and receive a Response back .
pub fn send(self) -> HttpResult<Response> {
        let RequestBuilder { client, method, url, headers, body } = self;
        let mut url = try!(url.into_url());
        debug!("client.request {} {}", method, url);
        let can_have_body = match &method {
            &Method::Get | &Method::Head => false,
            _ => true
        };
        let mut body = if can_have_body {
            body.map(|b| b.into_body())
        } else {
             None
        };
        loop {
            let mut req = try!(Request::with_connector(method.clone(), url.clone(), &mut client.connector));
            headers.as_ref().map(|headers| req.headers_mut().extend(headers.iter()));
            match (can_have_body, body.as_ref()) {
                (true, Some(ref body)) => match body.size() {
                    Some(size) => req.headers_mut().set(ContentLength(size)),
                    None => (), // chunked, Request will add it automatically
                },
                (true, None) => req.headers_mut().set(ContentLength(0)),
                _ => () // neither
            }
            let mut streaming = try!(req.start());
            body.take().map(|mut rdr| copy(&mut rdr, &mut streaming));
            let res = try!(streaming.send());
            if res.status.class() != Redirection {
                return Ok(res)
            }
            debug!("redirect code {} for {}", res.status, url);
            let loc = {
                // punching borrowck here
                let loc = match res.headers.get::<Location>() {
                    Some(&Location(ref loc)) => {
                        Some(UrlParser::new().base_url(&url).parse(loc[]))
                    }
                    None => {
                        debug!("no Location header");
                        // could be 304 Not Modified?
                        None
                    }
                };
                match loc {
                    Some(r) => r,
                    None => return Ok(res)
                }
            };
            url = match loc {
                Ok(u) => {
                    inspect!("Location", u)
                },
                Err(e) => {
                    debug!("Location header had invalid URI: {}", e);
                    return Ok(res);
                }
            };
            match client.redirect_policy {
                // separate branches because they cant be one
                RedirectPolicy::FollowAll => (), //continue
                RedirectPolicy::FollowIf(cond) if cond(&url) => (), //continue
                _ => return Ok(res),
            }
        }
    }
pub fn send ( self ) -> HttpResult < Response > { let RequestBuilder { client , method , url , headers , body } = self ; let mut url = try ! ( url into_url ( ) ) ; debug ! ( " " method url ) ; let can_have_body = match & method { & Method :: Get | & Method :: Head => false , _ => true } ; let mut body = if can_have_body { body . map ( | b | b . into_body ( ) ) } else { None } ; loop { let mut req = try ! ( Request with_connector ( method clone ( ) url clone ( ) mut client connector ) ) ; headers . as_ref ( ) . map ( | headers | req . headers_mut ( ) . extend ( headers . iter ( ) ) ) ; match ( can_have_body , body . as_ref ( ) ) { ( true , Some ( ref body ) ) => match body . size ( ) { Some ( size ) => req . headers_mut ( ) . set ( ContentLength ( size ) ) , None => ( ) , // chunked, Request will add it automatically } , ( true , None ) => req . headers_mut ( ) . set ( ContentLength ( 0 ) ) , _ => ( ) // neither } let mut streaming = try ! ( req start ( ) ) ; body . take ( ) . map ( | mut rdr | copy ( & mut rdr , & mut streaming ) ) ; let res = try ! ( streaming send ( ) ) ; if res . status . class ( ) != Redirection { return Ok ( res ) } debug ! ( " " res status url ) ; let loc = { // punching borrowck here let loc = match res . headers . get :: < Location > ( ) { Some ( & Location ( ref loc ) ) => { Some ( UrlParser :: new ( ) . base_url ( & url ) . parse ( loc [ ] ) ) } None => { debug ! ( " " ) ; // could be 304 Not Modified? None } } ; match loc { Some ( r ) => r , None => return Ok ( res ) } } ; url = match loc { Ok ( u ) => { inspect ! ( " " u ) } , Err ( e ) => { debug ! ( " " e ) ; return Ok ( res ) ; } } ; match client . redirect_policy { // separate branches because they cant be one RedirectPolicy :: FollowAll => ( ) , //continue RedirectPolicy :: FollowIf ( cond ) if cond ( & url ) => ( ) , //continue _ => return Ok ( res ) , } } }
Execute this request and receive a Response back.
Execute this request and receive a Response back .
self
self