don't
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor(knot): re-organize axum extractors

Signed-off-by: tjh <x@tjh.dev>

tjh b62483ca cfe13e59

+62 -65
+3
crates/gordian-knot/src/extract.rs
··· 1 + pub mod git_protocol; 2 + pub mod if_none_match; 3 + pub mod request_id;
+47
crates/gordian-knot/src/extract/request_id.rs
··· 1 + use std::ffi::OsStr; 2 + 3 + use axum::extract::OptionalFromRequestParts; 4 + use axum::http::StatusCode; 5 + use axum::response::IntoResponse; 6 + 7 + pub struct RequestId(pub String); 8 + 9 + impl<S: Sync> OptionalFromRequestParts<S> for RequestId { 10 + type Rejection = RequestIdRejection; 11 + 12 + async fn from_request_parts( 13 + parts: &mut axum::http::request::Parts, 14 + _: &S, 15 + ) -> Result<Option<Self>, Self::Rejection> { 16 + parts 17 + .extensions 18 + .get::<tower_http::request_id::RequestId>() 19 + .map(|request_id| { 20 + request_id 21 + .header_value() 22 + .to_str() 23 + .map(|s| Self(s.to_owned())) 24 + .map_err(|_| RequestIdRejection) 25 + }) 26 + .transpose() 27 + } 28 + } 29 + 30 + #[derive(Debug)] 31 + pub struct RequestIdRejection; 32 + 33 + impl IntoResponse for RequestIdRejection { 34 + fn into_response(self) -> axum::response::Response { 35 + ( 36 + StatusCode::BAD_REQUEST, 37 + "invalid bytes is request id header", 38 + ) 39 + .into_response() 40 + } 41 + } 42 + 43 + impl AsRef<OsStr> for RequestId { 44 + fn as_ref(&self) -> &OsStr { 45 + OsStr::new(&self.0) 46 + } 47 + }
-53
crates/gordian-knot/src/extractors.rs crates/gordian-knot/src/extract/if_none_match.rs
··· 1 - mod git_protocol; 2 1 use core::fmt; 3 2 4 3 use axum::extract::FromRequestParts; ··· 5 6 use axum::http::HeaderMap; 6 7 use axum::http::StatusCode; 7 8 use axum::response::IntoResponse; 8 - pub use git_protocol::GitProtocol; 9 - pub use git_protocol::GitProtocolRejection; 10 9 use reqwest::header::IF_NONE_MATCH; 11 - 12 - pub mod request_id { 13 - use std::ffi::OsStr; 14 - 15 - use axum::extract::OptionalFromRequestParts; 16 - use axum::http::StatusCode; 17 - use axum::response::IntoResponse; 18 - 19 - pub struct RequestId(pub String); 20 - 21 - impl<S: Sync> OptionalFromRequestParts<S> for RequestId { 22 - type Rejection = RequestIdRejection; 23 - 24 - async fn from_request_parts( 25 - parts: &mut axum::http::request::Parts, 26 - _: &S, 27 - ) -> Result<Option<Self>, Self::Rejection> { 28 - parts 29 - .extensions 30 - .get::<tower_http::request_id::RequestId>() 31 - .map(|request_id| { 32 - request_id 33 - .header_value() 34 - .to_str() 35 - .map(|s| Self(s.to_owned())) 36 - .map_err(|_| RequestIdRejection) 37 - }) 38 - .transpose() 39 - } 40 - } 41 - 42 - #[derive(Debug)] 43 - pub struct RequestIdRejection; 44 - 45 - impl IntoResponse for RequestIdRejection { 46 - fn into_response(self) -> axum::response::Response { 47 - ( 48 - StatusCode::BAD_REQUEST, 49 - "invalid bytes is request id header", 50 - ) 51 - .into_response() 52 - } 53 - } 54 - 55 - impl AsRef<OsStr> for RequestId { 56 - fn as_ref(&self) -> &OsStr { 57 - OsStr::new(&self.0) 58 - } 59 - } 60 - } 61 10 62 11 #[derive(Debug, PartialEq, Eq)] 63 12 pub enum ETag {
+2 -2
crates/gordian-knot/src/extractors/git_protocol.rs crates/gordian-knot/src/extract/git_protocol.rs
··· 15 15 /// ```rust,no_run 16 16 /// # use axum::Router; 17 17 /// # use axum::routing::get; 18 - /// # use gordian_knot::extractors::GitProtocol; 18 + /// # use gordian_knot::extract::git_protocol::GitProtocol; 19 19 /// async fn handler(git_protocol: GitProtocol) { 20 20 /// // ... 21 21 /// } ··· 32 32 /// ```rust,no_run 33 33 /// # use axum::Router; 34 34 /// # use axum::routing::get; 35 - /// # use gordian_knot::extractors::GitProtocol; 35 + /// # use gordian_knot::extract::git_protocol::GitProtocol; 36 36 /// async fn handler(git_protocol: Option<GitProtocol>) { 37 37 /// // ... 38 38 /// }
+1 -1
crates/gordian-knot/src/lib.rs
··· 1 1 pub mod command; 2 - pub mod extractors; 2 + pub mod extract; 3 3 pub mod model; 4 4 pub mod nsid; 5 5 pub mod private;
+2 -2
crates/gordian-knot/src/public/git.rs
··· 15 15 use tokio::io::AsyncWrite; 16 16 use tokio::io::AsyncWriteExt as _; 17 17 18 - use crate::extractors::GitProtocol; 19 - use crate::extractors::request_id::RequestId; 18 + use crate::extract::git_protocol::GitProtocol; 19 + use crate::extract::request_id::RequestId; 20 20 use crate::model::Knot; 21 21 22 22 pub fn router() -> axum::Router<Knot> {
+2 -2
crates/gordian-knot/src/public/git/receive_pack.rs
··· 14 14 15 15 use crate::command::ChildExt as _; 16 16 use crate::command::CommandExt as _; 17 - use crate::extractors::GitProtocol; 18 - use crate::extractors::request_id::RequestId; 17 + use crate::extract::git_protocol::GitProtocol; 18 + use crate::extract::request_id::RequestId; 19 19 use crate::model::Knot; 20 20 use crate::model::repository::TangledRepository; 21 21 use crate::private;
+2 -2
crates/gordian-knot/src/public/git/upload_archive.rs
··· 10 10 11 11 use crate::command::ChildExt as _; 12 12 use crate::command::CommandExt as _; 13 - use crate::extractors::GitProtocol; 14 - use crate::extractors::request_id::RequestId; 13 + use crate::extract::git_protocol::GitProtocol; 14 + use crate::extract::request_id::RequestId; 15 15 use crate::model::Knot; 16 16 use crate::model::repository::TangledRepository; 17 17
+2 -2
crates/gordian-knot/src/public/git/upload_pack.rs
··· 13 13 14 14 use crate::command::ChildExt; 15 15 use crate::command::CommandExt as _; 16 - use crate::extractors::GitProtocol; 17 - use crate::extractors::request_id::RequestId; 16 + use crate::extract::git_protocol::GitProtocol; 17 + use crate::extract::request_id::RequestId; 18 18 use crate::model::Knot; 19 19 use crate::model::repository::TangledRepository; 20 20
+1 -1
crates/gordian-knot/src/public/xrpc/sh_tangled/repo/impl_blob.rs
··· 18 18 use reqwest::header::ETAG; 19 19 use tokio_rayon::AsyncThreadPool as _; 20 20 21 - use crate::extractors::IfNoneMatch; 21 + use crate::extract::if_none_match::IfNoneMatch; 22 22 use crate::model::Knot; 23 23 use crate::model::repository::ResolveRevspec as _; 24 24 use crate::model::repository::ResolvedRevspec;