Akka-http: How to get the User-Agent header from the request header?

I tried to extract the User-agent header from the Request-Header , I tried this:

  headerValue(extractUserAgent) { userAgent => } def extractUserAgent: HttpHeader => Option[String] = { case h: `User-Agent` => Some(h.) case x => None } 

I am stuck in the string Some(h.) , I thought it could give some String values ​​as a User-agent there, but not string values ​​inside It.Help please !!

+3
source share
2 answers

I think you should read the documentation, it is written correctly, and you can find your solution there:

http://doc.akka.io/docs/akka-stream-and-http-experimental/1.0/scala/http/common/http-model.html

+1
source

I finally got a solution

 path("test") { get { headerValueByName("User-Agent") { header => println(">>>>>>>>>>>>>>>>>>>>>>" + header) complete(s"""{ "User-Agent" : "${header}" }""") } } } 
+1
source

All Articles