Class: HttpMonkey::Middlewares::RequestFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/http_monkey/middlewares/request_filter.rb

Overview

Intercept all requests

Example

HttpMonkey.configure do
  middlewares.use HttpMonkey::Middlewares::RequestFilter do |env, request|
    # HttpMonkey::Client::Environment, hash rack on steroids
    # You can use "snaky" methods like:
    # env.http_headers  # => {"Content-Type" => "text/html"}
    # env.add_http_header("X-Custom" => "custom")

    # HTTPI::Request, you can set proxy, timeouts, authentication etc.
    # req.proxy = "http://example.com"
  end
end

Instance Method Summary collapse

Constructor Details

#initialize(app, &block) ⇒ RequestFilter

Returns a new instance of RequestFilter.



21
22
23
24
# File 'lib/http_monkey/middlewares/request_filter.rb', line 21

def initialize(app, &block)
  @app = app
  @block = (block || lambda {|env, req| })
end

Instance Method Details

#call(env) ⇒ Object



26
27
28
29
# File 'lib/http_monkey/middlewares/request_filter.rb', line 26

def call(env)
  @block.call(env, env.monkey_request)
  @app.call(env)
end