Skip to content

Commit

Permalink
[v0.36.0] fix: Manually encode Authorization header for eventsource_c…
Browse files Browse the repository at this point in the history
…lient (#2285)

## Linked Issues/PRs
<!-- List of related issues/PRs -->
Copy of #2284 (targets `master`)
## Description
See #2284.

---------

Co-authored-by: Green Baneling <XgreenX9999@gmail.com>
  • Loading branch information
Br1ght0ne and xgreenx authored Oct 4, 2024
1 parent f1973cb commit fa1379c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions crates/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ description = "Tx client and schema specification."

[dependencies]
anyhow = { workspace = true }
base64 = { version = "0.22.1", optional = true }
cynic = { workspace = true }
derive_more = { workspace = true }
eventsource-client = { version = "0.12.2", optional = true }
eventsource-client = { version = "0.13.0", optional = true }
fuel-core-types = { workspace = true, features = ["alloc", "serde"] }
futures = { workspace = true, optional = true }
hex = { workspace = true }
Expand Down Expand Up @@ -46,4 +47,4 @@ serde_json = { version = "1.0", features = ["raw_value"] }
std = ["fuel-core-types/std"]
default = ["subscriptions", "std"]
test-helpers = []
subscriptions = ["eventsource-client", "futures", "hyper-rustls"]
subscriptions = ["base64", "eventsource-client", "futures", "hyper-rustls"]
18 changes: 18 additions & 0 deletions crates/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ use crate::client::{
};
use anyhow::Context;
#[cfg(feature = "subscriptions")]
use base64::prelude::{
Engine as _,
BASE64_STANDARD,
};
#[cfg(feature = "subscriptions")]
use cynic::StreamingOperation;
use cynic::{
http::ReqwestExt,
Expand Down Expand Up @@ -270,6 +275,19 @@ impl FuelClient {
format!("Failed to add header to client {e:?}"),
)
})?;
if let Some(password) = url.password() {
let username = url.username();
let credentials = format!("{}:{}", username, password);
let authorization = format!("Basic {}", BASE64_STANDARD.encode(credentials));
client_builder = client_builder
.header("Authorization", &authorization)
.map_err(|e| {
io::Error::new(
io::ErrorKind::Other,
format!("Failed to add header to client {e:?}"),
)
})?;
}

if let Some(value) = self.cookie.deref().cookies(&self.url) {
let value = value.to_str().map_err(|e| {
Expand Down

0 comments on commit fa1379c

Please sign in to comment.