Skip to content

Commit

Permalink
Fix duplicate content-type in server response (#1163)
Browse files Browse the repository at this point in the history
Signed-off-by: Guy Margalit <[email protected]>
  • Loading branch information
guymguym authored Feb 7, 2022
1 parent 25c50a5 commit 2a68774
Showing 1 changed file with 15 additions and 13 deletions.
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

0 comments on commit 2a68774

Please sign in to comment.