Nikky
11/02/2018, 1:10 AM@Test
fun testChunkedEncoding() {
mock.chain(
request = mock.request().withMethod(Method.GET.value).withPath("/stream"),
response = mock.response().withHeader(Headers.TRANSFER_ENCODING, "chunked").withBody(
"""4\r\n
|Wiki\r\n
|5\r\n
|pedia\r\n
|E\r\n
| in\r\n
|\r\n\n
|chunks.\r\n
|0\r\n
|\r\n""".trimMargin().toByteArray()
)
)
val (request, response, result) = mock.path("stream").httpGet()
.responseObject(object : ResponseDeserializable<List<String>> {
override fun deserialize(reader: Reader): List<String> {
val list: MutableList<String> = mutableListOf<String>()
reader.forEachLine { line ->
println(line)
list += line
}
return list
}
})
when(result) {
is Result.Success -> println(result.value)
is Result.Failure -> {
println(request.cUrlString())
fail("request failed")
}
}
}