class Proxy::Dynflow::Callback::Core

Public Class Methods

relay(request, from, to) click to toggle source
# File lib/smart_proxy_dynflow/callback.rb, line 29
def self.relay(request, from, to)
  self.new.relay request, from, to
end

Public Instance Methods

relay(request, from, to) click to toggle source
# File lib/smart_proxy_dynflow/callback.rb, line 11
def relay(request, from, to)
  path = request.path.gsub(from, to)
  message = "Proxy request from #{request.host_with_port}#{request.path} to #{uri}#{path}"
  Proxy::LogBuffer::Decorator.instance.debug message
  req = case request.env['REQUEST_METHOD']
        when 'GET'
          request_factory.create_get path, request.env['rack.request.query_hash']
        when 'POST'
          request_factory.create_post path, request.body.read
        end
  req['X-Forwarded-For'] = request.env['HTTP_HOST']
  req['AUTHORIZATION'] = request.env['HTTP_AUTHORIZATION']
  req['X-Request-Id'] = ::Logging.mdc['request']
  response = send_request req
  Proxy::LogBuffer::Decorator.instance.debug "Proxy request status #{response.code} - #{response}"
  response
end
uri() click to toggle source
# File lib/smart_proxy_dynflow/callback.rb, line 7
def uri
  @uri ||= URI.parse Proxy::Dynflow::Plugin.settings.core_url
end