-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KTOR-2822 Change
HttpReceivePipeline
context to Unit (#2522)
Otherwise it's impossible to modify response, since context has its own instance of response.
- Loading branch information
Showing
9 changed files
with
80 additions
and
30 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
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
49 changes: 49 additions & 0 deletions
49
ktor-client/ktor-client-tests/common/test/io/ktor/client/tests/ClientPipelinesTest.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,49 @@ | ||
/* | ||
* Copyright 2014-2019 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.request.* | ||
import io.ktor.client.statement.* | ||
import io.ktor.client.tests.utils.* | ||
import io.ktor.client.utils.* | ||
import io.ktor.http.* | ||
import io.ktor.util.date.* | ||
import io.ktor.utils.io.* | ||
import kotlin.coroutines.* | ||
import kotlin.test.* | ||
|
||
class ClientPipelinesTest : ClientLoader() { | ||
@Test | ||
fun testCanAddHeaders() = clientTests { | ||
config { | ||
install("attr-test") { | ||
receivePipeline.intercept(HttpReceivePipeline.State) { response -> | ||
val headers = buildHeaders { | ||
appendAll(response.headers) | ||
append(HttpHeaders.WWWAuthenticate, "Bearer") | ||
} | ||
proceedWith( | ||
object : HttpResponse() { | ||
override val call: HttpClientCall = response.call | ||
override val status: HttpStatusCode = response.status | ||
override val version: HttpProtocolVersion = response.version | ||
override val requestTime: GMTDate = response.requestTime | ||
override val responseTime: GMTDate = response.responseTime | ||
override val content: ByteReadChannel = response.content | ||
override val headers get() = headers | ||
override val coroutineContext: CoroutineContext = response.coroutineContext | ||
} | ||
) | ||
} | ||
} | ||
} | ||
|
||
test { client -> | ||
val response = client.get("$TEST_SERVER/content/hello") | ||
assertEquals("Bearer", response.headers[HttpHeaders.WWWAuthenticate]) | ||
} | ||
} | ||
} |
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