Class: Rack::Prevoty::Interceptor
- Inherits:
-
Object
- Object
- Rack::Prevoty::Interceptor
- Defined in:
- lib/rack/interceptor.rb
Direct Known Subclasses
Class Method Summary collapse
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, opts) ⇒ Interceptor
constructor
A new instance of Interceptor.
Constructor Details
#initialize(app, opts) ⇒ Interceptor
Returns a new instance of Interceptor.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/rack/interceptor.rb', line 7 def initialize(app, opts) @app = app @base = opts[:api_base] ||= 'https://api.prevoty.com' @client = ::Prevoty::Client.new(opts[:api_key], @base) @configuration_key = opts[:configuration_key] @mode = opts[:mode] ||= 'monitor' @callback = opts[:callback] ||= nil @minimal_logging = opts[:minimal_logging] ||= false @log_destination = opts[:log_destination] ||= 'log' @paths = opts[:paths] ||= ['/'] @blacklist = opts[:blacklist] ||= [] end |
Class Method Details
.build_result(mode, request, input, result) ⇒ Object
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 49 |
# File 'lib/rack/interceptor.rb', line 24 def self.build_result(mode, request, input, result) data = { product: 'content', mode: mode, version: '1', input: input, timestamp: Time.now.utc.strftime('%b %d %Y %H:%M:%S %Z'), request_url: request.path, session_id: request.session["session_id"], cookies: request., http_method: request.request_method, src_ip: request.ip, dest_host: request.host, dest_port: request.port } # these are hacks due to differences between protect and monitor if mode === 'protect' data[:statistics] = result.statistics data[:output] = CGI::unescape(result.output) else data[:statistics] = result end ::Prevoty::ContentPayload.new(data) end |
Instance Method Details
#call(env) ⇒ Object
20 21 22 |
# File 'lib/rack/interceptor.rb', line 20 def call(env) raise 'this is an abstract class...instantiate one of the child rack middlewares' end |