class Capybara::Webmock::Proxy

Constants

DEFAULT_ALLOWED_HOSTS

Public Instance Methods

call(env) click to toggle source
Calls superclass method
# File lib/capybara/webmock/proxy.rb, line 7
def call(env)
  @streaming = true
  super
end
perform_request(env) click to toggle source
Calls superclass method
# File lib/capybara/webmock/proxy.rb, line 12
def perform_request(env)
  request = Rack::Request.new(env)

  if allowed_host?(request.host)
    super(env)
  else
    headers = {
      'Content-Type' => 'text/html',
      'Access-Control-Allow-Origin' => '*',
      'Access-Control-Allow-Methods' => '*',
      'Access-Control-Allow-Headers' => '*'
    }
    ['200', headers, ['']]
  end
end

Private Instance Methods

allowed_host?(host) click to toggle source
# File lib/capybara/webmock/proxy.rb, line 34
def allowed_host?(host)
  allowed_hosts.any? do |allowed_host|
    case allowed_host
    when Regexp
      allowed_host =~ host
    when String
      allowed_host == host
    end
  end
end
allowed_hosts() click to toggle source
# File lib/capybara/webmock/proxy.rb, line 30
def allowed_hosts
  DEFAULT_ALLOWED_HOSTS + ENV.fetch('CAPYBARA_WEBMOCK_ADDED_HOSTS', "").split(Capybara::Webmock::SEPARATOR)
end