diff --git a/build.gradle b/build.gradle index 2842815..0ba1552 100644 --- a/build.gradle +++ b/build.gradle @@ -14,7 +14,7 @@ dependencies { compile 'org.eclipse.jetty:jetty-server:9.4.27.v20200227' compile 'org.eclipse.jetty:jetty-servlet:9.4.27.v20200227' - compile 'com.github.DaikonWeb:daikon-core:1.3.3' + compile 'com.github.DaikonWeb:daikon-core:1.3.4' testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.2' testImplementation 'org.junit.jupiter:junit-jupiter-api:5.5.2' diff --git a/src/main/kotlin/daikon/HttpResponse.kt b/src/main/kotlin/daikon/HttpResponse.kt index d27afe5..e75bb96 100644 --- a/src/main/kotlin/daikon/HttpResponse.kt +++ b/src/main/kotlin/daikon/HttpResponse.kt @@ -28,10 +28,14 @@ class HttpResponse(private val response: HttpServletResponse) : Response { response.contentType = contentType } + override fun type() = response.contentType + override fun status(code: Int) { response.status = code } + override fun status() = response.status + override fun write(text: String) { writer.write(text) write(text.toByteArray(UTF_8)) diff --git a/src/test/kotlin/daikon/ResponseTest.kt b/src/test/kotlin/daikon/ResponseTest.kt index f4e7fb1..19fe8aa 100644 --- a/src/test/kotlin/daikon/ResponseTest.kt +++ b/src/test/kotlin/daikon/ResponseTest.kt @@ -2,6 +2,7 @@ package daikon import daikon.core.HttpStatus.CREATED_201 import daikon.core.HttpStatus.MOVED_PERMANENTLY_301 +import daikon.core.HttpStatus.NOT_FOUND_404 import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import topinambur.http @@ -79,4 +80,24 @@ class ResponseTest { assertThat(local("/").http.get().header("Server")).isEqualTo("Daikon") } } + + @Test + fun `can access to response status code`() { + HttpServer() + .any("/") { _, res -> res.status(NOT_FOUND_404)} + .after("/") { _, res -> res.write("StatusCode = ${res.status()}")} + .start().use { + assertThat(local("/").http.get().body).isEqualTo("StatusCode = 404") + } + } + + @Test + fun `can access to response type`() { + HttpServer() + .any("/") { _, res -> res.type("application/json")} + .after("/") { _, res -> res.write("Type = ${res.type()}")} + .start().use { + assertThat(local("/").http.get().body).isEqualTo("Type = application/json") + } + } } \ No newline at end of file