Skip to content

Commit 33a2c60

Browse files
committed
convert httpoptions to seq
1 parent 4dea5e9 commit 33a2c60

2 files changed

Lines changed: 10 additions & 15 deletions

File tree

cli/src/test/scala/com/codacy/analysis/cli/configuration/CLIConfigurationSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class CLIConfigurationSpec extends Specification with NoLanguageFeatures {
5151
commitUuid = commitUuid,
5252
extras = ExtraOptions(analyser = Analyser.defaultAnalyser.name))
5353
private val defaultEnvironment = new Environment(Map.empty)
54-
private val httpHelper = new HttpHelper(remoteUrl, Map.empty)
54+
private val httpHelper = new HttpHelper(remoteUrl, Map.empty, false)
5555

5656
private val noRemoteConfigCodacyClient =
5757
new CodacyClient(apiCredentials, httpHelper)(ExecutionContext.global) {

core/src/main/scala/com/codacy/analysis/core/utils/HttpHelper.scala

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,24 @@ import io.circe.parser.parse
44
import io.circe.{Json, ParsingFailure}
55
import scalaj.http.{Http, HttpRequest, HttpResponse, HttpOptions}
66

7-
class HttpHelper(apiUrl: String, extraHeaders: Map[String, String], allowUnsafeSSL: Boolean = false) {
7+
class HttpHelper(apiUrl: String, extraHeaders: Map[String, String], allowUnsafeSSL: Boolean) {
88

99
private lazy val connectionTimeoutMs = 2000
1010
private lazy val readTimeoutMs = 5000
1111

1212
private val remoteUrl = apiUrl + "/2.0"
1313

14+
private def httpOptions = if (allowUnsafeSSL) Seq(HttpOptions.allowUnsafeSSL) else Seq.empty
15+
1416
def get(endpoint: String): Either[ParsingFailure, Json] = {
1517
val headers: Map[String, String] = Map("Content-Type" -> "application/json") ++ extraHeaders
1618

1719
val response: HttpResponse[String] =
18-
if (allowUnsafeSSL)
19-
Http(s"$remoteUrl$endpoint")
20-
.headers(headers)
21-
.timeout(connectionTimeoutMs, readTimeoutMs)
22-
.options(HttpOptions.allowUnsafeSSL)
23-
.asString
24-
else
25-
Http(s"$remoteUrl$endpoint").headers(headers).timeout(connectionTimeoutMs, readTimeoutMs).asString
20+
Http(s"$remoteUrl$endpoint")
21+
.headers(headers)
22+
.timeout(connectionTimeoutMs, readTimeoutMs)
23+
.options(httpOptions)
24+
.asString
2625

2726
parse(response.body)
2827

@@ -34,11 +33,7 @@ class HttpHelper(apiUrl: String, extraHeaders: Map[String, String], allowUnsafeS
3433
} ++ extraHeaders
3534

3635
val request: HttpRequest = dataOpt.map { data =>
37-
if (allowUnsafeSSL) {
38-
Http(s"$remoteUrl$endpoint").options(HttpOptions.allowUnsafeSSL).postData(data.toString)
39-
} else {
40-
Http(s"$remoteUrl$endpoint").postData(data.toString)
41-
}
36+
Http(s"$remoteUrl$endpoint").options(httpOptions).postData(data.toString)
4237

4338
}.getOrElse(Http(s"$remoteUrl$endpoint"))
4439
.method("POST")

0 commit comments

Comments
 (0)