about summary refs log tree commit diff
path: root/src/indieauth
diff options
context:
space:
mode:
authorVika <vika@fireburn.ru>2024-08-26 15:22:29 +0300
committerVika <vika@fireburn.ru>2024-08-26 15:23:22 +0300
commit31a0bdad439a4575c1686f690e9e72bd44dde472 (patch)
tree6b8c9132c19445d997bd75964604b069ffbd573f /src/indieauth
parentc79e950ca22c7a957c11e510700664327b042115 (diff)
downloadkittybox-31a0bdad439a4575c1686f690e9e72bd44dde472.tar.zst
Add HTTP fetcher cache
It just does its thing in the background, potentially speeding up
things. Maybe I could also use the underlying in-memory cache
implementation (Moka) to speed up my database. I heard crates.io got
some good results from that.
Diffstat (limited to 'src/indieauth')
-rw-r--r--src/indieauth/mod.rs9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/indieauth/mod.rs b/src/indieauth/mod.rs
index 322a0e2..b3db77f 100644
--- a/src/indieauth/mod.rs
+++ b/src/indieauth/mod.rs
@@ -131,7 +131,7 @@ async fn authorization_endpoint_get<A: AuthBackend, D: Storage + 'static>(
     Host(host): Host,
     Query(request): Query<AuthorizationRequest>,
     State(db): State<D>,
-    State(http): State<reqwest::Client>,
+    State(http): State<reqwest_middleware::ClientWithMiddleware>,
     State(auth): State<A>
 ) -> Response {
     let me: url::Url = format!("https://{host}/").parse().unwrap();
@@ -148,7 +148,10 @@ async fn authorization_endpoint_get<A: AuthBackend, D: Storage + 'static>(
         tracing::debug!("Sending request to {} to fetch metadata", request.client_id);
         let metadata_request = http.get(request.client_id.clone())
             .header("Accept", "application/json, text/html");
-        match metadata_request.send().await.and_then(|res| res.error_for_status()) {
+        match metadata_request.send().await
+            .and_then(|res| res.error_for_status()
+                .map_err(reqwest_middleware::Error::Reqwest))
+        {
             Ok(response) if response.headers().typed_get::<ContentType>().to_owned().map(mime::Mime::from).map(|m| m.type_() == "text" && m.subtype() == "html").unwrap_or(false) => {
                 let url = response.url().clone();
                 let text = response.text().await.unwrap();
@@ -847,7 +850,7 @@ pub fn router<St, A, S>() -> axum::Router<St>
 where
     S: Storage + FromRef<St> + 'static,
     A: AuthBackend + FromRef<St>,
-    reqwest::Client: FromRef<St>,
+    reqwest_middleware::ClientWithMiddleware: FromRef<St>,
     St: Clone + Send + Sync + 'static
 {
     use axum::routing::{Router, get, post};