pub(crate) fn redirect_to(&mut self, url: URL) -> Result<(), Error> {
        // If the redirected resource does not have a fragment, but
        // the original URL did, the fragment should be preserved over
        // redirections. See RFC 7231 section 7.1.2.
        let inherit_fragment = |resource: String, original_resource: &str| {
            if resource.chars().any(|c| c == '#') {
                resource
            } else {
                let mut original_resource_split = original_resource.split('#');
                if let Some(fragment) = original_resource_split.nth(1) {
                    format!("{}#{}", resource, fragment)
                } else {
                    resource
                }
            }
        };

        if url.contains("://") {
            let (mut https, mut host, mut port, resource) =
                parse_url(&url).map_err(|_| Error::InvalidProtocolInRedirect)?;
            let mut resource = inherit_fragment(resource, &self.resource);
            std::mem::swap(&mut https, &mut self.https);
            std::mem::swap(&mut host, &mut self.host);
            std::mem::swap(&mut port, &mut self.port);
            std::mem::swap(&mut resource, &mut self.resource);
            self.redirects.push((https, host, resource));
        } else {
            // The url does not have the protocol part, assuming it's
            // a relative resource.
            let mut resource = inherit_fragment(url, &self.resource);
            std::mem::swap(&mut resource, &mut self.resource);
            self.redirects
                .push((self.https, self.host.clone(), resource));
        }

        let is_this_url = |(https_, host_, resource_): &(bool, URL, URL)| {
            resource_ == &self.resource && host_ == &self.host && https_ == &self.https
        };

        if self.redirects.len() > self.config.max_redirects {
            Err(Error::TooManyRedirections)
        } else if self.redirects.iter().any(is_this_url) {
            Err(Error::InfiniteRedirectionLoop)
        } else {
            Ok(())
        }
    }
/// Returns the redirected version of this Request, unless an
/// infinite redirection loop was detected, or the redirection
/// limit was reached.
Returns the redirected version of this Request, unless an
infinite redirection loop was detected, or the redirection
limit was reached.
Returns the redirected version of this Request unless an infinite redirection loop was detected or the redirection limit was reached .
pub(crate) fn redirect_to(&mut self, url: URL) -> Result<(), Error> {
        // If the redirected resource does not have a fragment, but
        // the original URL did, the fragment should be preserved over
        // redirections. See RFC 7231 section 7.1.2.
        let inherit_fragment = |resource: String, original_resource: &str| {
            if resource.chars().any(|c| c == '#') {
                resource
            } else {
                let mut original_resource_split = original_resource.split('#');
                if let Some(fragment) = original_resource_split.nth(1) {
                    format!("{}#{}", resource, fragment)
                } else {
                    resource
                }
            }
        };
        if url.contains("://") {
            let (mut https, mut host, mut port, resource) =
                parse_url(&url).map_err(|_| Error::InvalidProtocolInRedirect)?;
            let mut resource = inherit_fragment(resource, &self.resource);
            std::mem::swap(&mut https, &mut self.https);
            std::mem::swap(&mut host, &mut self.host);
            std::mem::swap(&mut port, &mut self.port);
            std::mem::swap(&mut resource, &mut self.resource);
            self.redirects.push((https, host, resource));
        } else {
            // The url does not have the protocol part, assuming it's
            // a relative resource.
            let mut resource = inherit_fragment(url, &self.resource);
            std::mem::swap(&mut resource, &mut self.resource);
            self.redirects
                .push((self.https, self.host.clone(), resource));
        }
        let is_this_url = |(https_, host_, resource_): &(bool, URL, URL)| {
            resource_ == &self.resource && host_ == &self.host && https_ == &self.https
        };
        if self.redirects.len() > self.config.max_redirects {
            Err(Error::TooManyRedirections)
        } else if self.redirects.iter().any(is_this_url) {
            Err(Error::InfiniteRedirectionLoop)
        } else {
            Ok(())
        }
    }
pub ( crate ) fn redirect_to ( & mut self , url : URL ) -> Result < ( ) , Error > { // If the redirected resource does not have a fragment, but // the original URL did, the fragment should be preserved over // redirections. See RFC 7231 section 7.1.2. let inherit_fragment = | resource : String , original_resource : & str | { if resource . chars ( ) . any ( | c | c == '#' ) { resource } else { let mut original_resource_split = original_resource . split ( '#' ) ; if let Some ( fragment ) = original_resource_split . nth ( 1 ) { format ! ( " " resource fragment ) } else { resource } } } ; if url . contains ( " " ) { let ( mut https , mut host , mut port , resource ) = parse_url ( & url ) . map_err ( | _ | Error :: InvalidProtocolInRedirect ) ? ; let mut resource = inherit_fragment ( resource , & self . resource ) ; std :: mem :: swap ( & mut https , & mut self . https ) ; std :: mem :: swap ( & mut host , & mut self . host ) ; std :: mem :: swap ( & mut port , & mut self . port ) ; std :: mem :: swap ( & mut resource , & mut self . resource ) ; self . redirects . push ( ( https , host , resource ) ) ; } else { // The url does not have the protocol part, assuming it's // a relative resource. let mut resource = inherit_fragment ( url , & self . resource ) ; std :: mem :: swap ( & mut resource , & mut self . resource ) ; self . redirects . push ( ( self . https , self . host . clone ( ) , resource ) ) ; } let is_this_url = | ( https_ , host_ , resource_ ) : & ( bool , URL , URL ) | { resource_ == & self . resource && host_ == & self . host && https_ == & self . https } ; if self . redirects . len ( ) > self . config . max_redirects { Err ( Error :: TooManyRedirections ) } else if self . redirects . iter ( ) . any ( is_this_url ) { Err ( Error :: InfiniteRedirectionLoop ) } else { Ok ( ( ) ) } }
Returns the redirected version of this Request, unless an
infinite redirection loop was detected, or the redirection
limit was reached.
Returns the redirected version of this Request unless an infinite redirection loop was detected or the redirection limit was reached .
&mut self
url
URL
&mut self
url
URL