-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'chrivers/json-extractor-workaround' into dev
- Loading branch information
Showing
16 changed files
with
625 additions
and
45 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use axum::extract::rejection::JsonRejection; | ||
use axum::extract::{FromRequest, Request}; | ||
use axum::response::IntoResponse; | ||
use bytes::Bytes; | ||
use serde::de::DeserializeOwned; | ||
use serde::Serialize; | ||
|
||
// Simple wrapper around axum::Json, which skips the header requirements. | ||
// | ||
// The axum version requires "Content-Type: application/json", which many | ||
// (buggy) apps don't actually send. So we are forced to skip this check. | ||
pub struct Json<T>(pub T); | ||
|
||
#[axum::async_trait] | ||
impl<S, T> FromRequest<S> for Json<T> | ||
where | ||
axum::Json<T>: FromRequest<S, Rejection = JsonRejection>, | ||
T: DeserializeOwned, | ||
S: Send + Sync, | ||
{ | ||
type Rejection = JsonRejection; | ||
|
||
async fn from_request(req: Request, state: &S) -> Result<Self, Self::Rejection> { | ||
let bytes = Bytes::from_request(req, state).await?; | ||
Ok(Self(axum::Json::from_bytes(&bytes)?.0)) | ||
} | ||
} | ||
|
||
impl<T: Serialize> IntoResponse for Json<T> { | ||
fn into_response(self) -> axum::response::Response { | ||
axum::Json(self.0).into_response() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.