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

Add protocol specific routers #1666

Merged
merged 12 commits into from
Aug 26, 2022
Merged

Add protocol specific routers #1666

merged 12 commits into from
Aug 26, 2022

Conversation

hlbarber
Copy link
Contributor

@hlbarber hlbarber commented Aug 24, 2022

Motivation and Context

Description

  • Add protocol specific routers
  • Add IntoResponse<Protocol> to allow for multiple implementations of IntoResponse.
  • Remove UnknownOperation from RuntimeError.
  • Convert directly from routing errors to a http::Response via IntoResponse.
  • Refactor existing Router to use protocol specific routers internally.

@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

rust-runtime/aws-smithy-http-server/src/protocols.rs Outdated Show resolved Hide resolved
rust-runtime/aws-smithy-http-server/src/protocols.rs Outdated Show resolved Hide resolved
@@ -36,3 +36,7 @@ use crate::body::BoxBody;

#[doc(hidden)]
pub type Response<T = BoxBody> = http::Response<T>;

pub trait IntoResponse<Protocol> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add #[doc(hidden)]? Since only codegen needs to be aware of this trait.

Copy link
Contributor Author

@hlbarber hlbarber Aug 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's already a #[doc(hidden)] at the module level in lib.rs. The Response above is double hidden, which threw me off too - should I remove that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's already a #[doc(hidden)] at the module level in lib.rs

Ah, missed that. Thought it wasn't because Response was doc hidden.

Ok then, no need to double hide Response --- although, I'm thinking that middleware authors will need access to it right?

Copy link
Contributor Author

@hlbarber hlbarber Aug 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that third-parties might want to see IntoResponse and FromRequest eventually? They'll need it to implement their own protocols etc. I was thinking of keeping them hidden until everything in the RFC has been implemented. I'm not 100% sure on whether IntoResponse needs a second parameterization over the operation, which would be a breaking change.

I don't mind (double?) unhiding Response, no strong feelings about that.

Harry Barber added 2 commits August 25, 2022 12:32
rust-runtime/aws-smithy-http-server/src/routing/mod.rs Outdated Show resolved Hide resolved
fn into_response(self) -> http::Response<BoxBody> {
match self {
Error::MethodDisallowed => super::method_disallowed(),
_ => http::Response::builder()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have the opportunity here to provide better error messages if we wanted. For example, if there is a missing header should we status code 400?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should only do things that are in the spec of these protocols. I don't even know if implementations of these protocols return 405 when the URI matches the route but the verb doesn't... These are good questions to be asking in the awslabs/smithy issue tracker, and push for better protocol test coverage.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -25,8 +25,6 @@ use crate::{protocols::Protocol, response::Response};

#[derive(Debug)]
pub enum RuntimeErrorKind {
/// The requested operation does not exist.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This a good example of the general approach laid out in the Protocol specific Errors section of the RFC.

  1. Make a protocol specific error
  2. Implement IntoResponse<Protocol> for it
  3. Remove the variant from RuntimeErrorKind

@github-actions
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

@hlbarber hlbarber marked this pull request as ready for review August 26, 2022 09:10
@hlbarber hlbarber requested a review from a team as a code owner August 26, 2022 09:10
@hlbarber hlbarber merged commit 778539f into main Aug 26, 2022
@hlbarber hlbarber deleted the harryb/protocol-specific-router branch August 26, 2022 16:53
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.

Should we code-generate the Router type?
2 participants