From a6b0c696bb28ab991b5cd71369f868c49773abd2 Mon Sep 17 00:00:00 2001 From: Vika Date: Mon, 21 Feb 2022 21:46:25 +0300 Subject: Make the HTTP client a generic This adds the ability to use mocks that don't actually touch the network and alternative transports such as using OpenSSL instead of rustls (but rustls is still superior). --- src/indieauth.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'src') 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::Body>; - -pub fn require_token(token_endpoint: String, http: HttpClient) -> impl Filter { +pub fn require_token(token_endpoint: String, http: hyper::Client) -> impl Filter + 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("Authorization").recover(|err: Rejection| async move { if err.find::().is_some() { Err(IndieAuthError { @@ -113,6 +110,7 @@ pub fn require_token(token_endpoint: String, http: HttpClient) -> impl Filter, 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 HttpClient { + fn get_http_client() -> hyper::Client { let builder = hyper::Client::builder(); let https = hyper_rustls::HttpsConnectorBuilder::new() .with_webpki_roots() -- cgit 1.4.1