diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/indieauth.rs | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/src/indieauth.rs b/src/indieauth.rs index 8f3ef8f..bcc8bbe 100644 --- a/src/indieauth.rs +++ b/src/indieauth.rs @@ -90,10 +90,8 @@ impl User { } } -// TODO: consider making this a generic -type HttpClient = hyper::Client<hyper_rustls::HttpsConnector<hyper::client::HttpConnector<hyper::client::connect::dns::GaiResolver>>, hyper::Body>; - -pub fn require_token(token_endpoint: String, http: HttpClient) -> impl Filter<Extract = (User,), Error = Rejection> { +pub fn require_token<T>(token_endpoint: String, http: hyper::Client<T, hyper::Body>) -> impl Filter<Extract = (User,), Error = Rejection> + Clone +where T: hyper::client::connect::Connect + Clone + Send + Sync + 'static { // It might be OK to panic here, because we're still inside the initialisation sequence for now. // Proper error handling on the top of this should be used though. let token_endpoint_uri = hyper::Uri::try_from(&token_endpoint) @@ -101,7 +99,6 @@ pub fn require_token(token_endpoint: String, http: HttpClient) -> impl Filter<Ex warp::any() .map(move || token_endpoint_uri.clone()) .and(warp::any().map(move || http.clone())) - .and_then(|token_endpoint, http: HttpClient, token| async move { .and(warp::header::<String>("Authorization").recover(|err: Rejection| async move { if err.find::<MissingHeader>().is_some() { Err(IndieAuthError { @@ -113,6 +110,7 @@ pub fn require_token(token_endpoint: String, http: HttpClient) -> impl Filter<Ex Err(err) } }).unify()) + .and_then(|token_endpoint, http: hyper::Client<T, hyper::Body>, token| async move { let request = hyper::Request::builder() .method(hyper::Method::GET) .uri(token_endpoint) @@ -197,7 +195,7 @@ pub fn require_token(token_endpoint: String, http: HttpClient) -> impl Filter<Ex #[cfg(test)] mod tests { - use super::{HttpClient, User, IndieAuthError, require_token}; + use super::{User, IndieAuthError, require_token}; use httpmock::prelude::*; #[test] @@ -212,7 +210,7 @@ mod tests { assert!(!user.check_scope("delete")); } - fn get_http_client() -> HttpClient { + fn get_http_client() -> hyper::Client<impl hyper::client::connect::Connect + Clone + Send + Sync + 'static, hyper::Body> { let builder = hyper::Client::builder(); let https = hyper_rustls::HttpsConnectorBuilder::new() .with_webpki_roots() |