eed3si9n / gigahorse

Gigahorse is an HTTP client for Scala with multiple backend support.
http://eed3si9n.com/gigahorse
Apache License 2.0
121 stars 25 forks source link

Setting ContentType with underlying ApacheHttpClient fails with IllegalArgumentException #81

Closed frosforever closed 2 years ago

frosforever commented 2 years ago

Version: 0.7.0 Scala Version: 2.12.16 Steps to replicate:

scala> import gigahorse._, support.apachehttp.Gigahorse
import gigahorse._
import support.apachehttp.Gigahorse

scala> Gigahorse.http(Gigahorse.config).run(Gigahorse.url("https://example.com").withContentType(MimeTypes.JSON, Gigahorse.utf8).post("foo"))
java.lang.IllegalArgumentException: MIME type may not contain reserved characters
  at gigahorse.shaded.apache.org.apache.http.util.Args.check(Args.java:36)
  at gigahorse.shaded.apache.org.apache.http.entity.ContentType.create(ContentType.java:229)
  at gigahorse.shaded.apache.org.apache.http.entity.ContentType.create(ContentType.java:241)
  at gigahorse.support.apachehttp.ApacheHttpClient.buildContentType$1(ApacheHttpClient.scala:106)
  at gigahorse.support.apachehttp.ApacheHttpClient.ct$1(ApacheHttpClient.scala:112)
  at gigahorse.support.apachehttp.ApacheHttpClient.buildProducer$1(ApacheHttpClient.scala:121)
  at gigahorse.support.apachehttp.ApacheHttpClient.buildRequestProducer(ApacheHttpClient.scala:127)
  at gigahorse.support.apachehttp.ApacheHttpClient.buildRequest(ApacheHttpClient.scala:79)
  at gigahorse.support.apachehttp.ApacheHttpClient.processFull(ApacheHttpClient.scala:158)
  at gigahorse.support.apachehttp.ApacheHttpClient.run(ApacheHttpClient.scala:66)
  ... 54 elided

I believe this may due to https://github.com/eed3si9n/gigahorse/blob/efc2e8e595f959e8b3ee02ec4b11a9d930a19162/apache-http/src/main/scala/gigahorse/support/apachehttp/ApacheHttpClient.scala#L106 calling ContentType.create(value) that will contain ; splitting the charset while it should instead be calling ContentType.create(mimeType, charset)?

Thanks in advance to reviewing this issue!

eed3si9n commented 2 years ago

@frosforever Thanks for the report. Would you like to send a PR for this?

frosforever commented 2 years ago

@eed3si9n submitted #82. thanks!