scalaj-http
scalaj-http copied to clipboard
Header application order (and/or special case for User-Agent)
I noticed that here the headers are applied in reverse order. This may well have further reaching implications, but it seems to do the wrong (or at least an unexpected) thing in the following scenario
import scalaj.http._
Http("http://user.agent").header("User-Agent", "i-expect-this-to-override-the-default")
// the User-Agent the server receives will still be the default (scalaj-http/1.0)
Thanks. I vaguely remember that there was a reason I did that, but clearly the behavior is wrong. I'll investigate further and fix.
In the meantime, If you need a work around for setting the User-Agent
you can create a new builder:
object MyHttp extends BaseHttp (
proxyConfig: Option[Proxy] = None,
options: Seq[HttpOptions.HttpOption] = HttpConstants.defaultOptions,
charset: String = HttpConstants.utf8,
sendBufferSize: Int = 4096,
userAgent: String = "my-custom-user-agent",
compress: Boolean = true
)
and then use MyHttp("http://user.agent")...
Just a note that I encountered this myself too.
Ended up doing Http(url).copy(headers = List("User-Agent" -> "my-custom-user-agent"))
instead