Note that in onRouteRequest
you are overriding the behavior to find the handler that will handle your request, not the call to the handler itself.
onRouteRequest
is called from onRequestReceived
:
def onRequestReceived(request: RequestHeader): (RequestHeader, Handler) = {
val (routedRequest, handler) = onRouteRequest(request) map {
case handler: RequestTaggingHandler => (handler.tagRequest(request), handler)
case otherHandler => (request, otherHandler)
} getOrElse {
(request, Action.async(BodyParsers.parse.empty)(_ => this.onHandlerNotFound(request)))
}
(routedRequest, doFilter(rh => handler)(routedRequest))
}
Note how the returned tuple of type (RequestHeader, Handler)
is using the original request
. Basically, all the changes to the request that you perfom in onRouteRequest
are completely ignored since the original request is used and applied to the found handler.
For your use case, a Filter may be a better option:
object ItalianLanguage extends Filter {
def apply(next: (RequestHeader) => Future[SimpleResult])(request: RequestHeader): Future[SimpleResult] = {
// your code to set the italian language in request
next(request)
}
}