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 /okhttp-handler/src | |
parent | 53829db6555e91de8170b87ca8511d46adfc5442 (diff) | |
download | sttp-a9b1aea56e1940bfcbc748cd8d817f8872542dc6.tar.gz sttp-a9b1aea56e1940bfcbc748cd8d817f8872542dc6.tar.bz2 sttp-a9b1aea56e1940bfcbc748cd8d817f8872542dc6.zip |
Make OkHttp client not follow redirects by default
Diffstat (limited to 'okhttp-handler/src')
-rw-r--r-- | okhttp-handler/src/main/scala/com/softwaremill/sttp/okhttp/OkHttpClientHandler.scala | 13 |
1 files changed, 11 insertions, 2 deletions
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) |