Class: SiteHub::Middleware::ReverseProxy

Inherits:
Object
  • Object
show all
Includes:
Constants::HttpHeaderKeys, CookieRewriting
Defined in:
lib/sitehub/middleware/reverse_proxy.rb

Constant Summary

Constants included from CookieRewriting

CookieRewriting::ENDING_WITH_NEWLINE

Constants included from Constants::HttpHeaderKeys

Constants::HttpHeaderKeys::CONNECTION_HEADER, Constants::HttpHeaderKeys::CONTENT_ENCODING, Constants::HttpHeaderKeys::CONTENT_LENGTH, Constants::HttpHeaderKeys::HOST_HEADER, Constants::HttpHeaderKeys::KEEP_ALIVE, Constants::HttpHeaderKeys::LOCATION_HEADER, Constants::HttpHeaderKeys::PROXY_AUTHENTICATE, Constants::HttpHeaderKeys::PROXY_AUTHORIZATION, Constants::HttpHeaderKeys::PROXY_CONNECTION, Constants::HttpHeaderKeys::SET_COOKIE, Constants::HttpHeaderKeys::TE, Constants::HttpHeaderKeys::TRAILERS, Constants::HttpHeaderKeys::TRANSACTION_ID, Constants::HttpHeaderKeys::TRANSFER_ENCODING, Constants::HttpHeaderKeys::UPGRADE, Constants::HttpHeaderKeys::X_FORWARDED_FOR_HEADER, Constants::HttpHeaderKeys::X_FORWARDED_HOST_HEADER

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CookieRewriting

#cookies_hash_to_string, #cookies_string_as_hash, #rewrite_cookies, #update_domain

Constructor Details

#initialize(app, directives) ⇒ ReverseProxy

Returns a new instance of ReverseProxy.



13
14
15
16
# File 'lib/sitehub/middleware/reverse_proxy.rb', line 13

def initialize(app, directives)
  @app = app
  @path_directives = LocationRewriters.new(directives)
end

Instance Attribute Details

#path_directivesObject (readonly)

Returns the value of attribute path_directives.



11
12
13
# File 'lib/sitehub/middleware/reverse_proxy.rb', line 11

def path_directives
  @path_directives
end

Instance Method Details

#call(env) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/sitehub/middleware/reverse_proxy.rb', line 18

def call(env)
  status, headers, body = @app.call(env).to_a
  mapping = env[REQUEST].mapping

  headers[LOCATION_HEADER] = location(headers, mapping.source_url) if headers[LOCATION_HEADER]

  rewrite_cookies(headers, substitute_domain: mapping.host) if headers[SET_COOKIE]

  [status, HttpHeaders.new(headers), body]
end