Skip to content

Commit

Permalink
Eliminate unreachable code warning
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Mashkov committed Oct 12, 2018
1 parent fa609bc commit 9861ea5
Showing 1 changed file with 14 additions and 11 deletions.
Expand Up @@ -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
}
}
}
Expand Down

0 comments on commit 9861ea5

Please sign in to comment.