Skip to content

Commit

Permalink
Remember to close the exchange.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelhg committed May 13, 2023
1 parent a137dcd commit 1acddf3
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/test/kotlin/io/mikael/ksoup/test/util.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,17 @@ open class StaticWebTest {
server = HttpServer.create(InetSocketAddress(PORT), 1).apply {
createContext("/").handler = HttpHandler { exchange ->
lastRequest = exchange.requestURI.path
when (val s = staticContentResolver(exchange.requestURI.path)) {
when (val filePath = staticContentResolver(exchange.requestURI.path)) {
null -> {
exchange.sendResponseHeaders(404, 0)
}
else -> {
val bytes = resource(s)!!.readBytes()
val bytes = resource(filePath)!!.readBytes()
exchange.sendResponseHeaders(200, bytes.size.toLong())
exchange.responseBody.write(bytes)
}
}
exchange.close()
}
this.start()
}
Expand Down

0 comments on commit 1acddf3

Please sign in to comment.