pub async fn redirect_request(&self, mut req: request::Request) -> RequestResult {
        use http::{Method, StatusCode};

        Self::apply_headers(&mut req);

        let mut rem_redirect = C::max_redirect_num();

        let mut method = req.parts.method.clone();
        let uri = req.parts.uri.clone();
        let mut headers = req.parts.headers.clone();
        let mut body = req.body.clone();
        #[cfg(feature = "carry_extensions")]
        let mut extensions = req.extract_extensions();

        loop {
            let ongoing = self.inner.request(req.into());
            let res = matsu!(ongoing).map(|resp| response::Response::new(resp))?;

            match res.status() {
                StatusCode::SEE_OTHER => {
                    rem_redirect -= 1;
                    match rem_redirect {
                        #[cfg(feature = "carry_extensions")]
                        0 => return Ok(res.replace_extensions(&mut extensions)),
                        #[cfg(not(feature = "carry_extensions"))]
                        0 => return Ok(res),
                        _ => {
                            //All requests should be changed to GET with no body.
                            //In most cases it is result of successful POST.
                            body = None;
                            method = Method::GET;
                        }
                    }
                },
                StatusCode::MOVED_PERMANENTLY | StatusCode::FOUND | StatusCode::TEMPORARY_REDIRECT | StatusCode::PERMANENT_REDIRECT => {
                    rem_redirect -= 1;
                    match rem_redirect {
                        #[cfg(feature = "carry_extensions")]
                        0 => return Ok(res.replace_extensions(&mut extensions)),
                        #[cfg(not(feature = "carry_extensions"))]
                        0 => return Ok(res),
                        _ => (),
                    }
                }
                #[cfg(feature = "carry_extensions")]
                _ => return Ok(res.replace_extensions(&mut extensions)),
                #[cfg(not(feature = "carry_extensions"))]
                _ => return Ok(res),
            }

            let location = match res.headers().get(header::LOCATION).and_then(|loc| loc.to_str().ok()).and_then(|loc| loc.parse::<hyper::Uri>().ok()) {
                Some(loc) => match loc.scheme().is_some() {
                    //We assume that if scheme is present then it is absolute redirect
                    true => {
                        //Well, it is unlikely that host would be empty, but just in case, right?
                        if let Some(prev_host) = uri.authority().map(|part| part.host()) {
                            match loc.authority().map(|part| part.host() == prev_host).unwrap_or(false) {
                                true => (),
                                false => {
                                    headers.remove("authorization");
                                    headers.remove("cookie");
                                    headers.remove("cookie2");
                                    headers.remove("www-authenticate");
                                }
                            }
                        }

                        loc
                    },
                    //Otherwise it is relative to current location.
                    false => {
                        let current = Path::new(uri.path());
                        let loc = Path::new(loc.path());
                        let loc = current.join(loc);
                        let loc = loc.to_str().expect("Valid UTF-8 path").parse::<hyper::Uri>().expect("Valid URI");
                        let mut loc_parts = loc.into_parts();

                        loc_parts.scheme = uri.scheme().cloned();
                        loc_parts.authority = uri.authority().cloned();

                        hyper::Uri::from_parts(loc_parts).expect("Create redirect URI")
                    },
                },
                #[cfg(feature = "carry_extensions")]
                None => return Ok(res.replace_extensions(&mut extensions)),
                #[cfg(not(feature = "carry_extensions"))]
                None => return Ok(res),
            };

            let (mut parts, _) = hyper::Request::<()>::new(()).into_parts();
            parts.method = method.clone();
            parts.uri = location;
            parts.headers = headers.clone();

            req = request::Request {
                parts,
                body: body.clone()
            };
        }
    }
///Sends request and returns response, while handling redirects.
Sends request and returns response, while handling redirects.
Sends request and returns response while handling redirects .
pub async fn redirect_request(&self, mut req: request::Request) -> RequestResult {
        use http::{Method, StatusCode};
        Self::apply_headers(&mut req);
        let mut rem_redirect = C::max_redirect_num();
        let mut method = req.parts.method.clone();
        let uri = req.parts.uri.clone();
        let mut headers = req.parts.headers.clone();
        let mut body = req.body.clone();
        #[cfg(feature = "carry_extensions")]
        let mut extensions = req.extract_extensions();
        loop {
            let ongoing = self.inner.request(req.into());
            let res = matsu!(ongoing).map(|resp| response::Response::new(resp))?;
            match res.status() {
                StatusCode::SEE_OTHER => {
                    rem_redirect -= 1;
                    match rem_redirect {
                        #[cfg(feature = "carry_extensions")]
                        0 => return Ok(res.replace_extensions(&mut extensions)),
                        #[cfg(not(feature = "carry_extensions"))]
                        0 => return Ok(res),
                        _ => {
                            //All requests should be changed to GET with no body.
                            //In most cases it is result of successful POST.
                            body = None;
                            method = Method::GET;
                        }
                    }
                },
                StatusCode::MOVED_PERMANENTLY | StatusCode::FOUND | StatusCode::TEMPORARY_REDIRECT | StatusCode::PERMANENT_REDIRECT => {
                    rem_redirect -= 1;
                    match rem_redirect {
                        #[cfg(feature = "carry_extensions")]
                        0 => return Ok(res.replace_extensions(&mut extensions)),
                        #[cfg(not(feature = "carry_extensions"))]
                        0 => return Ok(res),
                        _ => (),
                    }
                }
                #[cfg(feature = "carry_extensions")]
                _ => return Ok(res.replace_extensions(&mut extensions)),
                #[cfg(not(feature = "carry_extensions"))]
                _ => return Ok(res),
            }
            let location = match res.headers().get(header::LOCATION).and_then(|loc| loc.to_str().ok()).and_then(|loc| loc.parse::<hyper::Uri>().ok()) {
                Some(loc) => match loc.scheme().is_some() {
                    //We assume that if scheme is present then it is absolute redirect
                    true => {
                        //Well, it is unlikely that host would be empty, but just in case, right?
                        if let Some(prev_host) = uri.authority().map(|part| part.host()) {
                            match loc.authority().map(|part| part.host() == prev_host).unwrap_or(false) {
                                true => (),
                                false => {
                                    headers.remove("authorization");
                                    headers.remove("cookie");
                                    headers.remove("cookie2");
                                    headers.remove("www-authenticate");
                                }
                            }
                        }
                        loc
                    },
                    //Otherwise it is relative to current location.
                    false => {
                        let current = Path::new(uri.path());
                        let loc = Path::new(loc.path());
                        let loc = current.join(loc);
                        let loc = loc.to_str().expect("Valid UTF-8 path").parse::<hyper::Uri>().expect("Valid URI");
                        let mut loc_parts = loc.into_parts();
                        loc_parts.scheme = uri.scheme().cloned();
                        loc_parts.authority = uri.authority().cloned();
                        hyper::Uri::from_parts(loc_parts).expect("Create redirect URI")
                    },
                },
                #[cfg(feature = "carry_extensions")]
                None => return Ok(res.replace_extensions(&mut extensions)),
                #[cfg(not(feature = "carry_extensions"))]
                None => return Ok(res),
            };
            let (mut parts, _) = hyper::Request::<()>::new(()).into_parts();
            parts.method = method.clone();
            parts.uri = location;
            parts.headers = headers.clone();
            req = request::Request {
                parts,
                body: body.clone()
            };
        }
    }
