aboutsummaryrefslogtreecommitdiff
path: root/async-http-client-backend/src/main/scala/com
diff options
context:
space:
mode:
authoradamw <adam@warski.org>2017-10-06 14:19:44 +0200
committeradamw <adam@warski.org>2017-10-06 14:19:44 +0200
commitbb7abc189d9a5f079caa47a4508b5ae585dc8bcf (patch)
tree4d096e1b0c78156df923a7cf3282a86507b8ef8b /async-http-client-backend/src/main/scala/com
parent43baccc0edf12e8951c903d6697d7ee24a201e63 (diff)
downloadsttp-bb7abc189d9a5f079caa47a4508b5ae585dc8bcf.tar.gz
sttp-bb7abc189d9a5f079caa47a4508b5ae585dc8bcf.tar.bz2
sttp-bb7abc189d9a5f079caa47a4508b5ae585dc8bcf.zip
#10: add proxy support
Diffstat (limited to 'async-http-client-backend/src/main/scala/com')
-rw-r--r--async-http-client-backend/src/main/scala/com/softwaremill/sttp/asynchttpclient/AsyncHttpClientBackend.scala23
1 files changed, 16 insertions, 7 deletions
diff --git a/async-http-client-backend/src/main/scala/com/softwaremill/sttp/asynchttpclient/AsyncHttpClientBackend.scala b/async-http-client-backend/src/main/scala/com/softwaremill/sttp/asynchttpclient/AsyncHttpClientBackend.scala
index 87a3965..a19dc1a 100644
--- a/async-http-client-backend/src/main/scala/com/softwaremill/sttp/asynchttpclient/AsyncHttpClientBackend.scala
+++ b/async-http-client-backend/src/main/scala/com/softwaremill/sttp/asynchttpclient/AsyncHttpClientBackend.scala
@@ -8,6 +8,7 @@ import com.softwaremill.sttp.ResponseAs.EagerResponseHandler
import com.softwaremill.sttp._
import org.asynchttpclient.AsyncHandler.State
import org.asynchttpclient.handler.StreamedAsyncHandler
+import org.asynchttpclient.proxy.ProxyServer
import org.asynchttpclient.request.body.multipart.{
ByteArrayPart,
FilePart,
@@ -17,8 +18,8 @@ import org.asynchttpclient.{
AsyncCompletionHandler,
AsyncHandler,
AsyncHttpClient,
- DefaultAsyncHttpClientConfig,
DefaultAsyncHttpClient,
+ DefaultAsyncHttpClientConfig,
HttpResponseBodyPart,
HttpResponseHeaders,
HttpResponseStatus,
@@ -298,12 +299,20 @@ abstract class AsyncHttpClientBackend[R[_], S](asyncHttpClient: AsyncHttpClient,
object AsyncHttpClientBackend {
private[asynchttpclient] def defaultClient(
- connectionTimeout: Int): AsyncHttpClient =
- new DefaultAsyncHttpClient(
- new DefaultAsyncHttpClientConfig.Builder()
- .setConnectTimeout(connectionTimeout)
- .build()
- )
+ options: SttpBackendOptions): AsyncHttpClient = {
+
+ var configBuilder = new DefaultAsyncHttpClientConfig.Builder()
+ .setConnectTimeout(options.connectionTimeout.toMillis.toInt)
+
+ configBuilder = options.proxy match {
+ case None => configBuilder
+ case Some(p) =>
+ configBuilder.setProxyServer(
+ new ProxyServer.Builder(p.host, p.port).build())
+ }
+
+ new DefaultAsyncHttpClient(configBuilder.build())
+ }
}
object EmptyPublisher extends Publisher[ByteBuffer] {