File tree 2 files changed +8
-10
lines changed
ktor-client/ktor-client-cio/jvmAndNix/src/io/ktor/client/engine/cio
2 files changed +8
-10
lines changed Original file line number Diff line number Diff line change @@ -177,9 +177,13 @@ internal class Endpoint(
177
177
if (proxy?.type == ProxyType .HTTP ) {
178
178
startTunnel(requestData, connection.output, connection.input)
179
179
}
180
+ val realAddress = when (proxy) {
181
+ null -> address
182
+ else -> InetSocketAddress (requestData.url.host, requestData.url.port)
183
+ }
180
184
val tlsSocket = connection.tls(coroutineContext) {
181
185
takeFrom(config.https)
182
- serverName = serverName ? : address .hostname
186
+ serverName = serverName ? : realAddress .hostname
183
187
}
184
188
return tlsSocket.connection()
185
189
} catch (cause: Throwable ) {
Original file line number Diff line number Diff line change @@ -173,15 +173,9 @@ internal suspend fun startTunnel(
173
173
val builder = RequestResponseBuilder ()
174
174
175
175
try {
176
- builder.requestLine(HttpMethod (" CONNECT" ), request.url.hostWithPort, HttpProtocolVersion .HTTP_1_1 .toString())
177
- // this will only add the port to the host header if the port is non-standard for the protocol
178
- val host = if (request.url.protocol.defaultPort == request.url.port) {
179
- request.url.host
180
- } else {
181
- request.url.hostWithPort
182
- }
183
-
184
- builder.headerLine(HttpHeaders .Host , host)
176
+ val hostWithPort = request.url.hostWithPort
177
+ builder.requestLine(HttpMethod (" CONNECT" ), hostWithPort, HttpProtocolVersion .HTTP_1_1 .toString())
178
+ builder.headerLine(HttpHeaders .Host , hostWithPort)
185
179
builder.headerLine(" Proxy-Connection" , " Keep-Alive" ) // For HTTP/1.0 proxies like Squid.
186
180
request.headers[HttpHeaders .UserAgent ]?.let {
187
181
builder.headerLine(HttpHeaders .UserAgent , it)
You can’t perform that action at this time.
0 commit comments