pub fn canonicalize_url(url: &Url) -> Url {
    let mut url = url.clone();

    // Strip a trailing slash
    if let url::SchemeData::Relative(ref mut rel) = url.scheme_data {
        if rel.path.last().map(|s| s.is_empty()).unwrap_or(false) {
            rel.path.pop();
        }
    }

    // HACKHACK: For github URL's specifically just lowercase
    // everything.  GitHub treats both the same, but they hash
    // differently, and we're gonna be hashing them. This wants a more
    // general solution, and also we're almost certainly not using the
    // same case conversion rules that GitHub does. (#84)
    if url.domain() == Some("github.com") {
        url.scheme = "https".to_string();
        if let url::SchemeData::Relative(ref mut rel) = url.scheme_data {
            rel.port = Some(443);
            rel.default_port = Some(443);
            let path = mem::replace(&mut rel.path, Vec::new());
            rel.path = path.into_iter().map(|s| {
                s.chars().flat_map(|c| c.to_lowercase()).collect()
            }).collect();
        }
    }

    // Repos generally can be accessed with or w/o '.git'
    if let url::SchemeData::Relative(ref mut rel) = url.scheme_data {
        let needs_chopping = {
            let last = rel.path.last().map(|s| &s[..]).unwrap_or("");
            last.ends_with(".git")
        };
        if needs_chopping {
            let last = rel.path.pop().unwrap();
            rel.path.push(last[..last.len() - 4].to_string())
        }
    }

    url
}
// Some hacks and heuristics for making equivalent URLs hash the same
Some hacks and heuristics for making equivalent URLs hash the same
Some hacks and heuristics for making equivalent URLs hash the same
pub fn canonicalize_url(url: &Url) -> Url {
    let mut url = url.clone();
    // Strip a trailing slash
    if let url::SchemeData::Relative(ref mut rel) = url.scheme_data {
        if rel.path.last().map(|s| s.is_empty()).unwrap_or(false) {
            rel.path.pop();
        }
    }
    // HACKHACK: For github URL's specifically just lowercase
    // everything.  GitHub treats both the same, but they hash
    // differently, and we're gonna be hashing them. This wants a more
    // general solution, and also we're almost certainly not using the
    // same case conversion rules that GitHub does. (#84)
    if url.domain() == Some("github.com") {
        url.scheme = "https".to_string();
        if let url::SchemeData::Relative(ref mut rel) = url.scheme_data {
            rel.port = Some(443);
            rel.default_port = Some(443);
            let path = mem::replace(&mut rel.path, Vec::new());
            rel.path = path.into_iter().map(|s| {
                s.chars().flat_map(|c| c.to_lowercase()).collect()
            }).collect();
        }
    }
    // Repos generally can be accessed with or w/o '.git'
    if let url::SchemeData::Relative(ref mut rel) = url.scheme_data {
        let needs_chopping = {
            let last = rel.path.last().map(|s| &s[..]).unwrap_or("");
            last.ends_with(".git")
        };
        if needs_chopping {
            let last = rel.path.pop().unwrap();
            rel.path.push(last[..last.len() - 4].to_string())
        }
    }
    url
}
pub fn canonicalize_url ( url : & Url ) -> Url { let mut url = url . clone ( ) ; // Strip a trailing slash if let url :: SchemeData :: Relative ( ref mut rel ) = url . scheme_data { if rel . path . last ( ) . map ( | s | s . is_empty ( ) ) . unwrap_or ( false ) { rel . path . pop ( ) ; } } // HACKHACK: For github URL's specifically just lowercase // everything.  GitHub treats both the same, but they hash // differently, and we're gonna be hashing them. This wants a more // general solution, and also we're almost certainly not using the // same case conversion rules that GitHub does. (#84) if url . domain ( ) == Some ( " " ) { url . scheme = " " . to_string ( ) ; if let url :: SchemeData :: Relative ( ref mut rel ) = url . scheme_data { rel . port = Some ( 443 ) ; rel . default_port = Some ( 443 ) ; let path = mem :: replace ( & mut rel . path , Vec :: new ( ) ) ; rel . path = path . into_iter ( ) . map ( | s | { s . chars ( ) . flat_map ( | c | c . to_lowercase ( ) ) . collect ( ) } ) . collect ( ) ; } } // Repos generally can be accessed with or w/o '.git' if let url :: SchemeData :: Relative ( ref mut rel ) = url . scheme_data { let needs_chopping = { let last = rel . path . last ( ) . map ( | s | & s [ .. ] ) . unwrap_or ( " " ) ; last . ends_with ( " " ) } ; if needs_chopping { let last = rel . path . pop ( ) . unwrap ( ) ; rel . path . push ( last [ .. last . len ( ) - 4 ] . to_string ( ) ) } } url }
Some hacks and heuristics for making equivalent URLs hash the same
Some hacks and heuristics for making equivalent URLs hash the same
url
&Url
url
&Url