Skip to content

Commit

Permalink
Make private prepare_request() methods infallible
Browse files Browse the repository at this point in the history
  • Loading branch information
ramosbugs committed Feb 21, 2024
1 parent 1759897 commit 8ef74ac
Showing 1 changed file with 15 additions and 27 deletions.
42 changes: 15 additions & 27 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1779,16 +1779,13 @@ where
self
}

fn prepare_request<RE>(self) -> Result<HttpRequest, RequestTokenError<RE, TE>>
where
RE: Error + 'static,
{
fn prepare_request(self) -> HttpRequest {
let mut params: Vec<(&str, &str)> = vec![("token", self.token.secret())];
if let Some(ref token_type_hint) = self.token_type_hint {
params.push(("token_type_hint", token_type_hint));
}

Ok(endpoint_request(
endpoint_request(
self.auth_type,
self.client_id,
self.client_secret,
Expand All @@ -1797,7 +1794,7 @@ where
None,
self.introspection_url.url(),
params,
))
)
}

///
Expand All @@ -1808,7 +1805,7 @@ where
F: FnOnce(HttpRequest) -> Result<HttpResponse, RE>,
RE: Error + 'static,
{
endpoint_response(http_client(self.prepare_request()?)?)
endpoint_response(http_client(self.prepare_request())?)
}

///
Expand All @@ -1823,8 +1820,7 @@ where
F: Future<Output = Result<HttpResponse, RE>>,
RE: Error + 'static,
{
let http_request = self.prepare_request()?;
let http_response = http_client(http_request).await?;
let http_response = http_client(self.prepare_request()).await?;
endpoint_response(http_response)
}
}
Expand Down Expand Up @@ -1879,16 +1875,13 @@ where
self
}

fn prepare_request<RE>(self) -> Result<HttpRequest, RequestTokenError<RE, TE>>
where
RE: Error + 'static,
{
fn prepare_request(self) -> HttpRequest {
let mut params: Vec<(&str, &str)> = vec![("token", self.token.secret())];
if let Some(type_hint) = self.token.type_hint() {
params.push(("token_type_hint", type_hint));
}

Ok(endpoint_request(
endpoint_request(
self.auth_type,
self.client_id,
self.client_secret,
Expand All @@ -1897,7 +1890,7 @@ where
None,
self.revocation_url.url(),
params,
))
)
}

///
Expand All @@ -1917,7 +1910,7 @@ where
// From https://tools.ietf.org/html/rfc7009#section-2.2:
// "The content of the response body is ignored by the client as all
// necessary information is conveyed in the response code."
endpoint_response_status_only(http_client(self.prepare_request()?)?)
endpoint_response_status_only(http_client(self.prepare_request())?)
}

///
Expand All @@ -1932,8 +1925,7 @@ where
F: Future<Output = Result<HttpResponse, RE>>,
RE: Error + 'static,
{
let http_request = self.prepare_request()?;
let http_response = http_client(http_request).await?;
let http_response = http_client(self.prepare_request()).await?;
endpoint_response_status_only(http_response)
}
}
Expand Down Expand Up @@ -2186,11 +2178,8 @@ where
self
}

fn prepare_request<RE>(self) -> Result<HttpRequest, RequestTokenError<RE, TE>>
where
RE: Error + 'static,
{
Ok(endpoint_request(
fn prepare_request(self) -> HttpRequest {
endpoint_request(
self.auth_type,
self.client_id,
self.client_secret,
Expand All @@ -2199,7 +2188,7 @@ where
Some(&self.scopes),
self.device_authorization_url.url(),
vec![],
))
)
}

///
Expand All @@ -2214,7 +2203,7 @@ where
RE: Error + 'static,
EF: ExtraDeviceAuthorizationFields,
{
endpoint_response(http_client(self.prepare_request()?)?)
endpoint_response(http_client(self.prepare_request())?)
}

///
Expand All @@ -2230,8 +2219,7 @@ where
RE: Error + 'static,
EF: ExtraDeviceAuthorizationFields,
{
let http_request = self.prepare_request()?;
let http_response = http_client(http_request).await?;
let http_response = http_client(self.prepare_request()).await?;
endpoint_response(http_response)
}
}
Expand Down

0 comments on commit 8ef74ac

Please sign in to comment.