Class: SiteHub::ForwardProxy

Inherits:
Object
  • Object
show all
Includes:
Equality, Resolver, Rules
Defined in:
lib/sitehub/forward_proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Rules

#applies?, #rule

Methods included from Resolver

#resolve

Methods included from Equality

#==, #_clazz, included

Constructor Details

#initialize(sitehub_cookie_path: nil, sitehub_cookie_name:, id:, rule: nil, mapped_path:, mapped_url:) ⇒ ForwardProxy

Returns a new instance of ForwardProxy.



10
11
12
13
14
15
16
17
18
# File 'lib/sitehub/forward_proxy.rb', line 10

def initialize(sitehub_cookie_path: nil, sitehub_cookie_name:, id:, rule: nil, mapped_path:, mapped_url:)
  @downstream_client = DownstreamClient.new
  @sitehub_cookie_path = sitehub_cookie_path
  @sitehub_cookie_name = sitehub_cookie_name
  @id = id
  @rule = rule
  @mapped_path = mapped_path
  @mapped_url = mapped_url
end

Instance Attribute Details

#downstream_clientObject (readonly)

Returns the value of attribute downstream_client.



6
7
8
# File 'lib/sitehub/forward_proxy.rb', line 6

def downstream_client
  @downstream_client
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/sitehub/forward_proxy.rb', line 6

def id
  @id
end

#mapped_pathObject (readonly)

Returns the value of attribute mapped_path.



6
7
8
# File 'lib/sitehub/forward_proxy.rb', line 6

def mapped_path
  @mapped_path
end

#mapped_urlObject (readonly)

Returns the value of attribute mapped_url.



6
7
8
# File 'lib/sitehub/forward_proxy.rb', line 6

def mapped_url
  @mapped_url
end

Returns the value of attribute sitehub_cookie_name.



6
7
8
# File 'lib/sitehub/forward_proxy.rb', line 6

def sitehub_cookie_name
  @sitehub_cookie_name
end

Returns the value of attribute sitehub_cookie_path.



6
7
8
# File 'lib/sitehub/forward_proxy.rb', line 6

def sitehub_cookie_path
  @sitehub_cookie_path
end

Instance Method Details

#call(env) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/sitehub/forward_proxy.rb', line 20

def call(env)
  request = env[REQUEST]
  request.map(mapped_path, mapped_url)

  downstream_client.call(request).tap do |response|
    response.set_cookie(sitehub_cookie_name,
                        path: resolve_sitehub_cookie_path(request),
                        value: id)
  end
end


31
32
33
# File 'lib/sitehub/forward_proxy.rb', line 31

def resolve_sitehub_cookie_path(request)
  sitehub_cookie_path || request.path
end