From d1cbec6888d526154680b2639425f0fbc96d787b Mon Sep 17 00:00:00 2001 From: rafaavc Date: Tue, 28 Nov 2023 18:17:59 +0000 Subject: [PATCH] Upgrade Unirest dependency to 4.2.0 --- core/build.sbt | 3 -- .../main/scala/com/velocidi/apso/http/W.scala | 33 ++++--------------- project/Dependencies.scala | 4 +-- 3 files changed, 9 insertions(+), 31 deletions(-) diff --git a/core/build.sbt b/core/build.sbt index 2d496098..072c0a18 100644 --- a/core/build.sbt +++ b/core/build.sbt @@ -1,9 +1,6 @@ import Dependencies._ libraryDependencies ++= Seq( - ApacheHttpAsyncClient, - ApacheHttpClient, - ApacheHttpCore, CirceCore, ScalaCollectionCompat, ScalaLogging, diff --git a/core/src/main/scala/com/velocidi/apso/http/W.scala b/core/src/main/scala/com/velocidi/apso/http/W.scala index 0487c17f..62cef9d5 100644 --- a/core/src/main/scala/com/velocidi/apso/http/W.scala +++ b/core/src/main/scala/com/velocidi/apso/http/W.scala @@ -2,14 +2,9 @@ package com.velocidi.apso.http import scala.concurrent.duration._ -import com.mashape.unirest.http.{HttpResponse, Unirest} -import com.mashape.unirest.request.{HttpRequest, HttpRequestWithBody} import com.typesafe.scalalogging.Logger import io.circe.Json -import org.apache.http.client.config.{CookieSpecs, RequestConfig} -import org.apache.http.impl.client.DefaultRedirectStrategy -import org.apache.http.impl.nio.client.HttpAsyncClients -import org.apache.http.protocol.HttpContext +import kong.unirest.core.{CookieSpecs, HttpRequest, HttpRequestWithBody, HttpResponse, Unirest} object W { case class Timeout(duration: FiniteDuration) @@ -17,27 +12,13 @@ object W { private[this] lazy val logger = Logger("W") private[this] lazy val defaultTimeout = Timeout(10.seconds) - private[this] object NeverRedirectStrategy extends DefaultRedirectStrategy { - override def isRedirected( - request: org.apache.http.HttpRequest, - response: org.apache.http.HttpResponse, - context: HttpContext - ) = false - } - - private[this] val reqConfig = RequestConfig.custom - .setCookieSpec(CookieSpecs.STANDARD) - .build() - - Unirest.setAsyncHttpClient( - HttpAsyncClients.custom - .setDefaultRequestConfig(reqConfig) - .setRedirectStrategy(NeverRedirectStrategy) - .disableCookieManagement() - .build() - ) + Unirest + .config() + .cookieSpec(CookieSpecs.STANDARD) + .followRedirects(false) + .enableCookieManagement(false) - implicit private[this] class RichHttpRequest(val req: HttpRequest) { + implicit private[this] class RichHttpRequest[T <: HttpRequest[T]](val req: HttpRequest[T]) { def headers(headers: Map[String, Seq[String]]) = { headers.foldLeft(req) { case (acc, (k, vs)) => vs.foldLeft(acc) { (acc2, v) => acc2.header(k, v) } diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 77b3ee73..a8ab90ac 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -28,7 +28,7 @@ object Dependencies { val Squants = "1.8.3" val SshJ = "0.37.0" val TypesafeConfig = "1.4.3" - val UnirestJava = "1.4.9" + val UnirestJava = "4.2.0" } // scalafmt: { maxColumn = 200 } @@ -83,6 +83,6 @@ object Dependencies { val Squants = "org.typelevel" %% "squants" % Versions.Squants val SshJ = "com.hierynomus" % "sshj" % Versions.SshJ val TypesafeConfig = "com.typesafe" % "config" % Versions.TypesafeConfig - val UnirestJava = "com.mashape.unirest" % "unirest-java" % Versions.UnirestJava + val UnirestJava = "com.konghq" % "unirest-java-core" % Versions.UnirestJava // scalafmt: { maxColumn = 120 } }