Method: Strobe::Middleware::Proxy#call

Defined in:
lib/strobe/middleware/proxy.rb

#call(env) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/strobe/middleware/proxy.rb', line 90

def call(env)
  if env['PATH_INFO'] =~ PROXY_PATH
    p1, p2     = $1, $2
    scheme     = scheme_from_env(env)
    host, port = p1.split(':')
    path       = p2 || '/'
    port       = (port || (scheme == 'http' ? 80 : 443)).to_i

    url = "#{scheme}://#{host}"

    if port
      if (scheme == 'http' && port != 80) || (scheme == 'https' && port != 443)
        url << ":#{port}"
      end
    end

    url << path

    if !env['QUERY_STRING'].empty?
      url << "?#{env['QUERY_STRING']}"
    end

    request = ProxyRequest.new(env, url, @opts)
    request.handle!

    throw :async
  else
    @app.call(env)
  end
end