Skip to content
Permalink
Browse files

Eliminate unreachable code warning

  • Loading branch information...
cy6erGn0m committed Oct 12, 2018
1 parent fa609bc commit 9861ea50b6a377ae4eb62f7d19d45214ec27aa1d
Showing with 14 additions and 11 deletions.
  1. +14 −11 ktor-client/ktor-client-core/src/io/ktor/client/features/HttpRedirect.kt
@@ -20,20 +20,23 @@ class HttpRedirect {

override fun install(feature: HttpRedirect, scope: HttpClient) {
scope.feature(HttpSend)!!.intercept { origin ->
if (!origin.response.status.isRedirect()) return@intercept origin
handleCall(origin)
}
}

private suspend fun Sender.handleCall(origin: HttpClientCall): HttpClientCall {
if (!origin.response.status.isRedirect()) return origin

var call = origin
while (true) {
val location = call.response.headers[HttpHeaders.Location]
var call = origin
while (true) {
val location = call.response.headers[HttpHeaders.Location]

call = execute(HttpRequestBuilder().apply {
takeFrom(origin.request)
location?.let { url.takeFrom(it) }
})
call = execute(HttpRequestBuilder().apply {
takeFrom(origin.request)
location?.let { url.takeFrom(it) }
})

if (!call.response.status.isRedirect()) return@intercept call
}
return@intercept call
if (!call.response.status.isRedirect()) return call
}
}
}

0 comments on commit 9861ea5

Please sign in to comment.
You can’t perform that action at this time.