Razvan
10/21/2020, 4:42 PM@Test
fun `response body string for html`() {
val logAll = Filter { next: HttpHandler ->
{ request ->
println("REQ: ${request.bodyString()}")
val response = next(request)
println("REP: ${response.bodyString()}")
response
}
}
val server = logAll
.then(routes("/static" bind static(ResourceLoader.Classpath("static"))))
.asServer(Undertow(8080)).start()
val client = DebuggingFilters.PrintResponse()
.then(OkHttp())
val response = client(Request(GET, "<http://localhost:8080/static/index.html>"))
response.status shouldBe 200
}
static/index.html exists the filter prints it.
the result:
REQ:
REP: <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hello http4k</title>
</head>
<body>
<h1>Hello http4k</h1>
</body>
</html>
***** RESPONSE 500 to GET: <http://localhost:8080/static/index.html> *****
HTTP/1.1 500 Internal Server Error
connection: keep-alive
content-length: 0
content-type: text/html
date: Wed, 21 Oct 2020 16:41:37 GMT
s4nchez
10/21/2020, 7:23 PMstream: closed
exception (invisible unless you debug it)val logAll = Filter { next: HttpHandler ->
{ request ->
println("REQ: ${request.bodyString()}")
val response = next(request)
val bodyPayload = response.bodyString()
println("REP: $bodyPayload")
response.body(bodyPayload)
}
}
Razvan
10/21/2020, 7:40 PMdave
10/23/2020, 1:57 AMRazvan
10/23/2020, 8:21 PM