Skip to content

Commit

Permalink
Upgrade Unirest dependency to 4.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaavc committed Nov 28, 2023
1 parent becc75f commit d1cbec6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 31 deletions.
3 changes: 0 additions & 3 deletions core/build.sbt
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import Dependencies._

libraryDependencies ++= Seq(
ApacheHttpAsyncClient,
ApacheHttpClient,
ApacheHttpCore,
CirceCore,
ScalaCollectionCompat,
ScalaLogging,
Expand Down
33 changes: 7 additions & 26 deletions core/src/main/scala/com/velocidi/apso/http/W.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,23 @@ 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)

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) }
Expand Down
4 changes: 2 additions & 2 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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 }
}

0 comments on commit d1cbec6

Please sign in to comment.