mirror of
https://github.com/denoland/deno.git
synced 2024-12-27 01:29:14 -05:00
7b33623b1d
Originally landed in
f6fd6619e7
.
Reverted in https://github.com/denoland/deno/pull/24574.
This reland contains a fix that sends "Accept: */*" header for calls made
from "FileFetcher". Absence of this header made downloading source code
from JSR broken. This is tested by ensuring this header is present in the
test server that servers JSR packages.
---------
Co-authored-by: Sean McArthur <sean@seanmonstar.com>
25 lines
740 B
Rust
25 lines
740 B
Rust
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
|
|
use deno_npm::npm_rc::RegistryConfig;
|
|
use http::header;
|
|
|
|
// TODO(bartlomieju): support more auth methods besides token and basic auth
|
|
pub fn maybe_auth_header_for_npm_registry(
|
|
registry_config: &RegistryConfig,
|
|
) -> Option<(header::HeaderName, header::HeaderValue)> {
|
|
if let Some(token) = registry_config.auth_token.as_ref() {
|
|
return Some((
|
|
header::AUTHORIZATION,
|
|
header::HeaderValue::from_str(&format!("Bearer {}", token)).unwrap(),
|
|
));
|
|
}
|
|
|
|
if let Some(auth) = registry_config.auth.as_ref() {
|
|
return Some((
|
|
header::AUTHORIZATION,
|
|
header::HeaderValue::from_str(&format!("Basic {}", auth)).unwrap(),
|
|
));
|
|
}
|
|
|
|
None
|
|
}
|