Class: Goliath::Rack::ReverseProxy
- Inherits:
-
Object
- Object
- Goliath::Rack::ReverseProxy
- Includes:
- AsyncMiddleware
- Defined in:
- lib/goliath/rack/reverse_proxy.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options) ⇒ ReverseProxy
constructor
A new instance of ReverseProxy.
- #post_process(env, status, headers, body, connection) ⇒ Object
- #request_headers(env, headers) ⇒ Object
Constructor Details
#initialize(app, options) ⇒ ReverseProxy
Returns a new instance of ReverseProxy.
8 9 10 11 |
# File 'lib/goliath/rack/reverse_proxy.rb', line 8 def initialize(app, ) @app = app @connection = EM::HttpRequest.new([:base_url]) end |
Instance Method Details
#call(env) ⇒ Object
13 14 15 16 |
# File 'lib/goliath/rack/reverse_proxy.rb', line 13 def call(env) connection = @connection.dup super(env, connection) end |
#post_process(env, status, headers, body, connection) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/goliath/rack/reverse_proxy.rb', line 18 def post_process(env, status, headers, body, connection) method = env['REQUEST_METHOD'].downcase.to_sym = {:head => request_headers(env, headers), :path => env['REQUEST_URI']} [:body] = env['params'] if [:put, :post, :patch].include? method http = connection.send(method, ) [http.response_header.status, http.response_header.raw, [http.response]] end |
#request_headers(env, headers) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/goliath/rack/reverse_proxy.rb', line 29 def request_headers(env, headers) env.each do |key, value| headers[$1.gsub('_', '-').downcase] = value if key =~ /HTTP_(.*)/ end headers['X-Forwarded-Host'] = env['HTTP_HOST'] headers['X-Forwarded-User'] = env['REMOTE_USER'] if env['REMOTE_USER'] headers end |