Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow users to specify a prebuilt reqwest client #203

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
18 changes: 15 additions & 3 deletions src/v2/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub struct Config {
username: Option<String>,
password: Option<String>,
accept_invalid_certs: bool,
client: Option<reqwest::Client>,
}

impl Config {
Expand All @@ -21,6 +22,7 @@ impl Config {
user_agent: Some(crate::USER_AGENT.to_owned()),
username: None,
password: None,
client: None,
}
}

Expand Down Expand Up @@ -69,6 +71,12 @@ impl Config {
self
}

/// Specify a prebuilt reqwest http client to be used when interacting with the registry.
pub fn client(mut self, client: reqwest::Client) -> Self {
self.client = Some(client);
self
}

/// Return a `Client` to interact with a v2 registry.
pub fn build(self) -> Result<Client> {
let base = if self.insecure_registry {
Expand All @@ -89,9 +97,13 @@ impl Config {
p.unwrap_or_else(|| "".into()),
)),
};
let client = reqwest::ClientBuilder::new()
.danger_accept_invalid_certs(self.accept_invalid_certs)
.build()?;

let client = match self.client {
Some(client) => Ok(client),
None => reqwest::ClientBuilder::new()
.danger_accept_invalid_certs(self.accept_invalid_certs)
.build(),
}?;

let c = Client {
base_url: base,
Expand Down