Skip to content

Commit

Permalink
Share hostname string in RequestFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
dlon committed Oct 21, 2023
1 parent 990a3d6 commit 0be2712
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion mullvad-api/src/access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct AccountState {

impl AccessTokenStore {
pub(crate) fn new(service: RequestServiceHandle) -> Self {
let factory = rest::RequestFactory::new(API.host.clone(), None);
let factory = rest::RequestFactory::new(&API.host, None);
let (tx, rx) = mpsc::unbounded();
tokio::spawn(Self::service_requests(rx, service, factory));
Self { tx }
Expand Down
2 changes: 1 addition & 1 deletion mullvad-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ impl Runtime {
)
.await;
let token_store = access::AccessTokenStore::new(service.clone());
let factory = rest::RequestFactory::new(API.host.clone(), Some(token_store));
let factory = rest::RequestFactory::new(&API.host, Some(token_store));

rest::MullvadRestHandle::new(
service,
Expand Down
6 changes: 3 additions & 3 deletions mullvad-api/src/rest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,13 +467,13 @@ struct NewErrorResponse {

#[derive(Clone)]
pub struct RequestFactory {
hostname: String,
hostname: &'static str,
token_store: Option<AccessTokenStore>,
default_timeout: Duration,
}

impl RequestFactory {
pub fn new(hostname: String, token_store: Option<AccessTokenStore>) -> Self {
pub fn new(hostname: &'static str, token_store: Option<AccessTokenStore>) -> Self {
Self {
hostname,
token_store,
Expand Down Expand Up @@ -550,7 +550,7 @@ impl RequestFactory {
.uri(uri)
.header(header::USER_AGENT, HeaderValue::from_static(USER_AGENT))
.header(header::ACCEPT, HeaderValue::from_static("application/json"))
.header(header::HOST, self.hostname.clone());
.header(header::HOST, self.hostname.to_owned());

let result = request.body(hyper::Body::empty())?;
Ok(result)
Expand Down

0 comments on commit 0be2712

Please sign in to comment.