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