Skip to content
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

Merged
merged 1 commit into from
Sep 4, 2024
Merged

feat: ergonomic improvements to HTTP payload deserialization #921

merged 1 commit into from
Sep 4, 2024

Conversation

mlaota
Copy link
Contributor

@mlaota mlaota commented Sep 2, 2024

📬 Issue #, if available:
#917

✍️ Description of changes:
Ergonomic improvements to HTTP payload deserialization with intent-driven helper methods (json and form_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 to json and form_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

  • I confirm that I've ran cargo +nightly fmt.
  • I confirm that I've ran cargo clippy --fix.
  • I confirm that I've made a best effort attempt to update all relevant documentation.
  • I confirm that my contribution is made under the terms of the Apache 2.0 license.

@mlaota mlaota changed the title feat: ergonomic improvements to HTTP payload deserialization (#917) feat: ergonomic improvements to HTTP payload deserialization Sep 3, 2024
Copy link
Contributor

@calavera calavera left a 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! ✨

@@ -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>;
Copy link
Contributor

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.

Copy link
Contributor Author

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)

Copy link
Contributor

@calavera calavera left a 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
@calavera calavera merged commit 27191d0 into awslabs:main Sep 4, 2024
5 checks passed
@mlaota mlaota deleted the intent-payload-parsers branch September 5, 2024 03:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants