Class: ApiValve::Forwarder
- Inherits:
-
Object
- Object
- ApiValve::Forwarder
- Includes:
- Benchmarking
- Defined in:
- lib/api_valve/forwarder.rb
Overview
This class is responsible for forwarding the HTTP request to the designated endpoint. It is instantiated once per Proxy with relevant options, and called from the router.
Defined Under Namespace
Classes: LocationConverter, Request, Response
Instance Method Summary collapse
-
#call(original_request, local_options = {}) ⇒ Object
Takes the original rack request with optional options and returns a rack response Instantiates the Request and Response classes and wraps them around the original request and response.
-
#initialize(options = {}) ⇒ Forwarder
constructor
Initialized with global options.
Methods included from Benchmarking
Constructor Details
#initialize(options = {}) ⇒ Forwarder
Initialized with global options. Possible values are: request: Options for the request wrapper. See Request#new. response: Options for the response wrapper. See Response#new
16 17 18 19 20 21 |
# File 'lib/api_valve/forwarder.rb', line 16 def initialize( = {}) @options = .with_indifferent_access uri = URI([:endpoint]) # Target prefix must be without trailing slash @target_prefix = uri.path.gsub(%r{/$}, '') end |
Instance Method Details
#call(original_request, local_options = {}) ⇒ Object
Takes the original rack request with optional options and returns a rack response Instantiates the Request and Response classes and wraps them around the original request and response.
26 27 28 29 30 |
# File 'lib/api_valve/forwarder.rb', line 26 def call(original_request, = {}) request = build_request(original_request, .deep_merge()) response = build_response(original_request, run_request(request), ) response.rack_response end |