httpx 1.1.3 → 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 88e35920c570a12032835c1c67c9ffde6119b0f5e26e357ba58dbe385e1483a5
4
- data.tar.gz: e421a0532b92e6a1e689c1d907ef0b87d98e6589093d791ce9a905d475b0c638
3
+ metadata.gz: d95b9f470645015a3308ade4ab2349375eddd0598f6919fbf063d4feba61926c
4
+ data.tar.gz: 95518fc5601eb0ba9a22e13814f9f0a339addca71e94c33122ed211780049ca4
5
5
  SHA512:
6
- metadata.gz: e01adb8c3974497b091c72d8b9848dd02973c19924c910be4649f83c3430b579a6ea0889f0f27a348cabbddd6ed56cc1b682be0ae984b4dd0ef5dbf76543ba8e
7
- data.tar.gz: 343ace24f2a3be6ce420b4c5f8fbe919ad84dabdc8f3b97bbafc3bda8466fef6dfa48a1985478fd7ec6056678818a60b9cfb158f4423569086f42d4c27c696f6
6
+ metadata.gz: 729bfc7fc5888f6872ecf9dfdcaefa6df68ba96b705cf1ccd1e8b9b866d25bf2c3081577b3c1828b99556009fc686c0705eb30dcb6fd5f2a3fb951128e0c621e
7
+ data.tar.gz: 1173ae3cd242caf251c099e14db090efc3ac3524d8e3f63e04c331f2938a6d747c9874999d79dbc4790894fc8c447c900740235a62cb0376f2b124dad3674acc
@@ -1,4 +1,4 @@
1
- # 1.1.2
1
+ # 1.1.3
2
2
 
3
3
  ## improvements
4
4
 
@@ -0,0 +1,6 @@
1
+ # 1.1.4
2
+
3
+ ## bugfixes
4
+
5
+ * datadog adapter: use `Gem::Version` to invoke the correct configuration API.
6
+ * stream plugin: do not preempt request enqueuing (this was making integration with the `:follow_redirects` plugin fail when set up with `webmock`).
@@ -0,0 +1,12 @@
1
+ # 1.1.5
2
+
3
+ ## improvements
4
+
5
+ * pattern matching support for responses has been backported to ruby 2.7 as well.
6
+
7
+ ## bugfixes
8
+
9
+ * `stream` plugin: fix for `HTTPX::StreamResponse#each_line` not yielding the last line of the payload when not delimiter-terminated.
10
+ * `stream` plugin: fix `webmock` adapter integration when methods calls would happen in the `HTTPX::StreamResponse#each` block.
11
+ * `stream` plugin: fix `:follow_redirects` plugin integration which was caching the redirect response and using it for method calls inside the `HTTPX::StreamResponse#each` block.
12
+ * "103 early hints" responses will be ignored when processing the response (it was causing the response returned by sesssions to hold its headers, instead of the following 200 response, while keeping the 200 response body).
@@ -126,7 +126,7 @@ module Datadog::Tracing
126
126
  option :distributed_tracing, default: true
127
127
  option :split_by_domain, default: false
128
128
 
129
- if DDTrace::VERSION::STRING >= "1.13.0"
129
+ if Gem::Version.new(DDTrace::VERSION::STRING) >= Gem::Version.new("1.13.0")
130
130
  option :enabled do |o|
131
131
  o.type :bool
132
132
  o.env "DD_TRACE_HTTPX_ENABLED"
@@ -182,12 +182,12 @@ module Datadog::Tracing
182
182
 
183
183
  option :distributed_tracing, default: true
184
184
 
185
- if DDTrace::VERSION::STRING >= "1.15.0"
185
+ if Gem::Version.new(DDTrace::VERSION::STRING) >= Gem::Version.new("1.15.0")
186
186
  option :error_handler do |o|
187
187
  o.type :proc
188
188
  o.default_proc(&DEFAULT_ERROR_HANDLER)
189
189
  end
