Class: ExampleServiceProxy

Inherits:
Rack::Proxy show all
Defined in:
lib/rack_proxy_examples/example_service_proxy.rb

Constant Summary

Constants inherited from Rack::Proxy

Rack::Proxy::HOP_BY_HOP_HEADERS, Rack::Proxy::VERSION

Instance Method Summary collapse

Methods inherited from Rack::Proxy

build_header_hash, #call, extract_http_request_headers, #initialize, normalize_headers, #rewrite_env, #rewrite_response

Constructor Details

This class inherits a constructor from Rack::Proxy

Instance Method Details

#perform_request(env) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/rack_proxy_examples/example_service_proxy.rb', line 18

def perform_request(env)
  request = Rack::Request.new(env)

  # use rack proxy for anything hitting our host app at /example_service
  if request.path =~ %r{^/example_service}
      backend = URI(ENV['SERVICE_URL'])
      # most backends required host set properly, but rack-proxy doesn't set this for you automatically
      # even when a backend host is passed in via the options
      env["HTTP_HOST"] = backend.host

      # This is the only path that needs to be set currently on Rails 5 & greater
      env['PATH_INFO'] = ENV['SERVICE_PATH'] || '/configuring.html'

      # don't send your sites cookies to target service, unless it is a trusted internal service that can parse all your cookies
      env['HTTP_COOKIE'] = ''
      super(env)
  else
    @app.call(env)
  end
end