From 29469ffc7ade94a21d205dcbcc03f400678a314b Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Mon, 22 Aug 2016 00:40:01 +0200 Subject: [PATCH] Add okhttp plugin --- build.sbt | 12 +++++++++++- .../coursier/cache/protocol/HttpHandler.scala | 17 +++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 okhttp/src/main/scala/coursier/cache/protocol/HttpHandler.scala diff --git a/build.sbt b/build.sbt index d71559f98..4b00cd505 100644 --- a/build.sbt +++ b/build.sbt @@ -570,8 +570,18 @@ lazy val `http-server` = project ) ) +lazy val okhttp = project + .dependsOn(cache) + .settings(commonSettings) + .settings( + name := "coursier-okhttp", + libraryDependencies ++= Seq( + "com.squareup.okhttp" % "okhttp-urlconnection" % "2.7.5" + ) + ) + lazy val `coursier` = project.in(file(".")) - .aggregate(coreJvm, coreJs, `fetch-js`, testsJvm, testsJs, cache, bootstrap, cli, plugin, web, doc, `http-server`) + .aggregate(coreJvm, coreJs, `fetch-js`, testsJvm, testsJs, cache, bootstrap, cli, plugin, web, doc, `http-server`, okhttp) .settings(commonSettings) .settings(noPublishSettings) .settings(releaseSettings) diff --git a/okhttp/src/main/scala/coursier/cache/protocol/HttpHandler.scala b/okhttp/src/main/scala/coursier/cache/protocol/HttpHandler.scala new file mode 100644 index 000000000..89a0e4419 --- /dev/null +++ b/okhttp/src/main/scala/coursier/cache/protocol/HttpHandler.scala @@ -0,0 +1,17 @@ +package coursier.cache.protocol + +import java.net.{URLStreamHandler, URLStreamHandlerFactory} + +import com.squareup.okhttp.{OkHttpClient, OkUrlFactory} + +object HttpHandler { + lazy val okHttpClient = new OkHttpClient + lazy val okHttpFactory = new OkUrlFactory(okHttpClient) +} + +class HttpHandler extends URLStreamHandlerFactory { + def createURLStreamHandler(protocol: String): URLStreamHandler = + HttpHandler.okHttpFactory.createURLStreamHandler(protocol) +} + +class HttpsHandler extends HttpHandler