extractRequestContext
§シグネチャ
§説明
リクエストの根底にある:class:`RequestContext`を抽出します。
このディレクティブは、他のディレクティブのビルディングブロックとして使用され、コンテキストを抽出し、その値の一部を調べることによって、リクエストを処理するかどうかを決定できます。たとえば、値を指定するか、リクエストを拒否します。
HttpRequest`インスタンス自体にのみ興味がある場合は:ref:
-extractRequest-`を参照してください。
§例
- val route =
- extractRequestContext { ctx =>
- ctx.log.debug("Using access to additional context availablethings, like the logger.")
- val request = ctx.request
- complete(s"Request method is ${request.method.name} and content-type is ${request.entity.contentType}")
- }
-
- // tests:
- Post("/", "text") ~> route ~> check {
- responseAs[String] shouldEqual "Request method is POST and content-type is text/plain; charset=UTF-8"
- }
- Get("/") ~> route ~> check {
- responseAs[String] shouldEqual "Request method is GET and content-type is none/none"
- }