mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 09:31:22 -05:00

This commit re-implements `ext/fetch` and all dependent crates using `hyper` and `hyper-util`, instead of `reqwest`. The reasoning is that we want to have greater control and access to low level `hyper` APIs when implementing `fetch` API as well as `node:http` module. --------- Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.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
|
|
}
|