Class: Async::HTTP::Internet
- Inherits:
-
Object
- Object
- Async::HTTP::Internet
- Defined in:
- lib/async/http/internet.rb
Instance Method Summary collapse
- #call(method, url, headers = [], body = nil) ⇒ Object
- #client_for(endpoint) ⇒ Object
- #close ⇒ Object
-
#initialize(**options) ⇒ Internet
constructor
A new instance of Internet.
Constructor Details
#initialize(**options) ⇒ Internet
Returns a new instance of Internet.
31 32 33 34 |
# File 'lib/async/http/internet.rb', line 31 def initialize(**) @clients = {} @options = end |
Instance Method Details
#call(method, url, headers = [], body = nil) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/async/http/internet.rb', line 36 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., method, endpoint.path, nil, headers, body) return client.call(request) end |
#client_for(endpoint) ⇒ Object
51 52 53 |
# File 'lib/async/http/internet.rb', line 51 def client_for(endpoint) Client.new(endpoint, **@options) end |
#close ⇒ Object
55 56 57 58 |
# File 'lib/async/http/internet.rb', line 55 def close @clients.each_value(&:close) @clients.clear end |