summaryrefslogtreecommitdiffhomepage
path: root/mullvad-api/src
diff options
context:
space:
mode:
authorjonathan <jonathan@mullvad.net>2022-06-10 10:22:44 +0200
committerjonathan <jonathan@mullvad.net>2022-06-13 09:32:53 +0200
commit08b60d4ac77d5f58649930ccd0770e490b732864 (patch)
tree06c6940021736480858b8350edb04675d564da4b /mullvad-api/src
parent1065db6ec3e2e0485bd39a5730942071f5cdbaf4 (diff)
downloadmullvadvpn-08b60d4ac77d5f58649930ccd0770e490b732864.tar.xz
mullvadvpn-08b60d4ac77d5f58649930ccd0770e490b732864.zip
Perform a clippy --fix
This is a giant commit which performs only a clippy --fix. Auditing can happen in two ways, either by reading every line or by running a `cargo clippy --fix` on the previous commit and make sure that the result is the same.
Diffstat (limited to 'mullvad-api/src')
-rw-r--r--mullvad-api/src/address_cache.rs4
-rw-r--r--mullvad-api/src/https_client_with_sni.rs4
-rw-r--r--mullvad-api/src/lib.rs8
-rw-r--r--mullvad-api/src/relay_list.rs7
-rw-r--r--mullvad-api/src/rest.rs19
5 files changed, 18 insertions, 24 deletions
diff --git a/mullvad-api/src/address_cache.rs b/mullvad-api/src/address_cache.rs
index 3b6fcba074..92b7b6054f 100644
--- a/mullvad-api/src/address_cache.rs
+++ b/mullvad-api/src/address_cache.rs
@@ -49,7 +49,7 @@ impl AddressCache {
let address_cache = Self {
inner: Arc::new(Mutex::new(cache)),
- write_path: write_path.map(|cache| Arc::from(cache)),
+ write_path: write_path.map(Arc::from),
};
Ok(address_cache)
}
@@ -109,7 +109,7 @@ impl AddressCacheInner {
async fn read_address_file(path: &Path) -> Result<SocketAddr, Error> {
let mut file = fs::File::open(path)
.await
- .map_err(|error| Error::OpenAddressCache(error))?;
+ .map_err(Error::OpenAddressCache)?;
let mut address = String::new();
file.read_to_string(&mut address)
.await
diff --git a/mullvad-api/src/https_client_with_sni.rs b/mullvad-api/src/https_client_with_sni.rs
index 409492712e..cc7e2c1561 100644
--- a/mullvad-api/src/https_client_with_sni.rs
+++ b/mullvad-api/src/https_client_with_sni.rs
@@ -220,7 +220,7 @@ impl HttpsConnectorWithSni {
"invalid url, missing host",
))?;
let port = uri.port_u16().unwrap_or(443);
- if let Some(addr) = hostname.parse::<IpAddr>().ok() {
+ if let Ok(addr) = hostname.parse::<IpAddr>() {
return Ok(SocketAddr::new(addr, port));
}
@@ -234,7 +234,7 @@ impl HttpsConnectorWithSni {
//
let mut addrs = GaiResolver::new()
.call(
- Name::from_str(&hostname)
+ Name::from_str(hostname)
.map_err(|err| io::Error::new(io::ErrorKind::InvalidInput, err))?,
)
.await
diff --git a/mullvad-api/src/lib.rs b/mullvad-api/src/lib.rs
index 714718814b..17bbc5b3a2 100644
--- a/mullvad-api/src/lib.rs
+++ b/mullvad-api/src/lib.rs
@@ -116,12 +116,8 @@ impl ApiEndpoint {
log::debug!("Overriding API. Using {} at {}", api.host, api.addr);
}
}
- } else {
- if host_var.is_some() || address_var.is_some() {
- log::warn!(
- "MULLVAD_API_HOST and MULLVAD_API_ADDR are ignored in production builds"
- );
- }
+ } else if host_var.is_some() || address_var.is_some() {
+ log::warn!("MULLVAD_API_HOST and MULLVAD_API_ADDR are ignored in production builds");
}
api
}
diff --git a/mullvad-api/src/relay_list.rs b/mullvad-api/src/relay_list.rs
index 7f72767a1b..6bd4523652 100644
--- a/mullvad-api/src/relay_list.rs
+++ b/mullvad-api/src/relay_list.rs
@@ -35,7 +35,7 @@ impl RelayListProxy {
let service = self.handle.service.clone();
let request = self.handle.factory.request("app/v1/relays", Method::GET);
- let future = async move {
+ async move {
let mut request = request?;
request.set_timeout(RELAY_LIST_TIMEOUT);
@@ -67,8 +67,7 @@ impl RelayListProxy {
.await?
.into_relay_list(etag),
))
- };
- future
+ }
}
}
@@ -113,7 +112,7 @@ impl ServerRelayList {
relay_list::RelayList {
etag: etag.map(|mut tag| {
- if tag.starts_with("\"") {
+ if tag.starts_with('"') {
tag.insert_str(0, "W/");
}
tag
diff --git a/mullvad-api/src/rest.rs b/mullvad-api/src/rest.rs
index 84560e07ba..fbd2986b7c 100644
--- a/mullvad-api/src/rest.rs
+++ b/mullvad-api/src/rest.rs
@@ -151,10 +151,9 @@ impl<
socket_bypass_tx.clone(),
);
- proxy_config_provider
- .next()
- .await
- .map(|config| connector_handle.set_connection_mode(config));
+ if let Some(config) = proxy_config_provider.next().await {
+ connector_handle.set_connection_mode(config);
+ }
let (command_tx, command_rx) = mpsc::unbounded();
let client = Client::builder().build(connector);
@@ -293,14 +292,14 @@ pub struct RestRequest {
impl RestRequest {
/// Constructs a GET request with the given URI. Returns an error if the URI is not valid.
pub fn get(uri: &str) -> Result<Self> {
- let uri = hyper::Uri::from_str(&uri).map_err(Error::UriError)?;
+ let uri = hyper::Uri::from_str(uri).map_err(Error::UriError)?;
let mut builder = http::request::Builder::new()
.method(Method::GET)
.header(header::USER_AGENT, HeaderValue::from_static(USER_AGENT))
.header(header::ACCEPT, HeaderValue::from_static("application/json"));
if let Some(host) = uri.host() {
- builder = builder.header(header::HOST, HeaderValue::from_str(&host)?);
+ builder = builder.header(header::HOST, HeaderValue::from_str(host)?);
};
let request = builder
@@ -499,14 +498,14 @@ pub fn send_request(
async move {
let mut request = request?;
if let Some((store, account)) = &auth {
- let access_token = store.get_token(&account).await?;
+ let access_token = store.get_token(account).await?;
request.set_auth(Some(access_token))?;
}
let response = service.request(request).await?;
let result = parse_rest_response(response, expected_statuses).await;
if let Some((store, account)) = &auth {
- store.check_response(&account, &result);
+ store.check_response(account, &result);
}
result
@@ -526,14 +525,14 @@ pub fn send_json_request<B: serde::Serialize>(
async move {
let mut request = request?;
if let Some((store, account)) = &auth {
- let access_token = store.get_token(&account).await?;
+ let access_token = store.get_token(account).await?;
request.set_auth(Some(access_token))?;
}
let response = service.request(request).await?;
let result = parse_rest_response(response, expected_statuses).await;
if let Some((store, account)) = &auth {
- store.check_response(&account, &result);
+ store.check_response(account, &result);
}
result