Class: Terminus::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/terminus/proxy.rb,
lib/terminus/proxy/rewrite.rb,
lib/terminus/proxy/external.rb,
lib/terminus/proxy/driver_body.rb

Defined Under Namespace

Modules: Rewrite Classes: DriverBody, External

Constant Summary collapse

CONTENT_TYPES =
%w[text/plain text/html]
BASIC_RESOURCES =
%w[/favicon.ico /robots.txt]
MAX_REDIRECTS =
5
REDIRECT_CODES =
[301, 302, 303, 305, 307]
INFINITE_REDIRECT_RESPONSE =
[
  200,
  {'Content-Type' => 'text/html'},
  [File.read(ROOT + '/terminus/views/infinite.html')]
]
ERROR_PAGE =
ERB.new(<<-HTML)
  <!doctype html>
  <html>
    <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    </head>
    <body>
      <h1><%= error.class %>: <%=ERB::Util.h error.message %></h1>
      <ul>
        <% error.backtrace.each do |line| %>
          <li><%=ERB::Util.h line %></li>
        <% end %>
      </ul>
    </body>
  </html>
HTML

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Proxy

Returns a new instance of Proxy.



46
47
48
49
50
# File 'lib/terminus/proxy.rb', line 46

def initialize(app)
  app = External.new(app) if Host === app
  @app = app
  @redirects = 0
end

Class Method Details

.[](app) ⇒ Object



36
37
38
39
# File 'lib/terminus/proxy.rb', line 36

def self.[](app)
  @proxies ||= {}
  @proxies[app] ||= new(app)
end

.content_type(response) ⇒ Object



41
42
43
44
# File 'lib/terminus/proxy.rb', line 41

def self.content_type(response)
  type = response[1].find { |key, _| key =~ /^content-type$/i }
  type && type.flatten.last.split(';').first
end

Instance Method Details

#call(env) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/terminus/proxy.rb', line 52

def call(env)
  add_cookies(env)
  response = forward_request(env)
  store_cookies(env, response)
  response = detect_infinite_redirect(response)
  rewrite_response(env, response)
end