Skip to content

Commit faa738c

Browse files
committed
Don't bypass the cache when retrieving metadata
1 parent 0f2124e commit faa738c

File tree

4 files changed

+46
-21
lines changed

4 files changed

+46
-21
lines changed

packages/zpm/src/commands/debug/bench.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,13 @@ impl BenchRun {
174174
let hyperfine_args = vec![
175175
"--min-runs=30".to_string(),
176176
"--warmup=4".to_string(),
177-
"--show-output".to_string(),
178177
format!("--export-json={bench_json_string}"),
179178
format!("--prepare={current_exec_string} debug bench {mode_string} --cleanup"),
180179
format!("{current_exec_string} debug bench {mode_string} --iteration"),
181180
];
182181

183182
ScriptEnvironment::new()?
183+
.enable_shell_forwarding()
184184
.with_cwd(temp_directory)
185185
.run_exec("hyperfine", hyperfine_args)
186186
.await?

packages/zpm/src/fetchers/npm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub async fn fetch_locator<'a>(context: &InstallContext<'a>, locator: &Locator,
6565

6666
let cached_blob = package_cache.ensure_blob(locator.clone(), ".zip", || async {
6767
let bytes
68-
= http_npm::get(&http_npm::NpmHttpParams {
68+
= http_npm::get_raw(&http_npm::NpmHttpParams {
6969
http_client: &project.http_client,
7070
registry: &registry_base,
7171
path: &registry_path,

packages/zpm/src/http.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ impl HttpClient {
363363
/// Performs a cached GET request. If the URL has already been fetched,
364364
/// returns the cached response bytes. Concurrent requests to the same URL
365365
/// will wait for the first request to complete and share the result.
366-
pub async fn cached_get(&self, url: impl AsRef<str>) -> Result<Bytes, Error> {
366+
pub async fn cached_get(&self, url: impl AsRef<str>, headers: Option<HeaderMap>) -> Result<Bytes, Error> {
367367
let url_str
368368
= url.as_ref().to_string();
369369

@@ -374,7 +374,8 @@ impl HttpClient {
374374

375375
let result = cell.get_or_init(|| async {
376376
let request
377-
= self.get(&url_str)?;
377+
= self.get(&url_str)?
378+
.add_headers(headers);
378379

379380
let result
380381
= request.send().await?;

packages/zpm/src/http_npm.rs

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -274,24 +274,48 @@ pub async fn get(params: &NpmHttpParams<'_>) -> Result<Bytes, Error> {
274274
let url
275275
= format!("{}{}", params.registry, params.path);
276276

277-
let bytes = match params.authorization {
278-
Some(authorization) => {
279-
params.http_client.get(&url)?
280-
.header("accept", Some("application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*"))
281-
.header("authorization", Some(authorization))
282-
.send().await?
283-
.error_for_status()?
284-
.bytes().await?
285-
},
277+
let mut headers
278+
= http::HeaderMap::new();
279+
280+
headers.insert(
281+
http::header::ACCEPT,
282+
http::HeaderValue::from_static("application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*"),
283+
);
284+
285+
if let Some(authorization) = params.authorization {
286+
headers.insert(
287+
http::header::AUTHORIZATION,
288+
http::HeaderValue::from_str(authorization).unwrap(),
289+
);
290+
}
286291

287-
None => {
288-
params.http_client.get(&url)?
289-
.header("accept", Some("application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*"))
290-
.send().await?
291-
.error_for_status()?
292-
.bytes().await?
293-
},
294-
};
292+
let bytes
293+
= params.http_client.cached_get(&url, Some(headers)).await?;
294+
295+
Ok(bytes)
296+
}
297+
298+
pub async fn get_raw(params: &NpmHttpParams<'_>) -> Result<Bytes, Error> {
299+
let url
300+
= format!("{}{}", params.registry, params.path);
301+
302+
let mut headers
303+
= http::HeaderMap::new();
304+
305+
if let Some(authorization) = params.authorization {
306+
headers.insert(
307+
http::header::AUTHORIZATION,
308+
http::HeaderValue::from_str(authorization).unwrap(),
309+
);
310+
}
311+
312+
let bytes
313+
= params.http_client.get(&url)?
314+
.add_headers(Some(headers))
315+
.send()
316+
.await?
317+
.error_for_status()?
318+
.bytes().await?;
295319

296320
Ok(bytes)
297321
}

0 commit comments

Comments
 (0)