Class: Terminus::Proxy::External

Inherits:
Rack::Proxy
  • Object
show all
Defined in:
lib/terminus/proxy/external.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri) ⇒ External

Returns a new instance of External.



7
8
9
10
# File 'lib/terminus/proxy/external.rb', line 7

def initialize(uri)
  uri.host.gsub!(LOCALHOST, '127.0.0.1')
  @uri = uri
end

Instance Attribute Details

#uriObject (readonly)

Returns the value of attribute uri.



5
6
7
# File 'lib/terminus/proxy/external.rb', line 5

def uri
  @uri
end

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/terminus/proxy/external.rb', line 12

def call(env)
  dock_host = env['SERVER_NAME']
  response = super
  response[1].delete('transfer-encoding')
  response[2].extend(Rewrite)
  response[2].dock_host = dock_host
  response
end

#hostObject



21
22
23
# File 'lib/terminus/proxy/external.rb', line 21

def host
  "#{@uri.host}:#{@uri.port}"
end

#rewrite_env(env) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/terminus/proxy/external.rb', line 25

def rewrite_env(env)
  env = env.dup
  env['SERVER_NAME'] = @uri.host
  env['SERVER_PORT'] = @uri.port
  env['HTTP_HOST']   = "#{@uri.host}:#{@uri.port}"
  env.delete('HTTP_ACCEPT_ENCODING')

  if scheme = @uri.scheme
    env['rack.url_scheme'] = scheme
  end

  if %w[PUT POST].include?(env['REQUEST_METHOD'])
    env['CONTENT_LENGTH'] ||= '0'
  end

  env
end