I have some Scala code which retrieves the value from a variable in the http header.
println("header auth: ", request.headers.get(myParam))
This shows the following in the console
(header auth: ,Some(xxx_made_up_stuff_xxx))
What I actually need is the value inside Some()
I have tried toString()
but that did not change anything.
I am very very new to Scala, so apologies is this is very basic.
request.headers.get(myParam)
returns on Option
. To get the value inside you can use .getOrElse
, .fold
or the unsafe .get
:
request.headers.get(myParam).getOrElse("No header for key myParam")
request.headers.get(myParam).fold("No header for key myParam")(identity)
request.headers.get(myParam) // can throw `java.util.NoSuchElementException`
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.