@@ -2,22 +2,29 @@ package com.codacy.analysis.core.utils
22
33import io .circe .parser .parse
44import io .circe .{Json , ParsingFailure }
5- import scalaj .http .{Http , HttpRequest , HttpResponse }
5+ import scalaj .http .{Http , HttpRequest , HttpResponse , HttpOptions }
66
7- class HttpHelper (apiUrl : String , extraHeaders : Map [String , String ]) {
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- 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
1925
2026 parse(response.body)
27+
2128 }
2229
2330 def post (endpoint : String , dataOpt : Option [Json ] = None ): Either [ParsingFailure , Json ] = {
@@ -26,7 +33,8 @@ class HttpHelper(apiUrl: String, extraHeaders: Map[String, String]) {
2633 } ++ extraHeaders
2734
2835 val request : HttpRequest = dataOpt.map { data =>
29- Http (s " $remoteUrl$endpoint" ).postData(data.toString)
36+ Http (s " $remoteUrl$endpoint" ).options(httpOptions).postData(data.toString)
37+
3038 }.getOrElse(Http (s " $remoteUrl$endpoint" ))
3139 .method(" POST" )
3240 .headers(headers)
0 commit comments