-
Notifications
You must be signed in to change notification settings - Fork 193
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
Should we code-generate the Router
type?
#1606
Comments
Note that passing a trait object for the runtime error into response conversion closure: type RuntimeErrorFn = Box<dyn Fn(RuntimeError) -> http::Response<BoxBody>>;
pub struct Router<B = Body> {
routes: Routes<B>,
runtime_error_fn: RuntimeErrorFn,
} Would not break user code. However, we need ---- src/operation_registry.rs - operation_registry::OperationRegistry (line 29) stdout ----
error[E0277]: the trait bound `Router: Clone` is not satisfied
--> src/operation_registry.rs:49:50
|
22 | let server = hyper::Server::bind(&bind).serve(app.into_make_service());
| ----- ^^^^^^^^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `Router`
| |
| required by a bound introduced by this call
|
= note: required because of the requirements on the impl of `for<'a> Service<&'a AddrStream>` for `IntoMakeService<Router>`
= note: required because of the requirements on the impl of `service::make::MakeServiceRef<AddrStream, Body>` for `IntoMakeService<Router>` This failing idea is implemented in this davidpz/make-runtime-error-into-response-protocol-agnostic-via-trait-object branch. |
|
We use them now, it's something that we already do.
Unknown protocols.
Code-generating the
If by existing code generator, you mean either the
I've already thought about this. I think performance improvements would only start being noticeable in services with a huge (100?) number of routes. However, the main problem with trie-based routing is that we can't use something off-the-shelf like matchit because of Smithy's routing requirements. It would be very challenging to implement, say, routing based on query string literals using a trie-like data structure, because they can appear anywhere in the request URI after the path.
Yes, the
This is unrelated to the fact of whether we code-generate the
Yes. At codegen time we have this information in the model and we can thus filter out the logging statements in any component that is code-generated.
The assumption is that every time the user deploys, they are running the code generator. |
Closed by #1666 |
Currently, the conversion from
RuntimeError
intohttp::Response
is in theaws-smithy-http-server
runtime crate:https://github.com/awslabs/smithy-rs/blob/430f4bf8b49f2b1827d9c1657a6d0a5096cad978/rust-runtime/aws-smithy-http-server/src/runtime_error.rs#L59-L97
This conversion is used both by the
Router
(that convertsRuntimeError::UnknownOperation
into an 404 HTTP response), and in the code-generated operation handlers'from_request
functions (example below):However, the conversion is protocol-specific: that is, each protocol converts the runtime error into an HTTP response in a different way. This means the conversion cannot live in the runtime: we want to support loading
RustCodegenDecorator
s from the classpath that add support for protocols defined outside the smithy-rs project.Say we code-generate a protocol-specific function
fn runtime_error_to_response(err: RuntimeError) -> http::Response<BoxBody>
. There is no problem in having an operation handler'sfrom_request
use said function to return the HTTP response. However, theRouter
is a runtime component, not a code-generated one. In order for it to call the function we would have to pass it to the constructor (which is called by the code-generatedimpl From<OperationRegistry> for Router
):(note that
F
does not have a default and needs to go first in the list of generic type parameters). This is a breaking change, users would need to at least typeRouter<_>
in their code.The act of routing the incoming HTTP request itself to an operation is also protocol-specific: each protocol defines its own routing rules. We currently
match
over all externally-supported protocols, when we only always exercise one branch. So this is another place where we need to be able to inject protocol-specific routing logic into theRouter
when constructing it, by passing in another closure.It seems to me like after these breaking changes, there isn't much protocol-agnostic stuff in the
Router
type. This begs the question: should we entirely code-generate a protocol and service-specificRouter
in the generated sSDK?The text was updated successfully, but these errors were encountered: