Class: Rack::Prevoty::MonitorInterceptor
- Inherits:
-
Interceptor
- Object
- Interceptor
- Rack::Prevoty::MonitorInterceptor
- Defined in:
- lib/rack/monitor_interceptor.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, opts) ⇒ MonitorInterceptor
constructor
A new instance of MonitorInterceptor.
Methods inherited from Interceptor
Constructor Details
#initialize(app, opts) ⇒ MonitorInterceptor
Returns a new instance of MonitorInterceptor.
6 7 8 9 10 |
# File 'lib/rack/monitor_interceptor.rb', line 6 def initialize(app, opts) super(app, opts) @monitor = ::Prevoty::ContentMonitor.new(@client, opts) end |
Instance Method Details
#call(env) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/rack/monitor_interceptor.rb', line 12 def call(env) req = Rack::Request.new(env) # passthru if not listed in paths return @app.call(env) if @paths.detect {|p| req.path.start_with?(p)}.nil? # passthru if blacklisted return @app.call(env) unless @blacklist.detect {|p| req.path.start_with?(p)}.nil? case req.request_method when "GET", "DELETE" unless env['QUERY_STRING'] === '' querystring = URI.unescape(env['QUERY_STRING']) @monitor.process({mode: @mode, input: querystring, request: req}) end when "POST", "PUT" if req.media_type === 'multipart/form-data' # TODO: implement support for multipart. The Rack multipart # implementation doesn't support parsing and re-creating the # mutlipart data so a custom implementation needs to be written else body = URI.unescape(req.body.read.encode('utf-8')) unless body === '' @monitor.process({mode: @mode, input: body, request: req}) end end # clean any GET data passed unless env['QUERY_STRING'] === '' querystring = URI.unescape(env['QUERY_STRING']) @monitor.process({mode: @mode, input: querystring, request: req}) end else Rails.logger.warn "unknown method #{req.request_method}" end @app.call(env) end |