bandwidth management with rails?

放肆的年华 提交于 2019-12-03 04:37:19

One option would be to add an after_filter in application.rb (so that it applies to all actions) and do the following:

def store_bandwidth_usage
   response_size = response.body.size
   # Assuming the User model has a bandwidth_usage attribute
   @current_user.increment!(:bandwidth_usage, response_size) 
end

Of course then you would need a before_filter which checked that a user had not gone over their allocated bandwidth otherwise they should be denied access.

Keep in mind that this will only be counted for requests that hit the rails server, any requests that are filled by an front-end server (e.g. images) will not be included.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!