1use std::borrow::Cow;
2use std::fmt::{Display, Formatter};
3use std::ops::Deref;
4use std::path::Path;
5use std::str::FromStr;
6use std::sync::{Arc, LazyLock, RwLock};
7
8use itertools::Either;
9use rustc_hash::{FxHashMap, FxHashSet};
10use thiserror::Error;
11use url::{ParseError, Url};
12use uv_auth::RealmRef;
13use uv_cache_key::CanonicalUrl;
14use uv_pep508::{Scheme, VerbatimUrl, VerbatimUrlError, split_scheme};
15use uv_redacted::DisplaySafeUrl;
16use uv_warnings::warn_user;
17
18use crate::{ExcludeNewerOverride, Index, IndexStatusCodeStrategy, Verbatim};
19
20static PYPI_URL: LazyLock<DisplaySafeUrl> =
21 LazyLock::new(|| DisplaySafeUrl::parse("https://pypi.org/simple").unwrap());
22
23static DEFAULT_INDEX: LazyLock<Index> = LazyLock::new(|| {
24 Index::from_index_url(IndexUrl::Pypi(Arc::new(VerbatimUrl::from_url(
25 PYPI_URL.clone(),
26 ))))
27});
28
29#[derive(Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
31pub enum IndexUrl {
32 Pypi(Arc<VerbatimUrl>),
33 Url(Arc<VerbatimUrl>),
34 Path(Arc<VerbatimUrl>),
35}
36
37impl IndexUrl {
38 pub fn parse(path: &str, root_dir: Option<&Path>) -> Result<Self, IndexUrlError> {
43 let url = VerbatimUrl::from_url_or_path(path, root_dir)?;
44 Ok(Self::from(url))
45 }
46
47 pub fn root(&self) -> Option<DisplaySafeUrl> {
52 let mut segments = self.url().path_segments()?;
53 let last = match segments.next_back()? {
54 "" => segments.next_back()?,
56 segment => segment,
57 };
58
59 if !(last.eq_ignore_ascii_case("simple") || last.eq_ignore_ascii_case("+simple")) {
61 return None;
62 }
63
64 let mut url = self.url().clone();
65 url.path_segments_mut().ok()?.pop_if_empty().pop();
66 Some(url)
67 }
68}
69
70#[cfg(feature = "schemars")]
71impl schemars::JsonSchema for IndexUrl {
72 fn schema_name() -> Cow<'static, str> {
73 Cow::Borrowed("IndexUrl")
74 }
75
76 fn json_schema(_generator: &mut schemars::generate::SchemaGenerator) -> schemars::Schema {
77 schemars::json_schema!({
78 "type": "string",
79 "description": "The URL of an index to use for fetching packages (e.g., `https://pypi.org/simple`), or a local path."
80 })
81 }
82}
83
84impl IndexUrl {
85 #[inline]
86 fn inner(&self) -> &VerbatimUrl {
87 match self {
88 Self::Pypi(url) | Self::Url(url) | Self::Path(url) => url,
89 }
90 }
91
92 pub fn url(&self) -> &DisplaySafeUrl {
94 self.inner().raw()
95 }
96
97 pub fn into_url(self) -> DisplaySafeUrl {
99 self.inner().to_url()
100 }
101
102 pub fn without_credentials(&self) -> Cow<'_, DisplaySafeUrl> {
104 let url = self.url();
105 if url.username().is_empty() && url.password().is_none() {
106 Cow::Borrowed(url)
107 } else {
108 let mut url = url.clone();
109 let _ = url.set_username("");
110 let _ = url.set_password(None);
111 Cow::Owned(url)
112 }
113 }
114
115 pub fn warn_on_disambiguated_relative_path(&self) {
120 let Self::Path(verbatim_url) = &self else {
121 return;
122 };
123
124 if let Some(path) = verbatim_url.given() {
125 if !is_disambiguated_path(path) {
126 if cfg!(windows) {
127 warn_user!(
128 "Relative paths passed to `--index` or `--default-index` should be disambiguated from index names (use `.\\{path}` or `./{path}`). Support for ambiguous values will be removed in the future"
129 );
130 } else {
131 warn_user!(
132 "Relative paths passed to `--index` or `--default-index` should be disambiguated from index names (use `./{path}`). Support for ambiguous values will be removed in the future"
133 );
134 }
135 }
136 }
137 }
138}
139
140impl Display for IndexUrl {
141 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
142 Display::fmt(self.inner(), f)
143 }
144}
145
146impl Verbatim for IndexUrl {
147 fn verbatim(&self) -> Cow<'_, str> {
148 self.inner().verbatim()
149 }
150}
151
152fn is_disambiguated_path(path: &str) -> bool {
158 if cfg!(windows) {
159 if path.starts_with(".\\") || path.starts_with("..\\") || path.starts_with('/') {
160 return true;
161 }
162 }
163 if path.starts_with("./") || path.starts_with("../") || Path::new(path).is_absolute() {
164 return true;
165 }
166 if let Some((scheme, _)) = split_scheme(path) {
168 return Scheme::parse(scheme).is_some();
169 }
170 false
172}
173
174#[derive(Error, Debug)]
176pub enum IndexUrlError {
177 #[error(transparent)]
178 Io(#[from] std::io::Error),
179 #[error(transparent)]
180 Url(#[from] ParseError),
181 #[error(transparent)]
182 VerbatimUrl(#[from] VerbatimUrlError),
183}
184
185impl FromStr for IndexUrl {
186 type Err = IndexUrlError;
187
188 fn from_str(s: &str) -> Result<Self, Self::Err> {
189 Self::parse(s, None)
190 }
191}
192
193impl serde::ser::Serialize for IndexUrl {
194 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
195 where
196 S: serde::ser::Serializer,
197 {
198 self.inner().without_credentials().serialize(serializer)
199 }
200}
201
202impl<'de> serde::de::Deserialize<'de> for IndexUrl {
203 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
204 where
205 D: serde::de::Deserializer<'de>,
206 {
207 struct Visitor;
208
209 impl serde::de::Visitor<'_> for Visitor {
210 type Value = IndexUrl;
211
212 fn expecting(&self, f: &mut Formatter) -> std::fmt::Result {
213 f.write_str("a string")
214 }
215
216 fn visit_str<E: serde::de::Error>(self, v: &str) -> Result<Self::Value, E> {
217 IndexUrl::from_str(v).map_err(serde::de::Error::custom)
218 }
219 }
220
221 deserializer.deserialize_str(Visitor)
222 }
223}
224
225impl From<VerbatimUrl> for IndexUrl {
226 fn from(url: VerbatimUrl) -> Self {
227 if url.scheme() == "file" {
228 Self::Path(Arc::new(url))
229 } else if *url.raw() == *PYPI_URL {
230 Self::Pypi(Arc::new(url))
231 } else {
232 Self::Url(Arc::new(url))
233 }
234 }
235}
236
237impl From<IndexUrl> for DisplaySafeUrl {
238 fn from(index: IndexUrl) -> Self {
239 index.inner().to_url()
240 }
241}
242
243impl Deref for IndexUrl {
244 type Target = Url;
245
246 fn deref(&self) -> &Self::Target {
247 self.inner()
248 }
249}
250
251#[derive(Default, Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
256#[serde(rename_all = "kebab-case", deny_unknown_fields)]
257pub struct IndexLocations {
258 indexes: Vec<Index>,
259 flat_index: Vec<Index>,
260 no_index: bool,
261}
262
263impl IndexLocations {
264 pub fn new(indexes: Vec<Index>, flat_index: Vec<Index>, no_index: bool) -> Self {
266 Self {
267 indexes,
268 flat_index,
269 no_index,
270 }
271 }
272
273 #[must_use]
280 pub fn combine(self, indexes: Vec<Index>, flat_index: Vec<Index>, no_index: bool) -> Self {
281 Self {
282 indexes: self.indexes.into_iter().chain(indexes).collect(),
283 flat_index: self.flat_index.into_iter().chain(flat_index).collect(),
284 no_index: self.no_index || no_index,
285 }
286 }
287
288 pub fn is_none(&self) -> bool {
291 *self == Self::default()
292 }
293}
294
295fn is_same_index(a: &IndexUrl, b: &IndexUrl) -> bool {
297 RealmRef::from(&**b.url()) == RealmRef::from(&**a.url())
298 && CanonicalUrl::new(a.url()) == CanonicalUrl::new(b.url())
299}
300
301impl<'a> IndexLocations {
302 pub fn default_index(&'a self) -> Option<&'a Index> {
308 if self.no_index {
309 None
310 } else {
311 let mut seen = FxHashSet::default();
312 self.indexes
313 .iter()
314 .filter(move |index| index.name.as_ref().is_none_or(|name| seen.insert(name)))
315 .find(|index| index.default)
316 .or_else(|| Some(&DEFAULT_INDEX))
317 }
318 }
319
320 pub fn implicit_indexes(&'a self) -> impl Iterator<Item = &'a Index> + 'a {
324 if self.no_index {
325 Either::Left(std::iter::empty())
326 } else {
327 let mut seen = FxHashSet::default();
328 Either::Right(
329 self.indexes
330 .iter()
331 .filter(move |index| index.name.as_ref().is_none_or(|name| seen.insert(name)))
332 .filter(|index| !index.default && !index.explicit),
333 )
334 }
335 }
336
337 pub fn indexes(&'a self) -> impl Iterator<Item = &'a Index> + 'a {
346 self.implicit_indexes()
347 .chain(self.default_index())
348 .filter(|index| !index.explicit)
349 }
350
351 pub fn simple_indexes(&'a self) -> impl Iterator<Item = &'a Index> + 'a {
355 if self.no_index {
356 Either::Left(std::iter::empty())
357 } else {
358 let mut seen = FxHashSet::default();
359 Either::Right(
360 self.indexes
361 .iter()
362 .filter(move |index| index.name.as_ref().is_none_or(|name| seen.insert(name))),
363 )
364 }
365 }
366
367 pub fn flat_indexes(&'a self) -> impl Iterator<Item = &'a Index> + 'a {
369 self.flat_index.iter()
370 }
371
372 pub fn no_index(&self) -> bool {
374 self.no_index
375 }
376
377 pub fn index_urls(&'a self) -> IndexUrls {
379 IndexUrls {
380 indexes: self.indexes.clone(),
381 no_index: self.no_index,
382 }
383 }
384
385 pub fn allowed_indexes(&'a self) -> Vec<&'a Index> {
392 if self.no_index {
393 self.flat_index.iter().rev().collect()
394 } else {
395 let mut indexes = vec![];
396
397 let mut seen = FxHashSet::default();
398 let mut default = false;
399 for index in {
400 self.indexes
401 .iter()
402 .chain(self.flat_index.iter())
403 .filter(move |index| index.name.as_ref().is_none_or(|name| seen.insert(name)))
404 } {
405 if index.default {
406 if default {
407 continue;
408 }
409 default = true;
410 }
411 indexes.push(index);
412 }
413 if !default {
414 indexes.push(&*DEFAULT_INDEX);
415 }
416
417 indexes.reverse();
418 indexes
419 }
420 }
421
422 pub fn known_indexes(&'a self) -> impl Iterator<Item = &'a Index> {
431 if self.no_index {
432 Either::Left(self.flat_index.iter().rev())
433 } else {
434 Either::Right(
435 std::iter::once(&*DEFAULT_INDEX)
436 .chain(self.flat_index.iter().rev())
437 .chain(self.indexes.iter().rev()),
438 )
439 }
440 }
441
442 pub fn simple_api_cache_control_for(&self, url: &IndexUrl) -> Option<http::HeaderValue> {
444 for index in &self.indexes {
445 if is_same_index(index.url(), url) {
446 return index.simple_api_cache_control();
447 }
448 }
449 None
450 }
451
452 pub fn artifact_cache_control_for(&self, url: &IndexUrl) -> Option<http::HeaderValue> {
454 for index in &self.indexes {
455 if is_same_index(index.url(), url) {
456 return index.artifact_cache_control();
457 }
458 }
459 None
460 }
461
462 pub fn exclude_newer_for(&self, url: &IndexUrl) -> Option<&ExcludeNewerOverride> {
464 for index in &self.indexes {
465 if is_same_index(index.url(), url) {
466 return index.exclude_newer();
467 }
468 }
469 None
470 }
471}
472
473impl From<&IndexLocations> for uv_auth::Indexes {
474 fn from(index_locations: &IndexLocations) -> Self {
475 Self::from_indexes(index_locations.allowed_indexes().into_iter().map(|index| {
476 let mut url = index.url().url().clone();
477 url.set_username("").ok();
478 url.set_password(None).ok();
479 let mut root_url = index.url().root().unwrap_or_else(|| url.clone());
480 root_url.set_username("").ok();
481 root_url.set_password(None).ok();
482 uv_auth::Index {
483 url,
484 root_url,
485 auth_policy: index.authenticate,
486 }
487 }))
488 }
489}
490
491#[derive(Default, Debug, Clone, PartialEq, Eq)]
496pub struct IndexUrls {
497 indexes: Vec<Index>,
498 no_index: bool,
499}
500
501impl<'a> IndexUrls {
502 pub fn from_indexes(indexes: Vec<Index>) -> Self {
503 Self {
504 indexes,
505 no_index: false,
506 }
507 }
508
509 fn default_index(&'a self) -> Option<&'a Index> {
515 if self.no_index {
516 None
517 } else {
518 let mut seen = FxHashSet::default();
519 self.indexes
520 .iter()
521 .filter(move |index| index.name.as_ref().is_none_or(|name| seen.insert(name)))
522 .find(|index| index.default)
523 .or_else(|| Some(&DEFAULT_INDEX))
524 }
525 }
526
527 fn implicit_indexes(&'a self) -> impl Iterator<Item = &'a Index> + 'a {
531 if self.no_index {
532 Either::Left(std::iter::empty())
533 } else {
534 let mut seen = FxHashSet::default();
535 Either::Right(
536 self.indexes
537 .iter()
538 .filter(move |index| index.name.as_ref().is_none_or(|name| seen.insert(name)))
539 .filter(|index| !index.default && !index.explicit),
540 )
541 }
542 }
543
544 pub fn indexes(&'a self) -> impl Iterator<Item = &'a Index> + 'a {
552 let mut seen = FxHashSet::default();
553 self.implicit_indexes()
554 .chain(self.default_index())
555 .filter(|index| !index.explicit)
556 .filter(move |index| seen.insert(index.raw_url())) }
558
559 pub fn defined_indexes(&'a self) -> impl Iterator<Item = &'a Index> + 'a {
570 if self.no_index {
571 return Either::Left(std::iter::empty());
572 }
573
574 let mut seen = FxHashSet::default();
575 let (non_default, default) = self
576 .indexes
577 .iter()
578 .filter(move |index| {
579 if let Some(name) = &index.name {
580 seen.insert(name)
581 } else {
582 true
583 }
584 })
585 .partition::<Vec<_>, _>(|index| !index.default);
586
587 Either::Right(non_default.into_iter().chain(default))
588 }
589
590 pub fn no_index(&self) -> bool {
592 self.no_index
593 }
594
595 pub fn status_code_strategy_for(&self, url: &IndexUrl) -> IndexStatusCodeStrategy {
597 for index in &self.indexes {
598 if is_same_index(index.url(), url) {
599 return index.status_code_strategy();
600 }
601 }
602 IndexStatusCodeStrategy::Default
603 }
604
605 pub fn simple_api_cache_control_for(&self, url: &IndexUrl) -> Option<http::HeaderValue> {
607 for index in &self.indexes {
608 if is_same_index(index.url(), url) {
609 return index.simple_api_cache_control();
610 }
611 }
612 None
613 }
614
615 pub fn artifact_cache_control_for(&self, url: &IndexUrl) -> Option<http::HeaderValue> {
617 for index in &self.indexes {
618 if is_same_index(index.url(), url) {
619 return index.artifact_cache_control();
620 }
621 }
622 None
623 }
624}
625
626bitflags::bitflags! {
627 #[derive(Debug, Copy, Clone)]
628 struct Flags: u8 {
629 const NO_RANGE_REQUESTS = 1;
631 const UNAUTHORIZED = 1 << 2;
633 const FORBIDDEN = 1 << 1;
635 }
636}
637
638#[derive(Debug, Default, Clone)]
644pub struct IndexCapabilities(Arc<RwLock<FxHashMap<IndexUrl, Flags>>>);
645
646impl IndexCapabilities {
647 pub fn supports_range_requests(&self, index_url: &IndexUrl) -> bool {
649 !self
650 .0
651 .read()
652 .unwrap()
653 .get(index_url)
654 .is_some_and(|flags| flags.intersects(Flags::NO_RANGE_REQUESTS))
655 }
656
657 pub fn set_no_range_requests(&self, index_url: IndexUrl) {
659 self.0
660 .write()
661 .unwrap()
662 .entry(index_url)
663 .or_insert(Flags::empty())
664 .insert(Flags::NO_RANGE_REQUESTS);
665 }
666
667 pub fn unauthorized(&self, index_url: &IndexUrl) -> bool {
669 self.0
670 .read()
671 .unwrap()
672 .get(index_url)
673 .is_some_and(|flags| flags.intersects(Flags::UNAUTHORIZED))
674 }
675
676 pub fn set_unauthorized(&self, index_url: IndexUrl) {
678 self.0
679 .write()
680 .unwrap()
681 .entry(index_url)
682 .or_insert(Flags::empty())
683 .insert(Flags::UNAUTHORIZED);
684 }
685
686 pub fn forbidden(&self, index_url: &IndexUrl) -> bool {
688 self.0
689 .read()
690 .unwrap()
691 .get(index_url)
692 .is_some_and(|flags| flags.intersects(Flags::FORBIDDEN))
693 }
694
695 pub fn set_forbidden(&self, index_url: IndexUrl) {
697 self.0
698 .write()
699 .unwrap()
700 .entry(index_url)
701 .or_insert(Flags::empty())
702 .insert(Flags::FORBIDDEN);
703 }
704}
705
706#[cfg(test)]
707mod tests {
708 use super::*;
709 use crate::{IndexCacheControl, IndexFormat, IndexName};
710 use http::HeaderValue;
711
712 #[test]
713 fn test_index_url_parse_valid_paths() {
714 assert!(is_disambiguated_path("/absolute/path"));
716 assert!(is_disambiguated_path("./relative/path"));
718 assert!(is_disambiguated_path("../../relative/path"));
719 if cfg!(windows) {
720 assert!(is_disambiguated_path("C:/absolute/path"));
722 assert!(is_disambiguated_path(".\\relative\\path"));
724 assert!(is_disambiguated_path("..\\..\\relative\\path"));
725 }
726 }
727
728 #[test]
729 fn test_index_url_parse_ambiguous_paths() {
730 assert!(!is_disambiguated_path("index"));
732 assert!(!is_disambiguated_path("relative/path"));
734 }
735
736 #[test]
737 fn test_index_url_parse_with_schemes() {
738 assert!(is_disambiguated_path("file:///absolute/path"));
739 assert!(is_disambiguated_path("https://registry.com/simple/"));
740 assert!(is_disambiguated_path(
741 "git+https://github.com/example/repo.git"
742 ));
743 }
744
745 #[test]
746 fn test_cache_control_lookup() {
747 use std::str::FromStr;
748
749 use crate::IndexFormat;
750 use crate::index_name::IndexName;
751
752 let indexes = vec![
753 Index {
754 name: Some(IndexName::from_str("index1").unwrap()),
755 url: IndexUrl::from_str("https://index1.example.com/simple").unwrap(),
756 cache_control: Some(crate::IndexCacheControl {
757 api: Some(HeaderValue::from_static("max-age=300")),
758 files: Some(HeaderValue::from_static("max-age=1800")),
759 }),
760 explicit: false,
761 default: false,
762 origin: None,
763 format: IndexFormat::Simple,
764 publish_url: None,
765 authenticate: uv_auth::AuthPolicy::default(),
766 ignore_error_codes: None,
767 exclude_newer: None,
768 },
769 Index {
770 name: Some(IndexName::from_str("index2").unwrap()),
771 url: IndexUrl::from_str("https://index2.example.com/simple").unwrap(),
772 cache_control: None,
773 explicit: false,
774 default: false,
775 origin: None,
776 format: IndexFormat::Simple,
777 publish_url: None,
778 authenticate: uv_auth::AuthPolicy::default(),
779 ignore_error_codes: None,
780 exclude_newer: None,
781 },
782 ];
783
784 let index_urls = IndexUrls::from_indexes(indexes);
785
786 let url1 = IndexUrl::from_str("https://index1.example.com/simple").unwrap();
787 assert_eq!(
788 index_urls.simple_api_cache_control_for(&url1),
789 Some(HeaderValue::from_static("max-age=300"))
790 );
791 assert_eq!(
792 index_urls.artifact_cache_control_for(&url1),
793 Some(HeaderValue::from_static("max-age=1800"))
794 );
795
796 let url2 = IndexUrl::from_str("https://index2.example.com/simple").unwrap();
797 assert_eq!(index_urls.simple_api_cache_control_for(&url2), None);
798 assert_eq!(index_urls.artifact_cache_control_for(&url2), None);
799
800 let url3 = IndexUrl::from_str("https://index3.example.com/simple").unwrap();
801 assert_eq!(index_urls.simple_api_cache_control_for(&url3), None);
802 assert_eq!(index_urls.artifact_cache_control_for(&url3), None);
803 }
804
805 #[test]
806 fn test_pytorch_default_cache_control() {
807 let indexes = vec![Index {
809 name: Some(IndexName::from_str("pytorch").unwrap()),
810 url: IndexUrl::from_str("https://download.pytorch.org/whl/cu118").unwrap(),
811 cache_control: None, explicit: false,
813 default: false,
814 origin: None,
815 format: IndexFormat::Simple,
816 publish_url: None,
817 authenticate: uv_auth::AuthPolicy::default(),
818 ignore_error_codes: None,
819 exclude_newer: None,
820 }];
821
822 let index_urls = IndexUrls::from_indexes(indexes.clone());
823 let index_locations = IndexLocations::new(indexes, Vec::new(), false);
824
825 let pytorch_url = IndexUrl::from_str("https://download.pytorch.org/whl/cu118").unwrap();
826
827 assert_eq!(index_urls.simple_api_cache_control_for(&pytorch_url), None);
829 assert_eq!(
830 index_urls.artifact_cache_control_for(&pytorch_url),
831 Some(HeaderValue::from_static(
832 "max-age=365000000, immutable, public",
833 ))
834 );
835
836 assert_eq!(
838 index_locations.simple_api_cache_control_for(&pytorch_url),
839 None
840 );
841 assert_eq!(
842 index_locations.artifact_cache_control_for(&pytorch_url),
843 Some(HeaderValue::from_static(
844 "max-age=365000000, immutable, public",
845 ))
846 );
847 }
848
849 #[test]
850 fn test_pytorch_user_override_cache_control() {
851 let indexes = vec![Index {
853 name: Some(IndexName::from_str("pytorch").unwrap()),
854 url: IndexUrl::from_str("https://download.pytorch.org/whl/cu118").unwrap(),
855 cache_control: Some(IndexCacheControl {
856 api: Some(HeaderValue::from_static("no-cache")),
857 files: Some(HeaderValue::from_static("max-age=3600")),
858 }),
859 explicit: false,
860 default: false,
861 origin: None,
862 format: IndexFormat::Simple,
863 publish_url: None,
864 authenticate: uv_auth::AuthPolicy::default(),
865 ignore_error_codes: None,
866 exclude_newer: None,
867 }];
868
869 let index_urls = IndexUrls::from_indexes(indexes.clone());
870 let index_locations = IndexLocations::new(indexes, Vec::new(), false);
871
872 let pytorch_url = IndexUrl::from_str("https://download.pytorch.org/whl/cu118").unwrap();
873
874 assert_eq!(
876 index_urls.simple_api_cache_control_for(&pytorch_url),
877 Some(HeaderValue::from_static("no-cache"))
878 );
879 assert_eq!(
880 index_urls.artifact_cache_control_for(&pytorch_url),
881 Some(HeaderValue::from_static("max-age=3600"))
882 );
883
884 assert_eq!(
886 index_locations.simple_api_cache_control_for(&pytorch_url),
887 Some(HeaderValue::from_static("no-cache"))
888 );
889 assert_eq!(
890 index_locations.artifact_cache_control_for(&pytorch_url),
891 Some(HeaderValue::from_static("max-age=3600"))
892 );
893 }
894
895 #[test]
896 fn test_nvidia_default_cache_control() {
897 let indexes = vec![Index {
899 name: Some(IndexName::from_str("nvidia").unwrap()),
900 url: IndexUrl::from_str("https://pypi.nvidia.com").unwrap(),
901 cache_control: None, explicit: false,
903 default: false,
904 origin: None,
905 format: IndexFormat::Simple,
906 publish_url: None,
907 authenticate: uv_auth::AuthPolicy::default(),
908 ignore_error_codes: None,
909 exclude_newer: None,
910 }];
911
912 let index_urls = IndexUrls::from_indexes(indexes.clone());
913 let index_locations = IndexLocations::new(indexes, Vec::new(), false);
914
915 let nvidia_url = IndexUrl::from_str("https://pypi.nvidia.com").unwrap();
916
917 assert_eq!(index_urls.simple_api_cache_control_for(&nvidia_url), None);
919 assert_eq!(
920 index_urls.artifact_cache_control_for(&nvidia_url),
921 Some(HeaderValue::from_static(
922 "max-age=365000000, immutable, public",
923 ))
924 );
925
926 assert_eq!(
928 index_locations.simple_api_cache_control_for(&nvidia_url),
929 None
930 );
931 assert_eq!(
932 index_locations.artifact_cache_control_for(&nvidia_url),
933 Some(HeaderValue::from_static(
934 "max-age=365000000, immutable, public",
935 ))
936 );
937 }
938}