Skip to content

Commit

Permalink
Merge pull request #43 from 47deg/javi-fix-forced-user-agent-js
Browse files Browse the repository at this point in the history
Fix forced user agent in js side
  • Loading branch information
Javier de Silóniz Sandino authored Nov 4, 2016
2 parents bb9441e + 75a9d51 commit 695bae0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ trait HttpRequestBuilderExtensionJS {
.withMethod(Method(rb.httpVerb.verb))
.withQueryParameters(rb.params.toSeq: _*)
.withHeader("content-type", "application/json")
.withHeader("user-agent", userAgent)
.withHeaders(rb.authHeader.toList: _*)
.withHeaders(rb.headers.toList: _*)

Expand Down
18 changes: 12 additions & 6 deletions github4s/shared/src/main/scala/github4s/HttpClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class HttpClient[C, M[_]](implicit urls: GithubApiUrls,
httpRbImpl.run[A](
httpRequestBuilder(buildURL(method))
.withAuth(accessToken)
.withHeaders(headers)
.withParams(params ++ pagination.fold(Map.empty[String, String])(p
Map("page" p.page.toString, "per_page" p.per_page.toString)))
)
Expand All @@ -134,14 +135,18 @@ class HttpClient[C, M[_]](implicit urls: GithubApiUrls,
headers: Map[String, String] = Map.empty,
data: String)(implicit D: Decoder[A]): M[GHResponse[A]] =
httpRbImpl.run[A](
httpRequestBuilder(buildURL(method)).patchMethod.withAuth(accessToken).withData(data))
httpRequestBuilder(buildURL(method)).patchMethod
.withAuth(accessToken)
.withHeaders(headers)
.withData(data))

def put[A](accessToken: Option[String] = None, method: String)(
implicit D: Decoder[A]): M[GHResponse[A]] =
def put[A](accessToken: Option[String] = None,
headers: Map[String, String] = Map(),
method: String)(implicit D: Decoder[A]): M[GHResponse[A]] =
httpRbImpl.run[A](
httpRequestBuilder(buildURL(method)).putMethod
.withAuth(accessToken)
.withHeaders(Map("Content-Length" "0")))
.withHeaders(Map("Content-Length" "0") ++ headers))

def post[A](
accessToken: Option[String] = None,
Expand Down Expand Up @@ -170,14 +175,15 @@ class HttpClient[C, M[_]](implicit urls: GithubApiUrls,
)(implicit D: Decoder[A]): M[GHResponse[A]] =
httpRbImpl.run[A](
httpRequestBuilder(url).postMethod
.withHeaders(Map("Accept" "application/json"))
.withHeaders(Map("Accept" "application/json") ++ headers)
.withData(data))

def delete[A](
accessToken: Option[String] = None,
method: String,
headers: Map[String, String] = Map.empty)(implicit D: Decoder[A]): M[GHResponse[A]] =
httpRbImpl.run[A](httpRequestBuilder(buildURL(method)).deleteMethod.withAuth(accessToken))
httpRbImpl.run[A](
httpRequestBuilder(buildURL(method)).deleteMethod.withHeaders(headers).withAuth(accessToken))

private def buildURL(method: String) = urls.baseUrl + method

Expand Down

0 comments on commit 695bae0

Please sign in to comment.