use uv_distribution_types::{IndexLocations, IndexUrl, RegistryBuiltWheel};
use uv_redacted::SafeUrl;
use crate::{Error, ErrorKind};
#[derive(Debug, Clone)]
pub(super) struct RegistryWheelRequest<'a> {
url: SafeUrl,
effective_index: &'a IndexUrl,
}
impl<'a> RegistryWheelRequest<'a> {
pub(super) fn for_wheel(
wheel: &'a RegistryBuiltWheel,
indexes: &'a IndexLocations,
) -> Result<Self, Error> {
let (url, effective_index) = if let Some(route) = indexes.proxy_route_for(&wheel.index) {
let url = route
.artifact_url_for_request(&wheel.file.location)
.map_err(ErrorKind::ProxyIndex)?;
(url, route.effective_url())
} else {
let url = wheel
.file
.location
.to_url()
.map_err(ErrorKind::InvalidUrl)?;
(url, &wheel.index)
};
Ok(Self {
url,
effective_index,
})
}
pub(super) fn as_url(&self) -> &SafeUrl {
&self.url
}
pub(super) fn into_url(self) -> SafeUrl {
self.url
}
pub(super) fn into_parts(self) -> (SafeUrl, &'a IndexUrl) {
(self.url, self.effective_index)
}
}