Unverified Commit 05ffd071 authored by Matteo Bigoi's avatar Matteo Bigoi Committed by GitHub
Browse files

[Server] Set http extensions for Request / Response (#963)

parent 6e16e2ba
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -164,7 +164,7 @@ class ServerCodegenVisitor(context: PluginContext, private val codegenDecorator:
    override fun structureShape(shape: StructureShape) {
        logger.info("[rust-server-codegen] Generating a structure $shape")
        rustCrate.useShapeWriter(shape) { writer ->
            StructureGenerator(model, symbolProvider, writer, shape).render()
            StructureGenerator(model, symbolProvider, writer, shape).renderServer()
            val builderGenerator =
                BuilderGenerator(codegenContext.model, codegenContext.symbolProvider, shape)
            builderGenerator.render(writer)
+0 −0

File moved.

+7 −1
Original line number Diff line number Diff line
@@ -68,12 +68,18 @@ class ServerCombinedErrorGenerator(
                    rust("matches!(&self, ${symbol.name}::${errorSymbol.name}(_))")
                }
            }
            writer.rust("/// Returns the error name string by matching the correct variant.")
            writer.rustBlock("pub fn name(&self) -> &'static str") {
                delegateToVariants {
                    rust("_inner.name()")
                }
            }
        }

        writer.rustBlock("impl #T for ${symbol.name}", RuntimeType.StdError) {
            rustBlock("fn source(&self) -> Option<&(dyn #T + 'static)>", RuntimeType.StdError) {
                delegateToVariants {
                    rust("Some(_inner)");
                    rust("Some(_inner)")
                }
            }
        }
+9 −2
Original line number Diff line number Diff line
@@ -66,6 +66,13 @@ class ServerOperationHandlerGenerator(
            } else {
                "impl<B, Fun, Fut> #{ServerOperationHandler}::Handler<B, (), $inputName> for Fun"
            }
            val storeErrorInExtensions = """{
                let error = aws_smithy_http_server::ExtensionRejection::new(r.to_string());
                let mut response = r.into_response();
                response.extensions_mut().insert(error);
                return response.map($serverCrate::boxed);
                }
            """.trimIndent()
            writer.rustBlockTemplate(
                """
                ##[#{AsyncTrait}::async_trait]
@@ -78,7 +85,7 @@ class ServerOperationHandlerGenerator(
                val callImpl = if (state) {
                    """let state = match $serverCrate::Extension::<S>::from_request(&mut req).await {
                    Ok(v) => v,
                    Err(r) => return r.into_response().map($serverCrate::boxed)
                    Err(r) => $storeErrorInExtensions
                    };
                    let input_inner = input_wrapper.into();
                    let output_inner = self(input_inner, state).await;"""
@@ -95,7 +102,7 @@ class ServerOperationHandlerGenerator(
                        use #{AxumCore}::response::IntoResponse;
                        let input_wrapper = match $inputWrapperName::from_request(&mut req).await {
                            Ok(v) => v,
                            Err(r) => return r.into_response().map(#{SmithyHttpServer}::boxed)
                            Err(r) => $storeErrorInExtensions
                        };
                        $callImpl
                        let output_wrapper: $outputWrapperName = output_inner.into();
+0 −0

File moved.

Loading