Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Treat malformed HTTP responses as connection errors #63

Merged
merged 3 commits into from
Sep 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/main/kotlin/tech/relaycorp/poweb/PoWebClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import kotlinx.coroutines.channels.ClosedReceiveChannelException
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.FlowCollector
import kotlinx.coroutines.flow.flow
import okhttp3.OkHttpClient
import tech.relaycorp.poweb.handshake.Challenge
import tech.relaycorp.poweb.handshake.InvalidChallengeException
import tech.relaycorp.poweb.handshake.Response
Expand Down Expand Up @@ -55,7 +56,14 @@ public class PoWebClient internal constructor(
internal val hostName: String,
internal val port: Int,
internal val useTls: Boolean,
ktorEngine: HttpClientEngine = OkHttp.create {}
ktorEngine: HttpClientEngine = OkHttp.create {
// By default, OkHTTP would throw an IOException when an illegal HTTP response is returned.
// Enabling retryOnConnectionFailure would treat that as a connection failure and try again,
// throwing a java.net.ConnectException if it still fails -- And ConnectException is a
// more reliable exception to handle when something like this goes wrong. See:
// https://github.com/relaycorp/relaynet-poweb-jvm/issues/61
preconfigured = OkHttpClient.Builder().retryOnConnectionFailure(true).build()
}
) : Closeable {
internal var ktorClient = HttpClient(ktorEngine) {
install(WebSockets)
Expand Down