pub async fn redirect_request ( & self , mut req : request :: Request ) -> RequestResult { use http :: { Method , StatusCode } ; Self :: apply_headers ( & mut req ) ; let mut rem_redirect = C :: max_redirect_num ( ) ; let mut method = req . parts . method . clone ( ) ; let uri = req . parts . uri . clone ( ) ; let mut headers = req . parts . headers . clone ( ) ; let mut body = req . body . clone ( ) ; # [ cfg ( feature " " ) ] let mut extensions = req . extract_extensions ( ) ; loop { let ongoing = self . inner . request ( req . into ( ) ) ; let res = matsu ! ( ongoing ) . map ( | resp | response :: Response :: new ( resp ) ) ? ; match res . status ( ) { StatusCode :: SEE_OTHER => { rem_redirect -= 1 ; match rem_redirect { # [ cfg ( feature " " ) ] 0 => return Ok ( res . replace_extensions ( & mut extensions ) ) , # [ cfg ( not ( feature " " ) ) ] 0 => return Ok ( res ) , _ => { //All requests should be changed to GET with no body. //In most cases it is result of successful POST. body = None ; method = Method :: GET ; } } } , StatusCode :: MOVED_PERMANENTLY | StatusCode :: FOUND | StatusCode :: TEMPORARY_REDIRECT | StatusCode :: PERMANENT_REDIRECT => { rem_redirect -= 1 ; match rem_redirect { # [ cfg ( feature " " ) ] 0 => return Ok ( res . replace_extensions ( & mut extensions ) ) , # [ cfg ( not ( feature " " ) ) ] 0 => return Ok ( res ) , _ => ( ) , } } # [ cfg ( feature " " ) ] _ => return Ok ( res . replace_extensions ( & mut extensions ) ) , # [ cfg ( not ( feature " " ) ) ] _ => return Ok ( res ) , } let location = match res . headers ( ) . get ( header :: LOCATION ) . and_then ( | loc | loc . to_str ( ) . ok ( ) ) . and_then ( | loc | loc . parse :: < hyper :: Uri > ( ) . ok ( ) ) { Some ( loc ) => match loc . scheme ( ) . is_some ( ) { //We assume that if scheme is present then it is absolute redirect true => { //Well, it is unlikely that host would be empty, but just in case, right? if let Some ( prev_host ) = uri . authority ( ) . map ( | part | part . host ( ) ) { match loc . authority ( ) . map ( | part | part . host ( ) == prev_host ) . unwrap_or ( false ) { true => ( ) , false => { headers . remove ( " " ) ; headers . remove ( " " ) ; headers . remove ( " " ) ; headers . remove ( " " ) ; } } } loc } , //Otherwise it is relative to current location. false => { let current = Path :: new ( uri . path ( ) ) ; let loc = Path :: new ( loc . path ( ) ) ; let loc = current . join ( loc ) ; let loc = loc . to_str ( ) . expect ( " " ) . parse :: < hyper :: Uri > ( ) . expect ( " " ) ; let mut loc_parts = loc . into_parts ( ) ; loc_parts . scheme = uri . scheme ( ) . cloned ( ) ; loc_parts . authority = uri . authority ( ) . cloned ( ) ; hyper :: Uri :: from_parts ( loc_parts ) . expect ( " " ) } , } , # [ cfg ( feature " " ) ] None => return Ok ( res . replace_extensions ( & mut extensions ) ) , # [ cfg ( not ( feature " " ) ) ] None => return Ok ( res ) , } ; let ( mut parts , _ ) = hyper :: Request :: < ( ) > :: new ( ( ) ) . into_parts ( ) ; parts . method = method . clone ( ) ; parts . uri = location ; parts . headers = headers . clone ( ) ; req = request :: Request { parts , body : body . clone ( ) } ; } }
Sends request and returns response, while handling redirects.
Sends request and returns response while handling redirects .
&self
req
request::Request