Class: Falcon::Proxy

Inherits:
Async::HTTP::Middleware
  • Object
show all
Defined in:
lib/falcon/proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, hosts) ⇒ Proxy

Returns a new instance of Proxy.



34
35
36
37
38
39
40
41
42
43
# File 'lib/falcon/proxy.rb', line 34

def initialize(app, hosts)
	super(app)
	
	@server_context = nil
	
	@hosts = hosts
	@clients = {}
	
	@count = 0
end

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



45
46
47
# File 'lib/falcon/proxy.rb', line 45

def count
  @count
end

Instance Method Details

#call(request) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/falcon/proxy.rb', line 64

def call(request, *)
	if endpoint = lookup(request)
		@count += 1
		
		client = connect(endpoint)
		
		client.call(request)
	else
		super
	end
end

#closeObject



47
48
49
50
51
# File 'lib/falcon/proxy.rb', line 47

def close
	@clients.each_value(&:close)
	
	super
end

#connect(endpoint) ⇒ Object



53
54
55
# File 'lib/falcon/proxy.rb', line 53

def connect(endpoint)
	@clients[endpoint] ||= Async::HTTP::Client.new(endpoint)
end

#lookup(request) ⇒ Object



57
58
59
60
61
62
# File 'lib/falcon/proxy.rb', line 57

def lookup(request)
	# Trailing dot and port is ignored/normalized.
	if authority = request.authority.sub(/(\.)?(:\d+)?$/, '')
		return @hosts[authority]
	end
end