Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/uv-auth/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ type FxOnceMap<K, V> = OnceMap<K, V, BuildHasherDefault<FxHasher>>;
pub struct CredentialsCache {
/// A cache per realm and username
realms: RwLock<FxHashMap<(Realm, Username), Arc<Credentials>>>,
/// A cache tracking the result of fetches from external services
pub(crate) fetches: FxOnceMap<(Realm, Username), Option<Arc<Credentials>>>,
/// A cache tracking the result of realm or index URL fetches from external services
pub(crate) fetches: FxOnceMap<(String, Username), Option<Arc<Credentials>>>,
/// A cache per URL, uses a trie for efficient prefix queries.
urls: RwLock<UrlTrie>,
}
Expand Down
15 changes: 13 additions & 2 deletions crates/uv-auth/src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl Indexes {
// efficient search.
self.0
.iter()
.find(|index| url.as_str().starts_with(index.root_url.as_str()))
.find(|index| is_url_prefix(&index.root_url, url))
.map(|index| &index.root_url)
}

Expand All @@ -93,10 +93,21 @@ impl Indexes {
// but we could use a trie instead of a HashMap here for more
// efficient search.
for index in &self.0 {
if url.as_str().starts_with(index.root_url.as_str()) {
if is_url_prefix(&index.root_url, url) {
return index.auth_policy;
}
}
AuthPolicy::Auto
}
}

fn is_url_prefix(base: &Url, url: &Url) -> bool {
if base.scheme() != url.scheme()
|| base.host_str() != url.host_str()
|| base.port_or_known_default() != url.port_or_known_default()
{
return false;
}

url.path().starts_with(base.path())
}
Loading
Loading