lib/httpx/client.rb in httpx-0.1.0 vs lib/httpx/client.rb in httpx-0.2.0

- old
+ new

@@ -54,41 +54,49 @@ @responses.delete(request) end def find_channel(request, **options) uri = URI(request.uri) - @connection.find_channel(uri) || begin - channel = @connection.build_channel(uri, **options) - set_channel_callbacks(channel) - channel - end + @connection.find_channel(uri) || build_channel(uri, options) end - def set_channel_callbacks(channel) + def set_channel_callbacks(channel, options) channel.on(:response, &method(:on_response)) channel.on(:promise, &method(:on_promise)) + channel.on(:uncoalesce) do |uncoalesced_uri| + other_channel = build_channel(uncoalesced_uri, options) + channel.unmerge(other_channel) + end end + def build_channel(uri, options) + channel = @connection.build_channel(uri, **options) + set_channel_callbacks(channel, options) + channel + end + def __build_reqs(*args, **options) - case args.size - when 1 - reqs = args.first - reqs.map do |verb, uri| - __build_req(verb, uri, options) - end - when 2, 3 - verb, uris = args - if uris.respond_to?(:each) - uris.map do |uri| - __build_req(verb, uri, options) - end - else - [__build_req(verb, uris, options)] - end - else - raise ArgumentError, "unsupported number of arguments" + requests = case args.size + when 1 + reqs = args.first + reqs.map do |verb, uri| + __build_req(verb, uri, options) + end + when 2, 3 + verb, uris = args + if uris.respond_to?(:each) + uris.map do |uri| + __build_req(verb, uri, options) + end + else + [__build_req(verb, uris, options)] + end + else + raise ArgumentError, "unsupported number of arguments" end + raise ArgumentError, "wrong number of URIs (given 0, expect 1..+1)" if requests.empty? + requests end def __send_reqs(*requests, **options) requests.each do |request| channel = find_channel(request, **options) @@ -163,7 +171,9 @@ plugin(pl, *args) end self end end + + plugin(:proxy) unless ENV.grep(/https?_proxy$/i).empty? end end