diff options
Diffstat (limited to 'mullvad-api/src')
| -rw-r--r-- | mullvad-api/src/lib.rs | 24 | ||||
| -rw-r--r-- | mullvad-api/src/rest.rs | 4 |
2 files changed, 12 insertions, 16 deletions
diff --git a/mullvad-api/src/lib.rs b/mullvad-api/src/lib.rs index 5427f51aad..c8765ec2b2 100644 --- a/mullvad-api/src/lib.rs +++ b/mullvad-api/src/lib.rs @@ -622,22 +622,14 @@ impl ApiProxy { } /// Check the availablility of `{APP_URL_PREFIX}/api-addrs`. - pub async fn api_addrs_available(&self) -> Result<(), rest::Error> { - let service = self.handle.service.clone(); - - rest::send_request( - &self.handle.factory, - service, - &format!("{APP_URL_PREFIX}/api-addrs"), - Method::HEAD, - None, - &[StatusCode::OK], - ) - .await?; + pub async fn api_addrs_available(&self) -> Result<bool, rest::Error> { + let request = self + .handle + .factory + .head(&format!("{APP_URL_PREFIX}/api-addrs"))? + .expected_status(&[StatusCode::OK]); - // NOTE: A HEAD request should *not* have a body: - // https://developer.mozilla.org/en-US/docs/web/http/methods/head - // I.e., no need to deserialize the result. - Ok(()) + let response = self.handle.service.request(request).await?; + Ok(response.status().is_success()) } } diff --git a/mullvad-api/src/rest.rs b/mullvad-api/src/rest.rs index 2484bec64b..559ddd4b4e 100644 --- a/mullvad-api/src/rest.rs +++ b/mullvad-api/src/rest.rs @@ -524,6 +524,10 @@ impl RequestFactory { self.request(path, Method::DELETE) } + pub fn head(&self, path: &str) -> Result<Request> { + self.request(path, Method::HEAD) + } + pub fn post_json<S: serde::Serialize>(&self, path: &str, body: &S) -> Result<Request> { self.json_request(Method::POST, path, body) } |
