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

Fix duplicate content-type in server response #1163

Merged
merged 1 commit into from
Feb 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,21 @@ private class ServerHttpProtocolImplGenerator(
* The `Content-Type` header is also set according to the protocol and the contents of the shape to be serialized.
*/
private fun RustWriter.serverRenderResponseHeaders(operationShape: OperationShape, errorShape: StructureShape? = null) {
val bindingGenerator = ServerResponseBindingGenerator(protocol, codegenContext, operationShape)
val addHeadersFn = bindingGenerator.generateAddHeadersFn(errorShape ?: operationShape)
if (addHeadersFn != null) {
// notice that we need to borrow the output only for output shapes but not for error shapes
val outputOwnedOrBorrow = if (errorShape == null) "&output" else "output"
rust(
"""
builder = #{T}($outputOwnedOrBorrow, builder)?;
""".trimIndent(),
addHeadersFn
)
}

// set the content type header *after* the response bindings headers have been set
// to allow operations that bind a member to content-type to take precedence
val contentType = httpBindingResolver.responseContentType(operationShape)
if (contentType != null) {
rustTemplate(
Expand All @@ -505,19 +520,6 @@ private class ServerHttpProtocolImplGenerator(
*codegenScope
)
}

val bindingGenerator = ServerResponseBindingGenerator(protocol, codegenContext, operationShape)
val addHeadersFn = bindingGenerator.generateAddHeadersFn(errorShape ?: operationShape)
if (addHeadersFn != null) {
// notice that we need to borrow the output only for output shapes but not for error shapes
val outputOwnedOrBorrow = if (errorShape == null) "&output" else "output"
rust(
"""
builder = #{T}($outputOwnedOrBorrow, builder)?;
""".trimIndent(),
addHeadersFn
)
}
}

private fun serverRenderBindingSerializer(
Expand Down