Skip to content

Commit

Permalink
touchups
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse committed Nov 3, 2023
1 parent a267540 commit 80cbc63
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
2 changes: 1 addition & 1 deletion crates/anvil/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ pub struct AnvilEvmArgs {
)]
pub fork_url: Option<ForkUrl>,

/// Pass headers to fork-url.
/// Headers to use for the rpc client, e.g. "User-Agent: test-agent"
///
/// See --fork-url.
#[clap(
Expand Down
9 changes: 3 additions & 6 deletions crates/common/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,19 +214,16 @@ impl ProviderBuilder {
} = self;
let url = url?;

let mut client_builder = RuntimeClientBuilder::new(
let client_builder = RuntimeClientBuilder::new(
url.clone(),
max_retry,
timeout_retry,
initial_backoff,
timeout,
compute_units_per_second,
)
.with_headers(headers);

if let Some(jwt) = jwt {
client_builder = client_builder.with_jwt(jwt);
}
.with_headers(headers)
.with_jwt(jwt);

let mut provider = Provider::new(client_builder.build());

Expand Down
18 changes: 7 additions & 11 deletions crates/common/src/runtime_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use reqwest::{
Url,
};
use serde::{de::DeserializeOwned, Serialize};
use std::{fmt::Debug, path::PathBuf, sync::Arc, time::Duration};
use std::{fmt::Debug, path::PathBuf, str::FromStr, sync::Arc, time::Duration};
use thiserror::Error;
use tokio::sync::RwLock;

Expand Down Expand Up @@ -146,15 +146,13 @@ impl RuntimeClient {
};

for header in self.headers.iter() {
let make_err = || RuntimeClientError::BadHeader(header.to_owned());
let make_err = || RuntimeClientError::BadHeader(header.to_string());

let parts: Vec<_> = header.split(':').map(|s| s.trim()).collect();
let key = parts.first().ok_or(make_err())?;
let val = parts.get(1).ok_or(make_err())?;
let (key, val) = header.split_once(':').ok_or_else(make_err)?;

headers.insert(
HeaderName::from_bytes(key.as_bytes()).map_err(|_| make_err())?,
HeaderValue::from_str(val).map_err(|_| make_err())?,
HeaderName::from_str(key.trim()).map_err(|_| make_err())?,
HeaderValue::from_str(val.trim()).map_err(|_| make_err())?,
);
}

Expand Down Expand Up @@ -224,17 +222,15 @@ impl RuntimeClientBuilder {
}

/// Set jwt to use with RuntimeClient
pub fn with_jwt(mut self, jwt: String) -> Self {
self.jwt = Some(jwt);

pub fn with_jwt(mut self, jwt: Option<String>) -> Self {
self.jwt = jwt;
self
}

/// Set http headers to use with RuntimeClient
/// Only works with http/https schemas
pub fn with_headers(mut self, headers: Vec<String>) -> Self {
self.headers = headers;

self
}

Expand Down

0 comments on commit 80cbc63

Please sign in to comment.