Class: Async::HTTP::Internet

Inherits:
Object
  • Object
show all
Defined in:
lib/async/http/internet.rb

Instance Method Summary collapse

Constructor Details

#initializeInternet

Returns a new instance of Internet.



31
32
33
# File 'lib/async/http/internet.rb', line 31

def initialize
	@clients = {}
end

Instance Method Details

#call(method, url, headers = [], body = nil) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/async/http/internet.rb', line 35

def call(method, url, headers = [], body = nil)
	endpoint = Endpoint.parse(url)
	key = host_key(endpoint)
	
	client = @clients.fetch(key) do
		@clients[key] = self.client_for(endpoint)
	end
	
	body = Body::Buffered.wrap(body)
	
	request = ::Protocol::HTTP::Request.new(client.scheme, endpoint.authority, method, endpoint.path, nil, headers, body)
	
	return client.call(request)
end

#client_for(endpoint) ⇒ Object



50
51
52
# File 'lib/async/http/internet.rb', line 50

def client_for(endpoint)
	Client.new(endpoint)
end

#closeObject



54
55
56
57
# File 'lib/async/http/internet.rb', line 54

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