Skip to content
This repository has been archived by the owner on Apr 4, 2022. It is now read-only.

Header application order (and/or special case for User-Agent) #113

Open
emanresusername opened this issue Nov 14, 2016 · 2 comments
Open

Comments

@emanresusername
Copy link
Contributor

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)
@hoffrocket
Copy link
Member

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")...

@wjlow
Copy link

wjlow commented Nov 29, 2017

Just a note that I encountered this myself too.

Ended up doing Http(url).copy(headers = List("User-Agent" -> "my-custom-user-agent")) instead

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants