aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoradamw <adam@warski.org>2017-08-31 15:52:57 +0200
committeradamw <adam@warski.org>2017-08-31 15:52:57 +0200
commita9b1aea56e1940bfcbc748cd8d817f8872542dc6 (patch)
tree601901e1f68c74321017c0e763e2683712783ab0
parent53829db6555e91de8170b87ca8511d46adfc5442 (diff)
downloadsttp-a9b1aea56e1940bfcbc748cd8d817f8872542dc6.tar.gz
sttp-a9b1aea56e1940bfcbc748cd8d817f8872542dc6.tar.bz2
sttp-a9b1aea56e1940bfcbc748cd8d817f8872542dc6.zip
Make OkHttp client not follow redirects by default
-rw-r--r--okhttp-handler/monix/src/main/scala/com/softwaremill/sttp/okhttp/monix/OkHttpMonixHandler.scala5
-rw-r--r--okhttp-handler/src/main/scala/com/softwaremill/sttp/okhttp/OkHttpClientHandler.scala13
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)