Kotlin / kotlinx-io

Kotlin multiplatform I/O library
Apache License 2.0
1.27k stars 56 forks source link

MockEngine 'Invalid JSON at 4088: Unexpected end in string' on iOS #38

Closed jrocharodrigues closed 1 year ago

jrocharodrigues commented 5 years ago

Ktor Version

1.1.2

Kx.io Version

0.1.5-dev-4

Ktor Engine Used(client or server and name)

Ktor-client with MockEngine

JVM Version, Operating System and Relevant Context

The bug occurs in when running my project on iOS in a multi-platform (android/iOS) project. In Android it works as expected

Feedback

I've recently came across this bug Kotlin/kotlinx.serialization#360 . After upgrading both kotlinx-io and kotlinx-coroutines-io to version 0.1.5-dev-4 the issue no long occured when making live requests to server. But when i use the mock engine, with an content bigger than 4088 chars i got this error: Invalid JSON at 4088: Unexpected end in string

If my content is smaller than 4088 it works fine.

Here's the code i use to create the MockEngin


val TOPOLOGY_ANSWER = """
  VERY BIG JSON STRING
"""

val httpMockEngine =  MockEngine {
        when (url.toString()) {
            "$baseUrl/${ApiEndpoints.TOPOLOGY}" -> {
                MockHttpResponse(
                    call,
                    HttpStatusCode.OK,                   
                    ByteReadChannel(TOPOLOGY_ANSWER.toByteArray(Charsets.UTF_8)),
                    headersOf("Content-Type" to listOf(ContentType.Application.Json.toString()))
                )
            }
            else -> {
                error("Unhandled $url")
            }
        }

val client: HttpClient = HttpClient(httpMockEngine) {
                install(JsonFeature) {
                    serializer = KotlinxSerializer(Json.nonstrict).apply {
                        setMapper(Topology::class, Topology.serializer())
                    }
                }

Thanks in advance

jrocharodrigues commented 5 years ago

If you need more info, just let me know.

fzhinkin commented 1 year ago

We're rebooting the kotlinx-io development (see https://github.com/Kotlin/kotlinx-io/issues/131), all issues related to the previous versions will be closed. Consider reopening it if the issue remains (or the feature is still missing) in a new version.