Skip to content

Commit

Permalink
Use url with explicit port for proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
e5l committed Jan 10, 2020
1 parent 7a83a9a commit a0ac489
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
15 changes: 2 additions & 13 deletions ktor-client/ktor-client-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -81,26 +81,15 @@ kotlin.sourceSets {
if (!ideaActive) {
listOf("linuxX64Test", "mingwX64Test", "macosX64Test").map { getByName(it) }.forEach {
it.dependencies {
api(project(":ktor-client:ktor-client-curl"))
}
}

listOf("iosX64Test", "iosArm64Test", "iosArm64Test", "macosX64Test").map { getByName(it) }.forEach {
it.dependencies {
api(project(":ktor-client:ktor-client-ios"))
// api(project(":ktor-client:ktor-client-curl"))
}
}
} else {
posixTest {
dependencies {
api(project(":ktor-client:ktor-client-curl"))
// api(project(":ktor-client:ktor-client-curl"))
}
}
// darwinTest {
// dependencies {
// api(project(":ktor-client:ktor-client-ios"))
// }
// }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class ProxyTest : ClientLoader() {
}

test { client ->
val response = client.get<ProxyResponse>("http://google.com")
val expected = ProxyResponse("OK")
val response = client.get<ProxyResponse>("http://google.com/json")
val expected = ProxyResponse("ok")

assertEquals(expected, response)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package io.ktor.client.tests.utils.tests

import io.ktor.client.utils.*
import io.ktor.http.*
import io.ktor.network.sockets.*
import io.ktor.utils.io.*
Expand All @@ -16,7 +17,11 @@ suspend fun proxyHandler(socket: Socket) {

val response = when (statusLine) {
"GET http://google.com/ HTTP/1.1" -> buildResponse(HttpStatusCode.OK)
"GET http://google.com/json HTTP/1.1" -> buildResponse(HttpStatusCode.OK, "{'status': 'ok'}")
"GET http://google.com/json HTTP/1.1" -> buildResponse(
HttpStatusCode.OK, buildHeaders {
append(HttpHeaders.ContentType, ContentType.Application.Json)
}, "{\"status\": \"ok\"}"
)
else -> buildResponse(HttpStatusCode.BadRequest)
}

Expand All @@ -28,9 +33,16 @@ suspend fun proxyHandler(socket: Socket) {
}
}

private fun buildResponse(status: HttpStatusCode, body: String = "proxy") = buildString {
private fun buildResponse(
status: HttpStatusCode,
headers: Headers = Headers.Empty,
body: String = "proxy"
): String = buildString {
append("HTTP/1.1 ${status.value} ${status.description}\r\n")
append("Connection: close\r\n")
headers.forEach { key, values ->
append("$key: ${values.joinToString()}\r\n")
}
append("\r\n")
append(body)
}

0 comments on commit a0ac489

Please sign in to comment.