190
- elsif DDTrace::VERSION::STRING >= "1.13.0"
190
+ elsif Gem::Version.new(DDTrace::VERSION::STRING) >= Gem::Version.new("1.13.0")
191
191
  option :error_handler do |o|
192
192
  o.type :proc
193
193
  o.experimental_default_proc(&DEFAULT_ERROR_HANDLER)
@@ -38,12 +38,10 @@ module WebMock
38
38
 
39
39
  return build_error_response(request, webmock_response.exception) if webmock_response.exception
40
40
 
41
- response = request.options.response_class.new(request,
42
- webmock_response.status[0],
43
- "2.0",
44
- webmock_response.headers)
45
- response << webmock_response.body.dup
46
- response
41
+ request.options.response_class.new(request,
42
+ webmock_response.status[0],
43
+ "2.0",
44
+ webmock_response.headers)
47
45
  end
48
46
 
49
47
  def build_error_response(request, exception)
@@ -90,6 +88,7 @@ module WebMock
90
88
  log { "mocking #{request.uri} with #{mock_response.inspect}" }
91
89
  request.response = response
92
90
  request.emit(:response, response)
91
+ response << mock_response.body.dup unless response.is_a?(HTTPX::ErrorResponse)
93
92
  elsif WebMock.net_connect_allowed?(request_signature.uri)
94
93
  if WebMock::CallbackRegistry.any_callbacks?
95
94
  request.on(:response) do |resp|
@@ -7,7 +7,7 @@ module HTTPX
7
7
  # the HTTP Authorization header, and another, +bearer_auth+, which fill the "Bearer " prefix
8
8
  # in its value.
9
9
  #
10
- # https://gitlab.com/os85/httpx/wikis/Auth#authorization
10
+ # https://gitlab.com/os85/httpx/wikis/Auth#auth
11
11
  #
12
12
  module Auth
13
13
  module InstanceMethods
@@ -5,7 +5,7 @@ module HTTPX
5
5
  #
6
6
  # This plugin adds helper methods to implement HTTP Basic Auth (https://tools.ietf.org/html/rfc7617)
7
7
  #
8
- # https://gitlab.com/os85/httpx/wikis/Authorization#basic-auth
8
+ # https://gitlab.com/os85/httpx/wikis/Auth#basic-auth
9
9
  #
10
10
  module BasicAuth
11
11
  class << self
@@ -5,7 +5,7 @@ module HTTPX
5
5
  #
6
6
  # This plugin adds helper methods to implement HTTP Digest Auth (https://tools.ietf.org/html/rfc7616)
7
7
  #
8
- # https://gitlab.com/os85/httpx/wikis/Authorization#digest-auth
8
+ # https://gitlab.com/os85/httpx/wikis/Auth#digest-auth
9
9
  #
10
10
  module DigestAuth
11
11
  DigestError = Class.new(Error)
@@ -11,6 +11,7 @@ module HTTPX
11
11
  @response = response
12
12
  @decoder = ->(z) { z }
13
13
  @consumed = false
14
+ @grpc_response = nil
14
15
  end
15
16
 
16
17
  def inspect
@@ -34,9 +35,7 @@ module HTTPX
34
35
  private
35
36
 
36
37
  def grpc_response
37
- return @grpc_response if defined?(@grpc_response)
38
-
39
- @grpc_response = if @response.respond_to?(:each)
38
+ @grpc_response ||= if @response.respond_to?(:each)
40
39
  Enumerator.new do |y|
41
40
  Message.stream(@response).each do |message|
42
41
  y << @decoder.call(message)
@@ -36,8 +36,8 @@ module HTTPX
36
36
 
37
37
  class Inflater
38
38
  def initialize(response)
39
- @encodings = response.headers.get("grpc-encoding")
40
39
  @response = response
40
+ @grpc_encodings = nil
41
41
  end
42
42
 
43
43
  def call(message, &blk)
@@ -49,7 +49,7 @@ module HTTPX
49
49
  encoded_data = message.byteslice(5..size + 5 - 1)
50
50
 
51
51
  if compressed == 1
