Skip to content

Commit

Permalink
Server streaming body + response headers
Browse files Browse the repository at this point in the history
Signed-off-by: Guy Margalit <[email protected]>
  • Loading branch information
guymguym committed Jan 2, 2022
1 parent 36faba8 commit ac3eb3c
Show file tree
Hide file tree
Showing 4 changed files with 207 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import software.amazon.smithy.rust.codegen.server.smithy.protocols.ServerHttpPro
import software.amazon.smithy.rust.codegen.smithy.CodegenContext
import software.amazon.smithy.rust.codegen.smithy.RuntimeType
import software.amazon.smithy.rust.codegen.smithy.generators.error.errorSymbol
import software.amazon.smithy.rust.codegen.util.hasStreamingMember
import software.amazon.smithy.rust.codegen.util.inputShape
import software.amazon.smithy.rust.codegen.util.outputShape

/**
Expand All @@ -39,6 +41,7 @@ class ServerOperationHandlerGenerator(
"PinProjectLite" to ServerCargoDependency.PinProjectLite.asType(),
"Tower" to ServerCargoDependency.Tower.asType(),
"FuturesUtil" to ServerCargoDependency.FuturesUtil.asType(),
"SmithyHttp" to CargoDependency.SmithyHttp(runtimeConfig).asType(),
"SmithyHttpServer" to CargoDependency.SmithyHttpServer(runtimeConfig).asType(),
"SmithyRejection" to ServerHttpProtocolGenerator.smithyRejection(runtimeConfig),
"Phantom" to ServerRuntimeType.Phantom,
Expand Down Expand Up @@ -132,13 +135,19 @@ class ServerOperationHandlerGenerator(
} else {
symbolProvider.toSymbol(operation.outputShape(model)).fullName
}
val streamingBodyTraitBounds = if (operation.inputShape(model).hasStreamingMember(model)) {
"B: Into<#{SmithyHttp}::byte_stream::ByteStream>,"
} else {
""
}
return """
$inputFn
Fut: std::future::Future<Output = $outputType> + Send,
B: $serverCrate::HttpBody + Send + 'static,
$streamingBodyTraitBounds
B::Data: Send,
B::Error: Into<$serverCrate::BoxError>,
$serverCrate::rejection::SmithyRejection: From<<B as $serverCrate::HttpBody>::Error>
"""
""".trimIndent()
}
}
Loading

0 comments on commit ac3eb3c

Please sign in to comment.