Skip to content

Commit c5c5b68

Browse files
committed
Merge branch 'master' of github.com:mduesterhoeft/lambda-kotlin-request-router
2 parents 9d7f876 + 92b2c2d commit c5c5b68

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[![](https://jitpack.io/v/mduesterhoeft/lambda-kotlin-request-router.svg)](https://jitpack.io/#mduesterhoeft/lambda-kotlin-request-router)
2+
3+
# lambda-kotlin-request-router

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

Lines changed: 7 additions & 6 deletions
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)