52
- @encodings.reverse_each do |encoding|
52
+ grpc_encodings.reverse_each do |encoding|
53
53
  decoder = @response.body.class.initialize_inflater_by_encoding(encoding, @response, bytesize: encoded_data.bytesize)
54
54
  encoded_data = decoder.call(encoded_data)
55
55
 
@@ -68,6 +68,12 @@ module HTTPX
68
68
 
69
69
  data
70
70
  end
71
+
72
+ private
73
+
74
+ def grpc_encodings
75
+ @grpc_encodings ||= @response.headers.get("grpc-encoding")
76
+ end
71
77
  end
72
78
 
73
79
  def self.encode(*args, **kwargs)
@@ -215,7 +215,7 @@ module HTTPX
215
215
  **opts)
216
216
  grpc_request = build_grpc_request(rpc_method, input, deadline: deadline, metadata: metadata, **opts)
217
217
  response = request(grpc_request, **opts)
218
- response.raise_for_status
218
+ response.raise_for_status unless opts[:stream]
219
219
  GRPC::Call.new(response)
220
220
  end
221
221
 
@@ -3,7 +3,7 @@
3
3
  module HTTPX
4
4
  module Plugins
5
5
  #
6
- # https://gitlab.com/os85/httpx/wikis/Authorization#ntlm-auth
6
+ # https://gitlab.com/os85/httpx/wikis/Auth#ntlm-auth
7
7
  #
8
8
  module NTLMAuth
9
9
  class << self
@@ -2,10 +2,10 @@
2
2
 
3
3
  module HTTPX
4
4
  class StreamResponse
5
- def initialize(request, session, connections)
5
+ def initialize(request, session)
6
6
  @request = request
7
7
  @session = session
8
- @connections = connections
8
+ @response = nil
9
9
  end
10
10
 
11
11
  def each(&block)
@@ -16,19 +16,9 @@ module HTTPX
16
16
  begin
17
17
  @on_chunk = block
18
18
 
19
- if @request.response
20
- # if we've already started collecting the payload, yield it first
21
- # before proceeding
22
- body = @request.response.body
23
-
24
- body.each do |chunk|
25
- on_chunk(chunk)
26
- end
27
- end
28
-
29
19
  response.raise_for_status
30
- response.close
31
20
  ensure
21
+ response.close if @response
32
22
  @on_chunk = nil
33
23
  end
34
24
  end
@@ -36,7 +26,7 @@ module HTTPX
36
26
  def each_line
37
27
  return enum_for(__method__) unless block_given?
38
28
 
39
- line = +""
29
+ line = "".b
40
30
 
41
31
  each do |chunk|
42
32
  line << chunk
@@ -47,6 +37,8 @@ module HTTPX
47
37
  line = line.byteslice(idx + 1..-1)
48
38
  end
49
39
  end
40
+
41
+ yield line unless line.empty?
50
42
  end
51
43
 
52
44
  # This is a ghost method. It's to be used ONLY internally, when processing streams
@@ -69,9 +61,11 @@ module HTTPX
69
61
  private
70
62
 
71
63
  def response
72
- @session.__send__(:receive_requests, [@request], @connections) until @request.response
64
+ return @response if @response
73
65
 
74
- @request.response
66
+ @request.response || begin
67
+ @response = @session.request(@request)
68
+ end
75
69
  end
76
70
 
77
71
  def respond_to_missing?(meth, *args)
@@ -105,9 +99,7 @@ module HTTPX
105
99
 
106
100
  request = requests.first
107
101
 
108
- connections = _send_requests(requests)
109
-
110
- StreamResponse.new(request, self, connections)
102
+ StreamResponse.new(request, self)
111
103
  end
112
104
  end
113
105
 
data/lib/httpx/request.rb CHANGED
@@ -119,10 +119,21 @@ module HTTPX
119
119
  def response=(response)
120
120
  return unless response
121
121
 
