Skip to content

Commit

Permalink
Fix readbytes
Browse files Browse the repository at this point in the history
  • Loading branch information
prange committed Apr 30, 2019
1 parent eb9e5d2 commit 79f8a5e
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ import java.net.URI
import java.util.*
import io.undertow.server.handlers.Cookie as UCookie
import io.vavr.collection.List
import java.io.IOException

fun fromExchange(exchange: HttpServerExchange) =
Request(
TreeMap.ofAll(exchange.requestCookies).mapValues { convertCookie(it) },
toMap(exchange.requestHeaders),
TreeMap.ofAll<String, Deque<String>>(exchange.queryParameters).mapValues({ d -> List.ofAll(d) }),
readBytes(exchange.inputStream),
readBytesToString(exchange.inputStream),
URI.create(exchange.requestURI),
List.of(*exchange.requestPath.split("/".toRegex()).dropLastWhile({ it.isEmpty() }).toTypedArray()),
List.empty(),
Expand All @@ -41,7 +42,7 @@ fun intoExcehange(response: Response, exchange: HttpServerExchange) {
exchange.statusCode = response.statusCode

response.body.forEach { body ->
val readAllBytes = body.readAllBytes()
val readAllBytes = body.readBytes()
exchange.responseContentLength = readAllBytes.size.toLong()
exchange.outputStream.write(readAllBytes)
}
Expand Down Expand Up @@ -81,7 +82,7 @@ fun convertCookie(cookie: Cookie): UCookie {
return ucookie
}

private fun readBytes(stream: InputStream): String =
private fun readBytesToString(stream: InputStream): String =
stream.bufferedReader().use { it.readText() }


Expand All @@ -99,3 +100,4 @@ private fun toMap(headerMap: HeaderMap): TreeMap<String, List<String>> =
})



0 comments on commit 79f8a5e

Please sign in to comment.