diff --git a/gradle.properties b/gradle.properties index 92f8e5b79e..5fce4fc953 100644 --- a/gradle.properties +++ b/gradle.properties @@ -37,7 +37,7 @@ mockkVersion=1.13.7 junitVersion=5.10.0 gatlingVersion=3.9.5 jmhVersion=1.37 -mkdocsMaterialVersion=9.2.3 +mkdocsMaterialVersion=9.2.4 mermaidDokkaVersion=0.4.4 nativeToolsVersion=0.9.24 diff --git a/http/http_handlers/README.md b/http/http_handlers/README.md index d6f0a80d77..be496a5529 100644 --- a/http/http_handlers/README.md +++ b/http/http_handlers/README.md @@ -12,6 +12,11 @@ feature (as [http_server_jetty]) in order to create an HTTP server. [http_server_jetty]: /http_server_jetty +# Chaining changes +The response can be modified chaining `send` calls (or its utility methods). However, If calls are +not chained, only the last one will be applied. I.e.: `send().send()` will apply both calls changes, +while `send(); send()` will pass only the last send method result. + # Context on HTTP processing An HTTP server is nothing more than a function that takes a request and returns a response. Requests and responses comply with several Web standards. diff --git a/http/http_test/src/main/kotlin/com/hexagonkt/http/test/examples/SamplesTest.kt b/http/http_test/src/main/kotlin/com/hexagonkt/http/test/examples/SamplesTest.kt index df56a447c7..3117ac8fc3 100644 --- a/http/http_test/src/main/kotlin/com/hexagonkt/http/test/examples/SamplesTest.kt +++ b/http/http_test/src/main/kotlin/com/hexagonkt/http/test/examples/SamplesTest.kt @@ -33,6 +33,7 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.TestInstance import org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS import java.net.InetAddress +import java.net.URI import kotlin.test.assertEquals @TestInstance(PER_CLASS) @@ -240,20 +241,38 @@ abstract class SamplesTest( // callbackResponse get("/response") { - response.body // Get response content - response.status // Get the response status - response.contentType // Get the content type + response.body // Get response content + response.status // Get the response status + response.contentType // Get the content type - status // Shortcut of `response.status` + status // Shortcut of `response.status` send( status = UNAUTHORIZED_401, // Set status code to 401 body = "Hello", // Sets content to Hello contentType = ContentType(APPLICATION_XML), // Set application/xml content type headers = response.headers - + Header("foo", "bar") // Sets header FOO with single value bar - + Header("baz", "1", "2") // Sets header FOO values with [ bar ] + + Header("foo", "bar") // Sets header FOO with single value bar + + Header("baz", "1", "2") // Sets header FOO values with [ bar ] ) + + // Utility methods for generating common responses + unauthorized("401: authorization missing") + forbidden("403: access not granted") + internalServerError("500: server error") + serverError(NOT_IMPLEMENTED_501, RuntimeException("Error")) + ok("Correct") + badRequest("400: incorrect request") + notFound("404: Missing resource") + created("201: Created") + redirect(FOUND_302, URI("/location")) + + // The response can be modified chaining send calls (or its utility methods) + ok("Replacing headers").send(headers = Headers()) + + // If calls are not chained, only the last one will be applied + ok("Intending to replace headers") + send(headers = Headers()) // This will be passed, but previous ok will be ignored } // callbackResponse @@ -338,7 +357,7 @@ abstract class SamplesTest( assertEquals("Invalid request", callResponse.body) assertEquals(OK_200, it.get("/request", body = "body", contentType = json).status) - assertEquals(UNAUTHORIZED_401, it.get("/response").status) + assertEquals(NOT_FOUND_404, it.get("/response").status) assertEquals(OK_200, it.get("/pathParam/param").status) assertEquals(OK_200, it.get("/queryParam").status) assertEquals(OK_200, it.get("/formParam").status) diff --git a/site/assets/css/mkdocs.css b/site/assets/css/mkdocs.css index 1d2167ddb0..89b0af4b99 100644 --- a/site/assets/css/mkdocs.css +++ b/site/assets/css/mkdocs.css @@ -83,7 +83,10 @@ ul.md-source__facts { div.md-hero + nav.md-tabs { background: #31415C; - text-align: center; +} + +ul.md-tabs__list { + justify-content: center; } .md-hero {