122
- if response.is_a?(Response) && response.status == 100 && @headers.key?("expect")
123
- @informational_status = response.status
124
- return
122
+ if response.is_a?(Response) && response.status < 200
123
+ # deal with informational responses
124
+
125
+ if response.status == 100 && @headers.key?("expect")
126
+ @informational_status = response.status
127
+ return
128
+ end
129
+
130
+ if response.status >= 103
131
+ # 103 Early Hints advertises resources in document to browsers.
132
+ # not very relevant for an HTTP client, discard.
133
+ return
134
+ end
125
135
  end
136
+
126
137
  @response = response
127
138
 
128
139
  emit(:response_started, response)
@@ -264,4 +264,4 @@ end
264
264
 
265
265
  require_relative "response/body"
266
266
  require_relative "response/buffer"
267
- require_relative "pmatch_extensions" if RUBY_VERSION >= "3.0.0"
267
+ require_relative "pmatch_extensions" if RUBY_VERSION >= "2.7.0"
data/lib/httpx/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HTTPX
4
- VERSION = "1.1.3"
4
+ VERSION = "1.1.5"
5
5
  end
@@ -21,11 +21,15 @@ module HTTPX
21
21
 
22
22
  class Inflater
23
23
  @response: Response
24
- @encodings: Array[String]
24
+ @grpc_encodings: Array[String]
25
25
 
26
26
  def initialize: (Response | StreamResponse response) -> void
27
27
 
28
28
  def call: (String message) ?{ (String) -> void } -> String
29
+
30
+ private
31
+
32
+ def grpc_encodings: () -> Array[String]
29
33
  end
30
34
 
31
35
  end
@@ -1,21 +1,4 @@
1
1
  module HTTPX
2
- class StreamResponse
3
- include _ToS
4
-
5
- def each: () { (String) -> void } -> void
6
- | () -> Enumerable[String]
7
-
8
- def each_line: () { (String) -> void } -> void
9
- | () -> Enumerable[String]
10
-
11
- def on_chunk: (string) -> void
12
-
13
- private
14
-
15
- def response: () -> response
16
- def initialize: (Request, Session, Array[Connection]) -> untyped
17
- end
18
-
19
2
  module Plugins
20
3
  module Stream
21
4
  module InstanceMethods
@@ -37,4 +20,28 @@ module HTTPX
37
20
 
38
21
  type sessionStream = Session & Stream::InstanceMethods
39
22
  end
23
+
24
+ class StreamResponse
25
+ include _ToS
26
+
27
+ type streamRequest = Request & Plugins::Stream::RequestMethods
28
+
29
+ @request: streamRequest
30
+ @session: Plugins::sessionStream
31
+ @on_chunk: ^(String) -> void | nil
32
+
33
+ def each: () { (String) -> void } -> void
34
+ | () -> Enumerable[String]
35
+
36
+ def each_line: () { (String) -> void } -> void
37
+ | () -> Enumerable[String]
38
+
39
+ def on_chunk: (string) -> void
40
+
41
+ def initialize: (streamRequest, Plugins::sessionStream) -> void
42
+
43
+ private
44
+
45
+ def response: () -> response
46
+ end
40
47
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: httpx
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tiago Cardoso
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-11-17 00:00:00.000000000 Z
11
+ date: 2023-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http-2-next
@@ -135,6 +135,8 @@ extra_rdoc_files:
135
135
  - doc/release_notes/1_1_1.md
136
136
  - doc/release_notes/1_1_2.md
137
137
  - doc/release_notes/1_1_3.md
138
+ - doc/release_notes/1_1_4.md
139
+ - doc/release_notes/1_1_5.md
138
140
  files:
139
141
  - LICENSE.txt
140
142
  - README.md
@@ -241,6 +243,8 @@ files:
241
243
  - doc/release_notes/1_1_1.md
242
244
  - doc/release_notes/1_1_2.md
243
245
  - doc/release_notes/1_1_3.md
246
+ - doc/release_notes/1_1_4.md
247
+ - doc/release_notes/1_1_5.md
244
248
  - lib/httpx.rb
245
249
  - lib/httpx/adapters/datadog.rb
246
250
  - lib/httpx/adapters/faraday.rb