2015-05-11 23:05:18 +02:00
|
|
|
.. _-headerValue-:
|
|
|
|
|
|
|
|
|
|
headerValue
|
|
|
|
|
===========
|
|
|
|
|
|
|
|
|
|
Signature
|
|
|
|
|
---------
|
|
|
|
|
|
2015-06-19 15:35:24 +02:00
|
|
|
.. includecode2:: /../../akka-http/src/main/scala/akka/http/scaladsl/server/directives/HeaderDirectives.scala
|
2015-05-11 23:05:18 +02:00
|
|
|
:snippet: headerValue
|
|
|
|
|
|
|
|
|
|
Description
|
|
|
|
|
-----------
|
2015-10-09 15:19:36 +02:00
|
|
|
Traverses the list of request headers with the specified function and extracts the first value the function returns as
|
|
|
|
|
``Some(value)``.
|
2015-05-11 23:05:18 +02:00
|
|
|
|
2015-10-09 15:19:36 +02:00
|
|
|
The :ref:`-headerValue-` directive is a mixture of ``map`` and ``find`` on the list of request headers. The specified function
|
2015-05-11 23:05:18 +02:00
|
|
|
is called once for each header until the function returns ``Some(value)``. This value is extracted and presented to the
|
|
|
|
|
inner route. If the function throws an exception the request is rejected with a ``MalformedHeaderRejection``. If the
|
|
|
|
|
function returns ``None`` for every header the request is rejected as "NotFound".
|
|
|
|
|
|
2015-10-09 15:19:36 +02:00
|
|
|
This directive is the basis for building other request header related directives.
|
|
|
|
|
|
|
|
|
|
See also :ref:`-headerValuePF-` for a nicer syntactic alternative.
|
2015-05-11 23:05:18 +02:00
|
|
|
|
|
|
|
|
Example
|
|
|
|
|
-------
|
|
|
|
|
|
2015-05-21 17:34:46 +02:00
|
|
|
.. includecode2:: ../../../../code/docs/http/scaladsl/server/directives/HeaderDirectivesExamplesSpec.scala
|
2015-05-11 23:05:18 +02:00
|
|
|
:snippet: headerValue-0
|