Class: AgileProxy::StubHandler

Inherits:
Object
  • Object
show all
Includes:
Handler
Defined in:
lib/agile_proxy/handlers/stub_handler.rb

Overview

The stub handler

This class is resonsible for matching incoming requests with a stub (request spec) and if one exists, respond with it rather than the real response from the destination server.

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Array

Called by ‘rack’ as an endpoint.

Fetches a ‘short list’ of potential matching request specs and builds a routing table to allow a router to do the hard work of parsing parameters, matching them, matching URL’s etc…

Parameters:

  • env (Hash)

    The rack environment

Returns:

  • (Array)

    The rack response [status, headers, body]



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/agile_proxy/handlers/stub_handler.rb', line 23

def call(env)
  request = ActionDispatch::Request.new(env)
  username, password = username_password env
  @route_set = ActionDispatch::Routing::RouteSet.new

  my_short_list = short_list(username, password, request.request_method, request.url).all.to_a.reverse
  headers = downcased_headers(env)
  body = request.body.read
  request.body.rewind
  setup_router my_short_list, request, headers, body
  rack_app.call(env)
end