about summary refs log tree commit diff
path: root/src/micropub/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/micropub/mod.rs')
-rw-r--r--src/micropub/mod.rs34
1 files changed, 22 insertions, 12 deletions
diff --git a/src/micropub/mod.rs b/src/micropub/mod.rs
index fc5dd10..63b81c5 100644
--- a/src/micropub/mod.rs
+++ b/src/micropub/mod.rs
@@ -5,12 +5,12 @@ use std::sync::Arc;
 use crate::database::{MicropubChannel, Storage, StorageError};
 use crate::indieauth::backend::AuthBackend;
 use crate::indieauth::User;
-use crate::media::storage::MediaStore;
 use crate::micropub::util::form_to_mf2_json;
-use axum::extract::{BodyStream, FromRef, Host, Query, State};
-use axum::headers::ContentType;
+use axum::extract::{FromRef, Host, Query, State};
+use axum::body::Body as BodyStream;
+use axum_extra::headers::ContentType;
 use axum::response::{IntoResponse, Response};
-use axum::TypedHeader;
+use axum_extra::TypedHeader;
 use axum::http::StatusCode;
 use serde::{Deserialize, Serialize};
 use serde_json::json;
@@ -136,10 +136,10 @@ async fn background_processing<D: 'static + Storage>(
                 // TODO parse link headers
                 let links = response
                     .headers()
-                    .get_all(hyper::http::header::LINK)
+                    .get_all(reqwest::header::LINK)
                     .iter()
                     .cloned()
-                    .collect::<Vec<hyper::http::HeaderValue>>();
+                    .collect::<Vec<reqwest::header::HeaderValue>>();
                 let html = response.text().await;
                 if html.is_err() {
                     return None;
@@ -330,9 +330,9 @@ pub(crate) async fn _post<D: 'static + Storage>(
         IntoResponse::into_response((StatusCode::ACCEPTED, [("Location", uid.as_str())]));
 
     #[cfg(not(tokio_unstable))]
-    jobset.lock().await.spawn(background_processing(db, mf2, http));
+    let _ = jobset.lock().await.spawn(background_processing(db, mf2, http));
     #[cfg(tokio_unstable)]
-    jobset.lock().await.build_task()
+    let _ = jobset.lock().await.build_task()
         .name(format!("Kittybox background processing for post {}", uid.as_str()).as_str())
         .spawn(background_processing(db, mf2, http));
 
@@ -459,7 +459,7 @@ enum PostBody {
 
 #[tracing::instrument]
 async fn dispatch_body(
-    mut body: BodyStream,
+    body: BodyStream,
     content_type: ContentType,
 ) -> Result<PostBody, MicropubError> {
     let body: Vec<u8> = {
@@ -467,6 +467,7 @@ async fn dispatch_body(
         use tokio_stream::StreamExt;
         let mut buf = Vec::default();
 
+        let mut body = body.into_data_stream();
         while let Some(chunk) = body.next().await {
             buf.extend_from_slice(&chunk.unwrap())
         }
@@ -673,7 +674,7 @@ where
 {
     axum::routing::get(query::<S, A>)
         .post(post::<S, A>)
-        .layer::<_, _, std::convert::Infallible>(tower_http::cors::CorsLayer::new()
+        .layer::<_, _>(tower_http::cors::CorsLayer::new()
                .allow_methods([
                    axum::http::Method::GET,
                    axum::http::Method::POST,
@@ -704,7 +705,8 @@ mod tests {
     use std::sync::Arc;
 
     use crate::{database::Storage, micropub::MicropubError};
-    use hyper::body::HttpBody;
+    use bytes::Bytes;
+    use futures::StreamExt;
     use serde_json::json;
     use tokio::sync::Mutex;
 
@@ -861,7 +863,15 @@ mod tests {
         .await;
 
         assert_eq!(res.status(), 401);
-        let body = res.body_mut().data().await.unwrap().unwrap();
+        let body = res
+            .into_body()
+            .into_data_stream()
+            .collect::<Vec<Result<Bytes, axum::Error>>>()
+            .await
+            .into_iter()
+            .map(Result::unwrap)
+            .by_ref()
+            .fold(Vec::new(), |mut a, i| { a.extend(i); a});
         let json: MicropubError = serde_json::from_slice(&body as &[u8]).unwrap();
         assert_eq!(json.error, super::ErrorType::NotAuthorized);
     }