lib/async/http/client.rb in async-http-0.18.0 vs lib/async/http/client.rb in async-http-0.19.0

- old
+ new

@@ -19,10 +19,12 @@ # THE SOFTWARE. require 'async/io/endpoint' require_relative 'protocol' +require_relative 'body/streamable' +require_relative 'middleware' module Async module HTTP class Client def initialize(endpoint, protocol = nil, authority = nil, **options) @@ -52,30 +54,23 @@ def close @connections.close end - VERBS = ['GET', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE'] + include Verbs - VERBS.each do |verb| - define_method(verb.downcase) do |reference, *args, &block| - self.request(verb, reference.to_str, *args, &block) + def call(request) + connection = @connections.acquire + + request.authority ||= @authority + response = connection.call(request) + + # The connection won't be released until the body is completely read/released. + Body::Streamable.wrap(response) do + @connections.release(connection) end - end - - def request(*args, &block) - @connections.acquire do |connection| - response = connection.send_request(@authority, *args) - - begin - return yield response if block_given? - ensure - # This forces the stream to complete reading. - response.finish - end - - return response - end + + return response end protected def connect(connection_limit: nil)