diff options
author | adamw <adam@warski.org> | 2017-10-06 14:19:44 +0200 |
---|---|---|
committer | adamw <adam@warski.org> | 2017-10-06 14:19:44 +0200 |
commit | bb7abc189d9a5f079caa47a4508b5ae585dc8bcf (patch) | |
tree | 4d096e1b0c78156df923a7cf3282a86507b8ef8b /okhttp-backend/src/main | |
parent | 43baccc0edf12e8951c903d6697d7ee24a201e63 (diff) | |
download | sttp-bb7abc189d9a5f079caa47a4508b5ae585dc8bcf.tar.gz sttp-bb7abc189d9a5f079caa47a4508b5ae585dc8bcf.tar.bz2 sttp-bb7abc189d9a5f079caa47a4508b5ae585dc8bcf.zip |
#10: add proxy support
Diffstat (limited to 'okhttp-backend/src/main')
-rw-r--r-- | okhttp-backend/src/main/scala/com/softwaremill/sttp/okhttp/OkHttpClientHandler.scala | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/okhttp-backend/src/main/scala/com/softwaremill/sttp/okhttp/OkHttpClientHandler.scala b/okhttp-backend/src/main/scala/com/softwaremill/sttp/okhttp/OkHttpClientHandler.scala index 116878f..bebecac 100644 --- a/okhttp-backend/src/main/scala/com/softwaremill/sttp/okhttp/OkHttpClientHandler.scala +++ b/okhttp-backend/src/main/scala/com/softwaremill/sttp/okhttp/OkHttpClientHandler.scala @@ -148,14 +148,22 @@ abstract class OkHttpBackend[R[_], S](client: OkHttpClient, object OkHttpBackend { - private[okhttp] def defaultClient(readTimeout: Long, - connectionTimeout: Long): OkHttpClient = - new OkHttpClient.Builder() + private[okhttp] def defaultClient( + readTimeout: Long, + options: SttpBackendOptions): OkHttpClient = { + var clientBuilder = new OkHttpClient.Builder() .followRedirects(false) .followSslRedirects(false) - .connectTimeout(connectionTimeout, TimeUnit.MILLISECONDS) + .connectTimeout(options.connectionTimeout.toMillis, TimeUnit.MILLISECONDS) .readTimeout(readTimeout, TimeUnit.MILLISECONDS) - .build() + + clientBuilder = options.proxy match { + case None => clientBuilder + case Some(p) => clientBuilder.proxy(p.asJava) + } + + clientBuilder.build() + } private[okhttp] def updateClientIfCustomReadTimeout[T, S]( r: Request[T, S], @@ -192,12 +200,11 @@ object OkHttpSyncBackend { new FollowRedirectsBackend[Id, Nothing]( new OkHttpSyncBackend(client, closeClient)) - def apply( - connectionTimeout: FiniteDuration = SttpBackend.DefaultConnectionTimeout) + def apply(options: SttpBackendOptions = SttpBackendOptions.Default) : SttpBackend[Id, Nothing] = - OkHttpSyncBackend(OkHttpBackend.defaultClient(DefaultReadTimeout.toMillis, - connectionTimeout.toMillis), - closeClient = true) + OkHttpSyncBackend( + OkHttpBackend.defaultClient(DefaultReadTimeout.toMillis, options), + closeClient = true) def usingClient(client: OkHttpClient): SttpBackend[Id, Nothing] = OkHttpSyncBackend(client, closeClient = false) @@ -243,13 +250,12 @@ object OkHttpFutureBackend { new FollowRedirectsBackend[Future, Nothing]( new OkHttpFutureBackend(client, closeClient)) - def apply(connectionTimeout: FiniteDuration = - SttpBackend.DefaultConnectionTimeout)( + def apply(options: SttpBackendOptions = SttpBackendOptions.Default)( implicit ec: ExecutionContext = ExecutionContext.Implicits.global) : SttpBackend[Future, Nothing] = - OkHttpFutureBackend(OkHttpBackend.defaultClient(DefaultReadTimeout.toMillis, - connectionTimeout.toMillis), - closeClient = true) + OkHttpFutureBackend( + OkHttpBackend.defaultClient(DefaultReadTimeout.toMillis, options), + closeClient = true) def usingClient(client: OkHttpClient)(implicit ec: ExecutionContext = ExecutionContext.Implicits.global) |