Compare commits

..

No commits in common. "6437b4b5fbcbe045481bc860a9e1e9d8af6bccbe" and "02c19170048d82afc8133335148fbff29f29c680" have entirely different histories.

10 changed files with 29 additions and 47 deletions

View File

@ -1,4 +1,4 @@
# 1.1.3
# 1.1.2
## improvements

View File

@ -1,6 +0,0 @@
# 1.1.4
## bug reports
* datadog adapter: use `Gem::Version` to invoke the correct configuration API.
* stream plugin: do not preempt request enqueuing (this was making integration with the `:follow_redirects` plugin fail when set up with `webmock`).

View File

@ -214,17 +214,6 @@ class WebmockTest < Minitest::Test
assert_not_requested(:get, "http://#{httpbin}")
end
def test_webmock_follow_redirects_with_stream_plugin
session = HTTPX.plugin(:follow_redirects).plugin(:stream)
redirect_url = "#{MOCK_URL_HTTP}/redirect"
initial_request = stub_request(:get, MOCK_URL_HTTP).to_return(status: 302, headers: { location: redirect_url })
redirect_request = stub_request(:get, redirect_url)
session.get(MOCK_URL_HTTP, stream: true).each.to_a.join
assert_requested(initial_request)
assert_requested(redirect_request)
end
private
def assert_raise_with_message(e, message, &block)

View File

@ -126,7 +126,7 @@ module Datadog::Tracing
option :distributed_tracing, default: true
option :split_by_domain, default: false
if Gem::Version.new(DDTrace::VERSION::STRING) >= Gem::Version.new("1.13.0")
if DDTrace::VERSION::STRING >= "1.13.0"
option :enabled do |o|
o.type :bool
o.env "DD_TRACE_HTTPX_ENABLED"
@ -182,12 +182,12 @@ module Datadog::Tracing
option :distributed_tracing, default: true
if Gem::Version.new(DDTrace::VERSION::STRING) >= Gem::Version.new("1.15.0")
if DDTrace::VERSION::STRING >= "1.15.0"
option :error_handler do |o|
o.type :proc
o.default_proc(&DEFAULT_ERROR_HANDLER)
end
elsif Gem::Version.new(DDTrace::VERSION::STRING) >= Gem::Version.new("1.13.0")
elsif DDTrace::VERSION::STRING >= "1.13.0"
option :error_handler do |o|
o.type :proc
o.experimental_default_proc(&DEFAULT_ERROR_HANDLER)

View File

@ -215,7 +215,7 @@ module HTTPX
**opts)
grpc_request = build_grpc_request(rpc_method, input, deadline: deadline, metadata: metadata, **opts)
response = request(grpc_request, **opts)
response.raise_for_status unless opts[:stream]
response.raise_for_status
GRPC::Call.new(response)
end

View File

@ -36,6 +36,7 @@ module HTTPX
class Inflater
def initialize(response)
@encodings = response.headers.get("grpc-encoding")
@response = response
end
@ -48,7 +49,7 @@ module HTTPX
encoded_data = message.byteslice(5..size + 5 - 1)
if compressed == 1
grpc_encodings.reverse_each do |encoding|
@encodings.reverse_each do |encoding|
decoder = @response.body.class.initialize_inflater_by_encoding(encoding, @response, bytesize: encoded_data.bytesize)
encoded_data = decoder.call(encoded_data)
@ -67,12 +68,6 @@ module HTTPX
data
end
private
def grpc_encodings
@grpc_encodings ||= @response.headers.get("grpc-encoding")
end
end
def self.encode(*args, **kwargs)

View File

@ -2,9 +2,10 @@
module HTTPX
class StreamResponse
def initialize(request, session)
def initialize(request, session, connections)
@request = request
@session = session
@connections = connections
end
def each(&block)
@ -15,9 +16,19 @@ module HTTPX
begin
@on_chunk = block
if @request.response
# if we've already started collecting the payload, yield it first
# before proceeding
body = @request.response.body
body.each do |chunk|
on_chunk(chunk)
end
end
response.raise_for_status
response.close
ensure
response.close if @response
@on_chunk = nil
end
end
@ -58,9 +69,9 @@ module HTTPX
private
def response
@response ||= begin
@request.response || @session.request(@request)
end
@session.__send__(:receive_requests, [@request], @connections) until @request.response
@request.response
end
def respond_to_missing?(meth, *args)
@ -94,7 +105,9 @@ module HTTPX
request = requests.first
StreamResponse.new(request, self)
connections = _send_requests(requests)
StreamResponse.new(request, self, connections)
end
end

View File

@ -1,5 +1,5 @@
# frozen_string_literal: true
module HTTPX
VERSION = "1.1.4"
VERSION = "1.1.3"
end

View File

@ -21,15 +21,11 @@ module HTTPX
class Inflater
@response: Response
@grpc_encodings: Array[String]
@encodings: Array[String]
def initialize: (Response | StreamResponse response) -> void
def call: (String message) ?{ (String) -> void } -> String
private
def grpc_encodings: () -> Array[String]
end
end

View File

@ -2,10 +2,6 @@ module HTTPX
class StreamResponse
include _ToS
@request: Request & RequestMethods
@session: sessionStream
@on_chunk: ^(String) -> void | nil
def each: () { (String) -> void } -> void
| () -> Enumerable[String]
@ -14,11 +10,10 @@ module HTTPX
def on_chunk: (string) -> void
def initialize: (Request, Session) -> void
private
def response: () -> response
def initialize: (Request, Session, Array[Connection]) -> untyped
end
module Plugins