Unverified Commit 8676219e authored by david-perez's avatar david-perez Committed by GitHub
Browse files

Set server response headers (#1086)

This commit adds support for the `httpHeaders` and `httpPrefixHeaders`
when applied to error shapes and operation output shapes to the server
implementation.

The presence of response headers is now asserted against in server
protocol tests.

Functions that set headers in requests that were used by the client have
been refactored into `HttpBindingGenerator.kt`, since they are useful
for the server to set headers in responses.

This commit also makes error shapes be serialized in JSON responses with
a `__type` field in the body, in favor of setting the `X-Amzn-Errortype`
header, as recommended by the specs of all AWS protocols.

This commit also removes the generation of operation structs for the
server in `ProtocolGenerator.kt`, since they are not useful for the
server implementation.

Closes #1071 #1075.
parent cc535bc1
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -160,7 +160,7 @@ mod test {
            )
        }
        assert_ok(validate_headers(
            &augmented_req.http(),
            &augmented_req.http().headers(),
            test_case.request_headers_after(),
        ))
    }
+1 −1
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ async fn set_correct_headers() {
        .await;
    let req = handler.expect_request();
    assert_ok(validate_headers(
        &req,
        &req.headers(),
        [
            (
                "x-amz-sha256-tree-hash",
+0 −1
Original line number Diff line number Diff line
@@ -219,7 +219,6 @@ class ServerCodegenVisitor(context: PluginContext, private val codegenDecorator:
            protocolGeneratorFactory.support(),
            protocolGeneratorFactory.protocol(codegenContext).httpBindingResolver,
            codegenContext,
            codegenDecorator
        )
            .render()
    }
+0 −2
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@ class ServerServiceGenerator(
    private val protocolSupport: ProtocolSupport,
    private val httpBindingResolver: HttpBindingResolver,
    private val context: CodegenContext,
    private val decorator: RustCodegenDecorator,
) {
    private val index = TopDownIndex.of(context.model)

@@ -42,7 +41,6 @@ class ServerServiceGenerator(
                protocolGenerator.serverRenderOperation(
                    operationWriter,
                    operation,
                    decorator.operationCustomizations(context, operation, listOf())
                )
                ServerProtocolTestGenerator(context, protocolSupport, operation, operationWriter)
                    .render()
+26 −0
Original line number Diff line number Diff line
/*
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0.
 */

package software.amazon.smithy.rust.codegen.server.smithy.generators.http


import software.amazon.smithy.model.shapes.OperationShape
import software.amazon.smithy.model.shapes.Shape
import software.amazon.smithy.rust.codegen.smithy.CodegenContext
import software.amazon.smithy.rust.codegen.smithy.RuntimeType
import software.amazon.smithy.rust.codegen.smithy.generators.http.HttpBindingGenerator
import software.amazon.smithy.rust.codegen.smithy.generators.http.HttpMessageType
import software.amazon.smithy.rust.codegen.smithy.protocols.Protocol

class ServerResponseBindingGenerator(
    protocol: Protocol,
    codegenContext: CodegenContext,
    operationShape: OperationShape
) {
    private val httpBindingGenerator = HttpBindingGenerator(protocol, codegenContext, operationShape)

    fun generateAddHeadersFn(shape: Shape): RuntimeType? =
        httpBindingGenerator.generateAddHeadersFn(shape, HttpMessageType.RESPONSE)
}
Loading