From d10710326da703f69eaa06723dc66e330fd32745 Mon Sep 17 00:00:00 2001 From: Vika Date: Wed, 1 Jan 2025 23:17:56 +0300 Subject: axum: 0.7.9 → 0.8.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some breaking changes. For better or for worse. The optional extractor breaking change is a double-edged sword, since not all extractors can be used with `Option` now, and you have to use `Result` even when you want to ignore an error coming from an extractor, such as `Query`. However, this allows catching errors on authorization extractors even in places where authorization is optional. Change-Id: I35f809d3adf27dbef0e7ee93dc1a7af178b7d014 --- src/micropub/mod.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/micropub/mod.rs') diff --git a/src/micropub/mod.rs b/src/micropub/mod.rs index 621d4f9..719fbf0 100644 --- a/src/micropub/mod.rs +++ b/src/micropub/mod.rs @@ -6,8 +6,9 @@ use crate::database::{MicropubChannel, Storage, StorageError}; use crate::indieauth::backend::AuthBackend; use crate::indieauth::User; use crate::micropub::util::form_to_mf2_json; -use axum::extract::{FromRef, Host, Query, State}; +use axum::extract::{FromRef, Query, State}; use axum::body::Body as BodyStream; +use axum_extra::extract::Host; use axum_extra::headers::ContentType; use axum::response::{IntoResponse, Response}; use axum_extra::TypedHeader; @@ -603,13 +604,13 @@ pub(crate) async fn post( #[tracing::instrument(skip(db))] pub(crate) async fn query( State(db): State, - query: Option>, + query: Result, as axum::extract::FromRequestParts<()>>::Rejection>, Host(host): Host, user: User, ) -> axum::response::Response { // We handle the invalid query case manually to return a // MicropubError instead of HTTP 422 - let query = if let Some(Query(query)) = query { + let query = if let Ok(Query(query)) = query { query } else { return MicropubError::from_static( @@ -771,7 +772,8 @@ mod tests { use super::FetchedPostContext; use kittybox_indieauth::{Scopes, Scope, TokenData}; - use axum::extract::{Host, State}; + use axum::extract::State; + use axum_extra::extract::Host; #[test] fn test_populate_reply_context() { @@ -927,7 +929,7 @@ mod tests { async fn test_query_foreign_url() { let res = super::query( State(crate::database::MemoryStorage::default()), - Some(axum::extract::Query(super::MicropubQuery::source( + Ok(axum::extract::Query(super::MicropubQuery::source( "https://aaronparecki.com/feeds/main", ))), Host("aaronparecki.com".to_owned()), -- cgit 1.4.1