禁用/配置每个控制器的 HoptoadNotifier
如何禁用或配置每个控制器的 HoptoadNotifier?背景是我将通知程序配置为报告“不允许方法”异常,例如,当使用 GET 而不是 POST 访问操作时会引发此异常。
但是我有一个自动完成控制器,机器人通过向我的控制器发送 GET 请求而不是 POST (带有各种奇怪的参数)来扫描它(可能是为了发现漏洞)。所以我想仅针对此异常、此操作或此控制器禁用通知程序。
已解决:感谢@Tanel,我做了以下似乎有效的操作:
def rescue_action_in_public exception
if exception.is_a? ActionController::MethodNotAllowed
rescue_action_in_public_without_hoptoad exception
else
super exception
end
end
How could I disable or configure the HoptoadNotifier per controller? Background is that I configured the notifier to report "Method not allowed" exception, eg this is raised when an action is accessed with GET instead of POST.
But I have an autocomplete controller which is scanned by bots (probably to find exploits) by sending GET requests to my controller instead of POST (with all sorts of strange parameters). So I want to disable the notifier for just this exception, this action, or this controller.
Solved: Thanks to @Tanel I did the following which seems to work:
def rescue_action_in_public exception
if exception.is_a? ActionController::MethodNotAllowed
rescue_action_in_public_without_hoptoad exception
else
super exception
end
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许覆盖特定控制器中的 rescue_action_in_public ?
这就是 Hoptoad 用来捕获异常的方法。
Perhaps overriding the rescue_action_in_public in the specific controller?
That's the method Hoptoad uses to catch its exceptions.