File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed
main/kotlin/io/moia/router
test/kotlin/io/moia/router Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,9 @@ import com.google.common.net.MediaType
6
6
import java.net.URI
7
7
import java.util.Base64
8
8
9
+ /* * Data class that represents an HTTP header */
10
+ data class Header (val name : String , val value : String )
11
+
9
12
fun APIGatewayProxyRequestEvent.acceptHeader () = getHeaderCaseInsensitive(" accept" )
10
13
fun APIGatewayProxyRequestEvent.acceptedMediaTypes () = acceptHeader()
11
14
?.split(" ," )
@@ -54,9 +57,15 @@ fun APIGatewayProxyRequestEvent.location(path: String): URI {
54
57
fun APIGatewayProxyRequestEvent.withHeader (name : String , value : String ) =
55
58
this .also { if (headers == null ) headers = mutableMapOf () }.also { headers[name] = value }
56
59
60
+ fun APIGatewayProxyRequestEvent.withHeader (header : Header ) =
61
+ this .withHeader(header.name, header.value)
62
+
57
63
fun APIGatewayProxyResponseEvent.withHeader (name : String , value : String ) =
58
64
this .also { if (headers == null ) headers = mutableMapOf () }.also { headers[name] = value }
59
65
66
+ fun APIGatewayProxyResponseEvent.withHeader (header : Header ) =
67
+ this .withHeader(header.name, header.value)
68
+
60
69
fun APIGatewayProxyResponseEvent.withLocationHeader (request : APIGatewayProxyRequestEvent , path : String ) =
61
70
this .also { if (headers == null ) headers = mutableMapOf () }.also { headers[" location" ] = request.location(path).toString() }
62
71
Original file line number Diff line number Diff line change 1
1
package io.moia.router
2
2
3
+ import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent
3
4
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent
4
5
import org.assertj.core.api.BDDAssertions.then
5
6
import org.junit.jupiter.api.Test
@@ -56,4 +57,20 @@ class APIGatewayProxyEventExtensionsTest {
56
57
57
58
then(location.toString()).isEqualTo(" http://example.com/some/path" )
58
59
}
60
+
61
+ @Test
62
+ fun `header class should work as expected with APIGatewayProxyRequestEvent` () {
63
+
64
+ val request = APIGatewayProxyRequestEvent ().withHeader(Header (" foo" , " bar" ))
65
+
66
+ then(request.headers[" foo" ]).isEqualTo(" bar" )
67
+ }
68
+
69
+ @Test
70
+ fun `header class should work as expected with APIGatewayProxyResponseEvent` () {
71
+
72
+ val request = APIGatewayProxyResponseEvent ().withHeader(Header (" foo" , " bar" ))
73
+
74
+ then(request.headers[" foo" ]).isEqualTo(" bar" )
75
+ }
59
76
}
You can’t perform that action at this time.
0 commit comments