-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: SDK-1568 expose okhttp client as a configuration in sdk core
- Loading branch information
Showing
5 changed files
with
241 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
core/src/main/kotlin/com/expediagroup/sdk/core/client/CompositeOkHttpEventListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
package com.expediagroup.sdk.core.client | ||
|
||
import okhttp3.Call | ||
import okhttp3.EventListener | ||
import okhttp3.Response | ||
import java.io.IOException | ||
|
||
// A CompositeEventListener that takes multiple event listener factories | ||
class CompositeOkHttpEventListener private constructor(private val listeners: List<EventListener>) : EventListener() { | ||
|
||
companion object Factory : EventListener.Factory { | ||
private lateinit var factories: Array<out EventListener.Factory> | ||
|
||
fun initialize(vararg factories: EventListener.Factory) { | ||
this.factories = factories | ||
} | ||
|
||
override fun create(call: Call): EventListener { | ||
val listeners = factories.map { it.create(call) } | ||
return CompositeOkHttpEventListener(listeners) | ||
} | ||
} | ||
|
||
override fun callStart(call: Call) { | ||
listeners.forEach { it.callStart(call) } | ||
} | ||
|
||
override fun callEnd(call: Call) { | ||
listeners.forEach { it.callEnd(call) } | ||
} | ||
|
||
override fun callFailed(call: Call, ioe: IOException) { | ||
listeners.forEach { it.callFailed(call, ioe) } | ||
} | ||
|
||
override fun canceled(call: Call) { | ||
listeners.forEach { it.canceled(call) } | ||
} | ||
|
||
override fun connectStart(call: Call, inetSocketAddress: java.net.InetSocketAddress, proxy: java.net.Proxy) { | ||
listeners.forEach { it.connectStart(call, inetSocketAddress, proxy) } | ||
} | ||
|
||
override fun connectEnd(call: Call, inetSocketAddress: java.net.InetSocketAddress, proxy: java.net.Proxy, protocol: okhttp3.Protocol?) { | ||
listeners.forEach { it.connectEnd(call, inetSocketAddress, proxy, protocol) } | ||
} | ||
|
||
override fun connectFailed(call: Call, inetSocketAddress: java.net.InetSocketAddress, proxy: java.net.Proxy, protocol: okhttp3.Protocol?, ioe: IOException) { | ||
listeners.forEach { it.connectFailed(call, inetSocketAddress, proxy, protocol, ioe) } | ||
} | ||
|
||
override fun requestHeadersStart(call: Call) { | ||
listeners.forEach { it.requestHeadersStart(call) } | ||
} | ||
|
||
override fun requestHeadersEnd(call: Call, request: okhttp3.Request) { | ||
listeners.forEach { it.requestHeadersEnd(call, request) } | ||
} | ||
|
||
override fun requestBodyStart(call: Call) { | ||
listeners.forEach { it.requestBodyStart(call) } | ||
} | ||
|
||
override fun requestBodyEnd(call: Call, byteCount: Long) { | ||
listeners.forEach { it.requestBodyEnd(call, byteCount) } | ||
} | ||
|
||
override fun responseHeadersStart(call: Call) { | ||
listeners.forEach { it.responseHeadersStart(call) } | ||
} | ||
|
||
override fun responseHeadersEnd(call: Call, response: okhttp3.Response) { | ||
listeners.forEach { it.responseHeadersEnd(call, response) } | ||
} | ||
|
||
override fun responseBodyStart(call: Call) { | ||
listeners.forEach { it.responseBodyStart(call) } | ||
} | ||
|
||
override fun responseBodyEnd(call: Call, byteCount: Long) { | ||
listeners.forEach { it.responseBodyEnd(call, byteCount) } | ||
} | ||
|
||
override fun responseFailed(call: Call, ioe: IOException) { | ||
listeners.forEach { it.responseFailed(call, ioe) } | ||
} | ||
|
||
override fun proxySelectStart(call: Call, url: okhttp3.HttpUrl) { | ||
listeners.forEach { it.proxySelectStart(call, url) } | ||
} | ||
|
||
override fun proxySelectEnd(call: Call, url: okhttp3.HttpUrl, proxies: List<java.net.Proxy>) { | ||
listeners.forEach { it.proxySelectEnd(call, url, proxies) } | ||
} | ||
|
||
override fun dnsStart(call: Call, domainName: String) { | ||
listeners.forEach { it.dnsStart(call, domainName) } | ||
} | ||
|
||
override fun dnsEnd(call: Call, domainName: String, inetAddressList: List<java.net.InetAddress>) { | ||
listeners.forEach { it.dnsEnd(call, domainName, inetAddressList) } | ||
} | ||
|
||
override fun connectionAcquired(call: Call, connection: okhttp3.Connection) { | ||
listeners.forEach { it.connectionAcquired(call, connection) } | ||
} | ||
|
||
override fun connectionReleased(call: Call, connection: okhttp3.Connection) { | ||
listeners.forEach { it.connectionReleased(call, connection) } | ||
} | ||
|
||
override fun secureConnectStart(call: Call) { | ||
listeners.forEach { it.secureConnectStart(call) } | ||
} | ||
|
||
override fun secureConnectEnd(call: Call, handshake: okhttp3.Handshake?) { | ||
listeners.forEach { it.secureConnectEnd(call, handshake) } | ||
} | ||
|
||
override fun requestFailed(call: Call, ioe: IOException) { | ||
listeners.forEach { it.requestFailed(call, ioe) } | ||
} | ||
|
||
override fun cacheHit(call: Call, response: Response) { | ||
listeners.forEach { it.cacheHit(call, response) } | ||
} | ||
|
||
override fun cacheMiss(call: Call) { | ||
listeners.forEach { it.cacheMiss(call) } | ||
} | ||
|
||
override fun cacheConditionalHit(call: Call, response: Response) { | ||
listeners.forEach { it.cacheConditionalHit(call, response) } | ||
} | ||
|
||
override fun satisfactionFailure(call: Call, response: Response) { | ||
listeners.forEach { it.satisfactionFailure(call, response) } | ||
} | ||
|
||
} |
Oops, something went wrong.