-
Notifications
You must be signed in to change notification settings - Fork 747
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Assume Content-Type is json for endpoints that require json #4575
Merged
mergify
merged 15 commits into
sigp:unstable
from
eserilev:ignore-content-type-header-for-json
Jan 31, 2024
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
ac16c6b
added default content type filter
eserilev 5ec781b
Merge branch 'unstable' of https://github.com/sigp/lighthouse into un…
eserilev 485c87f
create custom warp json filter that ignores content type header
eserilev d312394
cargo fmt and linting
eserilev dff057f
updated test
eserilev 8968239
updated test
eserilev 9a24a01
merge unstable
eserilev 133ed89
merge conflicts
eserilev 8a5f3f3
workspace=true
eserilev 3e8f176
use Bytes instead of Buf
eserilev afd06b7
resolve merge conflict
eserilev 6b199d4
resolve merge conflicts
eserilev 1a40738
add extra error message context
eserilev 350d7b3
merge conflicts
eserilev 29226b8
lint
eserilev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use bytes::Bytes; | ||
use serde::de::DeserializeOwned; | ||
use std::error::Error as StdError; | ||
use warp::{Filter, Rejection}; | ||
|
||
use crate::reject; | ||
|
||
struct Json; | ||
|
||
type BoxError = Box<dyn StdError + Send + Sync>; | ||
|
||
impl Json { | ||
fn decode<T: DeserializeOwned>(bytes: Bytes) -> Result<T, BoxError> { | ||
serde_json::from_slice(&bytes).map_err(Into::into) | ||
} | ||
} | ||
|
||
pub fn json<T: DeserializeOwned + Send>() -> impl Filter<Extract = (T,), Error = Rejection> + Copy { | ||
warp::body::bytes().and_then(|bytes: Bytes| async move { | ||
Json::decode(bytes).map_err(|err| reject::custom_deserialize_error(format!("{:?}", err))) | ||
}) | ||
} | ||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Diff from
warp::filters::body::json
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Equivalent code with the suggestion to remove the copy from #4575 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eserilev consider appending some extra message context like
lighthouse/common/warp_utils/src/reject.rs
Lines 164 to 165 in 1be5253