Multiple headers with the same name

329 views Asked by At

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 =>
      }
    }
  }
} 
1

There are 1 answers

0
jrudolph On BEST ANSWER

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