简体   繁体   中英

Multiple headers with the same name

Spray only supports extracting ONE header with a given name via headerValueByName. How could I get hold of ALL headers with the name "whatever" in the below Spray code snippet? There gotta be some way of extracting the headers!?

lazy val myRoute = {
  path("hello") {
    post {
      headerValueByName("whatever") { header =>
      }
    }
  }
} 

There's no predefined directive for that case (yet?). Here's a way to define it yourself:

def headersByName(name: String): Directive1[List[HttpHeader]] =
  extract(_.request.headers).map(_.filter(_.is(name.toLowerCase)))

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM