Skip to content

Commit aed95f7

Browse files
committed
take over status code and headers from response
1 parent ca71b63 commit aed95f7

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/main/kotlin/com/github/mduesterhoeft/router/RequestHandler.kt

+7-6
Original file line numberDiff line numberDiff line change
@@ -123,23 +123,24 @@ abstract class RequestHandler : RequestHandler<APIGatewayProxyRequestEvent, APIG
123123
return when {
124124
response.body is Unit -> APIGatewayProxyResponseEvent()
125125
.withStatusCode(204)
126+
.withHeaders(response.headers)
126127

127128
accept.`is`(MediaType.parse("application/x-protobuf")) -> APIGatewayProxyResponseEvent()
128-
.withStatusCode(200)
129+
.withStatusCode(response.statusCode)
129130
.withBody(Base64.getEncoder().encodeToString((response.body as GeneratedMessageV3).toByteArray()))
130-
.withHeaders(mapOf("Content-Type" to "application/x-protobuf"))
131+
.withHeaders(response.headers + ("Content-Type" to "application/x-protobuf"))
131132

132133
accept.`is`(MediaType.parse("application/json")) ->
133134
if (response.body is GeneratedMessageV3)
134135
APIGatewayProxyResponseEvent()
135-
.withStatusCode(200)
136+
.withStatusCode(response.statusCode)
136137
.withBody(toJsonWithoutWrappers(response.body))
137-
.withHeaders(mapOf("Content-Type" to "application/json"))
138+
.withHeaders(response.headers + ("Content-Type" to "application/json"))
138139
else
139140
APIGatewayProxyResponseEvent()
140-
.withStatusCode(200)
141+
.withStatusCode(response.statusCode)
141142
.withBody(response.body?.let { objectMapper.writeValueAsString(it) })
142-
.withHeaders(mapOf("Content-Type" to "application/json"))
143+
.withHeaders(response.headers + ("Content-Type" to "application/json"))
143144
else -> throw IllegalArgumentException("unsupported response $response")
144145
}
145146
}

0 commit comments

Comments
 (0)