@@ -24,6 +24,7 @@ type RemoteFileResult = Result<(RemoteFileText, RemoteFileHeaders), String>;
2424pub struct InMemoryLoader {
2525 pub sys : InMemorySys ,
2626 remote_files : HashMap < ModuleSpecifier , RemoteFileResult > ,
27+ remote_redirects : HashMap < ModuleSpecifier , String > ,
2728}
2829
2930impl InMemoryLoader {
@@ -38,6 +39,7 @@ impl InMemoryLoader {
3839 Self {
3940 sys,
4041 remote_files : HashMap :: new ( ) ,
42+ remote_redirects : HashMap :: new ( ) ,
4143 }
4244 }
4345
@@ -87,6 +89,18 @@ impl InMemoryLoader {
8789 self
8890 }
8991
92+ pub fn add_remote_redirect (
93+ & mut self ,
94+ specifier : impl AsRef < str > ,
95+ location : impl AsRef < str > ,
96+ ) -> & mut Self {
97+ self . remote_redirects . insert (
98+ ModuleSpecifier :: parse ( specifier. as_ref ( ) ) . unwrap ( ) ,
99+ location. as_ref ( ) . to_string ( ) ,
100+ ) ;
101+ self
102+ }
103+
90104 pub fn add_remote_file_with_error (
91105 & mut self ,
92106 specifier : impl AsRef < str > ,
@@ -118,6 +132,12 @@ impl deno_cache_dir::file_fetcher::HttpClient for InMemoryLoader {
118132 specifier : & ModuleSpecifier ,
119133 _headers : HeaderMap ,
120134 ) -> Result < SendResponse , SendError > {
135+ if let Some ( location) = self . remote_redirects . get ( specifier) {
136+ return Ok ( SendResponse :: Redirect ( to_headers ( HashMap :: from ( [ (
137+ "location" . to_string ( ) ,
138+ location. clone ( ) ,
139+ ) ] ) ) ) ) ;
140+ }
121141 let result = self
122142 . remote_files
123143 . get ( & specifier)
0 commit comments