Class: ApiValve::Forwarder::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/api_valve/forwarder/response.rb

Overview

This class is wraps the original response. The rack_response method is called by the Forwarder to build the rack response that will be returned by the proxy. By changing this class, we can control how the request is published to the original caller

Constant Summary collapse

WHITELISTED_HEADERS =
%w(
  Cache-Control
  Content-Disposition
  Content-Type
  Location
).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(original_request, original_response, options = {}) ⇒ Response

Returns a new instance of Response.



21
22
23
24
25
# File 'lib/api_valve/forwarder/response.rb', line 21

def initialize(original_request, original_response, options = {})
  @original_request = original_request
  @original_response = original_response
  @options = options.with_indifferent_access
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



12
13
14
# File 'lib/api_valve/forwarder/response.rb', line 12

def options
  @options
end

#original_requestObject (readonly)

Returns the value of attribute original_request.



12
13
14
# File 'lib/api_valve/forwarder/response.rb', line 12

def original_request
  @original_request
end

#original_responseObject (readonly)

Returns the value of attribute original_response.



12
13
14
# File 'lib/api_valve/forwarder/response.rb', line 12

def original_response
  @original_response
end

Instance Method Details

#rack_responseObject

Must return a rack compatible response array of status code, headers and body



28
29
30
# File 'lib/api_valve/forwarder/response.rb', line 28

def rack_response
  [status, headers, [body]]
end