-
Notifications
You must be signed in to change notification settings - Fork 347
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
feat: ergonomic improvements to HTTP payload deserialization #921
Conversation
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.
Thanks for adding all those tests and new documentation! ✨
lambda-http/src/ext/request.rs
Outdated
@@ -20,6 +20,39 @@ pub enum PayloadError { | |||
WwwFormUrlEncoded(SerdeError), | |||
} | |||
|
|||
/// Alias for a type-erased error type. | |||
pub type BoxError = Box<dyn std::error::Error + Send + Sync>; |
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.
I believe this is not used, can you remove it? We also have a similar type already exposed in lambda-http/lib.rs.
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.
Good catch! Removed.
(I was considering a generic Other
variant for the new error types that would keep a box error. Decided to keep the errors as a single-variant enum to leave the option open without forcing users to handle an error path would have been currently impossible, but let me know if that's something you'd actually prefer)
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.
Please, remove unused types.
BREAKING CHANGE: adds additional methods to the `RequestPayloadExt` trait. implements RFC #917
📬 Issue #, if available:
#917
✍️ Description of changes:
Ergonomic improvements to HTTP payload deserialization with intent-driven helper methods (
json
andform_url_encoded
are the initial implementations). Details in RFC (#917).Note: there was a bug in
RequestPayloadExt::payload
where if the content-type header was present but the body was empty, it would try to parse it anyways, resulting in a PayloadError. The bug was fixed when I updated the function to delegate tojson
andform_urlencoded
. I added a couple unit tests in this PR for that scenario to ensure the behavior doesn't regress if its implementation drifts from the new functions in the future.🔏 By submitting this pull request
cargo +nightly fmt
.cargo clippy --fix
.