Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

feat: allow for Authorization header override with raw parameter #2432

Merged
merged 1 commit into from
May 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ethers-providers/src/rpc/transports/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ pub enum Authorization {
Basic(String),
/// Bearer Auth
Bearer(String),
/// If you need to override the Authorization header value
Raw(String),
}

impl Authorization {
Expand All @@ -251,13 +253,19 @@ impl Authorization {
pub fn bearer(token: impl Into<String>) -> Self {
Self::Bearer(token.into())
}

/// Override the Authorization header with your own string
pub fn raw(token: impl Into<String>) -> Self {
Self::Raw(token.into())
}
}

impl fmt::Display for Authorization {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Authorization::Basic(auth_secret) => write!(f, "Basic {auth_secret}"),
Authorization::Bearer(token) => write!(f, "Bearer {token}"),
Authorization::Raw(s) => write!(f, "{s}"),
}
}
}
Expand Down