Akka Http Client - User-Agent header

2,008 views
Skip to first unread message

Marcin Gosk

unread,
Jan 7, 2015, 3:14:23 PM1/7/15
to akka...@googlegroups.com
Hey guys, is it possible to set custom header ("User-Agent") for akka streams


 val connection = Http().outgoingConnection("someServer", 443)
val request:HttpRequest = RequestBuilding.Get(s"/some/address.json")
// I want to add header here
//    request.addHeader(HttpHeader("User-Agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"))
Source.single(request).via(connection.flow).runWith(Sink.head).flatMap { response =>
response.status
match {
case status if status.isSuccess =>
val ticker = Unmarshal(response.entity).to[Ticker]
println(ticker)
ticker
case status =>
println(s"$status error:${response.toString}")
Future.
failed(new IOException(s"Token request failed with status ${response.status} and error ${response.entity}"))
}
}

André

unread,
Jan 8, 2015, 3:26:11 AM1/8/15
to akka...@googlegroups.com
Hi Marcin,

the user agent string is a config property and configured here.

Cheers
André

Grzegorz Wilkowicz

unread,
Jan 21, 2015, 6:51:24 AM1/21/15
to akka...@googlegroups.com
Hi,

What about other custom headers: X-Forwarded-For, SOAPAction, etc? How can I add them to the request?

André

unread,
Jan 21, 2015, 7:18:37 AM1/21/15
to akka...@googlegroups.com
The RequestBuilding trait is currently only used in tests.

you can use the methods on HttpMessage with RawHeaders instead:

HttpRequest(GET, "/some/address.json")
  .withHeaders(
    RawHeader("X-Forwarded-For", ...),
    RawHeader("SOAPAction", ...),
    ...)

Grzegorz Wilkowicz

unread,
Jan 21, 2015, 7:40:28 AM1/21/15
to akka...@googlegroups.com
Thanks.
Reply all
Reply to author
Forward
0 new messages