diff options
author | adamw <adam@warski.org> | 2017-08-31 15:52:57 +0200 |
---|---|---|
committer | adamw <adam@warski.org> | 2017-08-31 15:52:57 +0200 |
commit | a9b1aea56e1940bfcbc748cd8d817f8872542dc6 (patch) | |
tree | 601901e1f68c74321017c0e763e2683712783ab0 | |
parent | 53829db6555e91de8170b87ca8511d46adfc5442 (diff) | |
download | sttp-a9b1aea56e1940bfcbc748cd8d817f8872542dc6.tar.gz sttp-a9b1aea56e1940bfcbc748cd8d817f8872542dc6.tar.bz2 sttp-a9b1aea56e1940bfcbc748cd8d817f8872542dc6.zip |
Make OkHttp client not follow redirects by default
2 files changed, 14 insertions, 4 deletions
diff --git a/okhttp-handler/monix/src/main/scala/com/softwaremill/sttp/okhttp/monix/OkHttpMonixHandler.scala b/okhttp-handler/monix/src/main/scala/com/softwaremill/sttp/okhttp/monix/OkHttpMonixHandler.scala index 1ffd372..7a5c7cb 100644 --- a/okhttp-handler/monix/src/main/scala/com/softwaremill/sttp/okhttp/monix/OkHttpMonixHandler.scala +++ b/okhttp-handler/monix/src/main/scala/com/softwaremill/sttp/okhttp/monix/OkHttpMonixHandler.scala @@ -4,7 +4,7 @@ import java.nio.ByteBuffer import java.util.concurrent.ArrayBlockingQueue import com.softwaremill.sttp.{SttpHandler, _} -import com.softwaremill.sttp.okhttp.OkHttpAsyncHandler +import com.softwaremill.sttp.okhttp.{OkHttpAsyncHandler, OkHttpHandler} import monix.eval.Task import monix.execution.Ack.Continue import monix.execution.{Ack, Cancelable, Scheduler} @@ -77,7 +77,8 @@ class OkHttpMonixHandler private (client: OkHttpClient)(implicit s: Scheduler) } object OkHttpMonixHandler { - def apply(okhttpClient: OkHttpClient = new OkHttpClient())( + def apply( + okhttpClient: OkHttpClient = OkHttpHandler.buildClientNoRedirects())( implicit s: Scheduler = Scheduler.Implicits.global) : SttpHandler[Task, Observable[ByteBuffer]] = new OkHttpMonixHandler(okhttpClient)(s) diff --git a/okhttp-handler/src/main/scala/com/softwaremill/sttp/okhttp/OkHttpClientHandler.scala b/okhttp-handler/src/main/scala/com/softwaremill/sttp/okhttp/OkHttpClientHandler.scala index eca7777..295ca2a 100644 --- a/okhttp-handler/src/main/scala/com/softwaremill/sttp/okhttp/OkHttpClientHandler.scala +++ b/okhttp-handler/src/main/scala/com/softwaremill/sttp/okhttp/OkHttpClientHandler.scala @@ -136,6 +136,14 @@ abstract class OkHttpHandler[R[_], S](client: OkHttpClient) Failure(new IllegalStateException("Streaming isn't supported")) } +object OkHttpHandler { + def buildClientNoRedirects(): OkHttpClient = + new OkHttpClient.Builder() + .followRedirects(false) + .followSslRedirects(false) + .build() +} + class OkHttpSyncHandler private (client: OkHttpClient) extends OkHttpHandler[Id, Nothing](client) { override protected def doSend[T](r: Request[T, Nothing]): Response[T] = { @@ -148,7 +156,7 @@ class OkHttpSyncHandler private (client: OkHttpClient) } object OkHttpSyncHandler { - def apply(okhttpClient: OkHttpClient = new OkHttpClient()) + def apply(okhttpClient: OkHttpClient = OkHttpHandler.buildClientNoRedirects()) : SttpHandler[Id, Nothing] = new OkHttpSyncHandler(okhttpClient) } @@ -184,7 +192,8 @@ class OkHttpFutureHandler private (client: OkHttpClient)( extends OkHttpAsyncHandler[Future, Nothing](client, new FutureMonad) {} object OkHttpFutureHandler { - def apply(okhttpClient: OkHttpClient = new OkHttpClient())( + def apply( + okhttpClient: OkHttpClient = OkHttpHandler.buildClientNoRedirects())( implicit ec: ExecutionContext = ExecutionContext.Implicits.global) : SttpHandler[Future, Nothing] = new OkHttpFutureHandler(okhttpClient) |