-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KTOR-4511 Ignore ByteReadChannel for server response and client request
- Loading branch information
Showing
18 changed files
with
252 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...lient/ktor-client-plugins/ktor-client-content-negotiation/js/src/DefaultIgnoredTypesJs.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* Copyright 2014-2022 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package io.ktor.client.plugins.contentnegotiation | ||
|
||
import io.ktor.http.content.* | ||
import io.ktor.utils.io.* | ||
import kotlin.reflect.* | ||
|
||
internal actual val DefaultIgnoredTypes: Set<KClass<*>> = | ||
mutableSetOf(OutgoingContent::class, ByteReadChannel::class, ByteArray::class) |
13 changes: 13 additions & 0 deletions
13
...ent/ktor-client-plugins/ktor-client-content-negotiation/jvm/src/DefaultIgnoredTypesJvm.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Copyright 2014-2022 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package io.ktor.client.plugins.contentnegotiation | ||
|
||
import io.ktor.http.content.* | ||
import io.ktor.utils.io.* | ||
import java.io.* | ||
import kotlin.reflect.* | ||
|
||
internal actual val DefaultIgnoredTypes: Set<KClass<*>> = | ||
mutableSetOf(OutgoingContent::class, ByteReadChannel::class, InputStream::class, ByteArray::class) |
12 changes: 12 additions & 0 deletions
12
...t/ktor-client-plugins/ktor-client-content-negotiation/posix/src/DefaultIgnoredTypesNix.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* Copyright 2014-2022 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package io.ktor.client.plugins.contentnegotiation | ||
|
||
import io.ktor.http.content.* | ||
import io.ktor.utils.io.* | ||
import kotlin.reflect.* | ||
|
||
internal actual val DefaultIgnoredTypes: Set<KClass<*>> = | ||
mutableSetOf(OutgoingContent::class, ByteReadChannel::class, ByteArray::class) |
60 changes: 60 additions & 0 deletions
60
ktor-client/ktor-client-tests/jvm/test/io/ktor/client/tests/DefaultTransformTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright 2014-2022 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package io.ktor.client.tests | ||
|
||
import io.ktor.client.call.* | ||
import io.ktor.client.engine.mock.* | ||
import io.ktor.client.request.* | ||
import io.ktor.client.statement.* | ||
import io.ktor.client.tests.utils.* | ||
import io.ktor.http.* | ||
import io.ktor.http.content.* | ||
import io.ktor.utils.io.* | ||
import java.io.* | ||
import kotlin.test.* | ||
|
||
/* | ||
* Copyright 2014-2022 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
class DefaultTransformTest { | ||
|
||
@Test | ||
fun testSendInputStream() = testWithEngine(MockEngine) { | ||
config { | ||
engine { | ||
addHandler { | ||
val text = (it.body as OutgoingContent.ReadChannelContent).readFrom().readRemaining().readText() | ||
respond(text) | ||
} | ||
} | ||
} | ||
|
||
test { client -> | ||
val response = client.post("/post") { | ||
val stream = ByteArrayInputStream("""{"x": 123}""".toByteArray()) | ||
contentType(ContentType.Application.Json) | ||
setBody(stream) | ||
}.bodyAsText() | ||
assertEquals("""{"x": 123}""", response) | ||
} | ||
} | ||
|
||
@Test | ||
fun testReceiveInputStream() = testWithEngine(MockEngine) { | ||
config { | ||
engine { | ||
addHandler { | ||
respond("""{"x": 123}""") | ||
} | ||
} | ||
} | ||
|
||
test { client -> | ||
val response = client.get("/").body<InputStream>() | ||
assertEquals("""{"x": 123}""", response.bufferedReader().readText()) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...ver/ktor-server-plugins/ktor-server-content-negotiation/jvm/src/DefaultIgnoredTypesJvm.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Copyright 2014-2022 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package io.ktor.server.plugins.contentnegotiation | ||
|
||
import io.ktor.http.* | ||
import io.ktor.utils.io.* | ||
import java.io.* | ||
import kotlin.reflect.* | ||
|
||
internal actual val DefaultIgnoredTypes: Set<KClass<*>> = | ||
mutableSetOf(HttpStatusCode::class, ByteReadChannel::class, InputStream::class) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...ver/ktor-server-plugins/ktor-server-content-negotiation/nix/src/DefaultIgnoredTypesNix.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* Copyright 2014-2022 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package io.ktor.server.plugins.contentnegotiation | ||
|
||
import io.ktor.http.* | ||
import io.ktor.utils.io.* | ||
import kotlin.reflect.* | ||
|
||
internal actual val DefaultIgnoredTypes: Set<KClass<*>> = | ||
mutableSetOf(HttpStatusCode::class, ByteReadChannel::class) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.