如何在Play 2 + Scala中拦截所有控制器请求? [英] How do I intercept all controller requests in Play 2 + Scala?

查看:101
本文介绍了如何在Play 2 + Scala中拦截所有控制器请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Play 2的Java版本中,有 GlobalSettings.onRequest ,可以用来拦截所有传入控制器的请求.但是在 Scala等效版本中,没有onRequest处理程序.

In the Java flavor of Play 2, there is GlobalSettings.onRequest, which can be used to intercept all incoming requests to controllers. But in the Scala equivalent, there is no onRequest handler.

我怀疑这是因为Scala中不需要Java所需的Action委派逻辑,但这很烦人,因为我想在每个传入的控制器请求上运行一些代码.

I suspect this is because the Action delegation logic needed in Java isn't required in Scala, but it's rather annoying because I want to run some code on every incoming controller request.

有人知道如何在Scala + Play 2应用程序中拦截所有控制器请求吗?

Does anyone know how to intercept all controller requests in a Scala + Play 2 app?

推荐答案

覆盖 def onRouteRequest (request: RequestHeader): Option[Handler] 在您的全局对象中可能是您​​正在寻找的答案.

override def onRouteRequest (request: RequestHeader): Option[Handler] in your Global object might be the answer you're looking for.

在2.0.4 api中,当收到HTTP请求时调用它.

From the 2.0.4 api, it's called when an HTTP request has been received.

这篇关于如何在Play 2 + Scala中拦截所有控制器请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