-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add OkHttpSupplier classes and implement for all clients (#65)
- Loading branch information
Showing
9 changed files
with
179 additions
and
36 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
43 changes: 43 additions & 0 deletions
43
src/main/kotlin/io/livekit/server/okhttp/OkHttpSupplier.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,43 @@ | ||
package io.livekit.server.okhttp | ||
|
||
import okhttp3.OkHttpClient | ||
import okhttp3.logging.HttpLoggingInterceptor | ||
import java.util.function.Consumer | ||
import java.util.function.Supplier | ||
|
||
/** | ||
* Holds an [OkHttpClient] object that is used as-is when supplying one. | ||
*/ | ||
class OkHttpHolder(val okHttp: OkHttpClient) : Supplier<OkHttpClient> { | ||
override fun get() = okHttp | ||
} | ||
|
||
/** | ||
* Lazily creates and caches an [OkHttpClient] object. | ||
*/ | ||
class OkHttpFactory( | ||
/** | ||
* When set to true, turns on body level logging. | ||
*/ | ||
val logging: Boolean = false, | ||
/** | ||
* Provide this if you wish to customize the http client | ||
* (e.g. proxy, timeout, certificate/auth settings) | ||
*/ | ||
val okHttpConfigurator: Consumer<OkHttpClient.Builder>? = null | ||
) : Supplier<OkHttpClient> { | ||
|
||
val okHttp by lazy { | ||
with(OkHttpClient.Builder()) { | ||
if (logging) { | ||
val loggingInterceptor = HttpLoggingInterceptor() | ||
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY) | ||
addInterceptor(loggingInterceptor) | ||
} | ||
okHttpConfigurator?.accept(this) | ||
build() | ||
} | ||
} | ||
|
||
override fun get() = okHttp | ||
} |
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
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