httpx 1.2.2 → 1.2.3

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: 7aff2acc77577cb1243c30a63766f404755131c2f1b19162b9b6ba13c49d61f8
4
- data.tar.gz: 6297b0857edce0f5d93a0272c2b5e891257969c36cbf0c34c6a7ca6e4a5ced67
3
+ metadata.gz: 8803154870d8bd0f45f67ce543072fcc42d789400ca0c9251d3ea99f5f214562
4
+ data.tar.gz: 87024f70caa91f93711b6a185a8e3dc7b8987d695472abd13a5a4cb92243d37c
5
5
  SHA512:
6
- metadata.gz: 94da91dd14a8318e8f0a0199214f97c008b927c7b8d9f602f045434bbd375b4446c767ed805e424d826c3dc48e90a8a0fded192858d32763c4c38033e0107cae
7
- data.tar.gz: 657cefe9a977ca56dddda02bbdb07a94b4a8f158193e5f0d695c254bdbcafd95ffccd29641d38958d16468a81fd236f4d95ef4487c335cf7e079fb29b8d456ba
6
+ metadata.gz: ba28ac993c5b17d4d13db24240214a40cfbae5eac5fad40e6420e42725356a289ee33fcb02492bc382d2c26ce93a0696acf7f5f8d64ddf430136ee829f717b70
7
+ data.tar.gz: 93c174e3d210681f1c76127f7a3a69adf43d8a5b3c31432ae0b6e08abd96ca7d189399081efeed710f8c43566e3290931d04b2c38df7de0251508933b2fca129
@@ -0,0 +1,16 @@
1
+ # 1.2.3
2
+
3
+ ## Improvements
4
+
5
+ * `:retries` plugin: allow `:max_retries` set to 0 (allows for a soft disable of retries when using the faraday adapter).
6
+
7
+ ## Bugfixes
8
+
9
+ * `:oauth` plugin: fix for default auth method being ignored when setting grant type and scope as options only.
10
+ * ensure happy eyeballs-initiated cloned connections also set session callbacks (caused issues when server would respond with a 421 response, an event requiring a valid internal callback).
11
+ * native resolver cleanly transitions from tcp to udp after truncated DNS query (causing issues on follow-up CNAME resolution).
12
+ * elapsing timeouts now guard against mutation of callbacks while looping (prevents skipping callbacks in situations where a previous one would remove itself from the collection).
13
+
14
+ ## Chore
15
+
16
+ * datadog adapter: do not call `.lazy` on options (avoids deprecation warning, to be removed in ddtrace 2.0)
@@ -169,14 +169,14 @@ module Datadog::Tracing
169
169
  "httpx"
170
170
  )
171
171
  end
172
- o.lazy
172
+ o.lazy unless Gem::Version.new(DDTrace::VERSION::STRING) >= Gem::Version.new("1.13.0")
173
173
  end
174
174
  else
175
175
  option :service_name do |o|
176
176
  o.default do
177
177
  ENV.fetch("DD_TRACE_HTTPX_SERVICE_NAME", "httpx")
178
178
  end
179
- o.lazy
179
+ o.lazy unless Gem::Version.new(DDTrace::VERSION::STRING) >= Gem::Version.new("1.13.0")
180
180
  end
181
181
  end
182
182
 
@@ -16,7 +16,7 @@ module HTTPX
16
16
  SUPPORTED_AUTH_METHODS = %w[client_secret_basic client_secret_post].freeze
17
17
 
18
18
  class OAuthSession
19
- attr_reader :token_endpoint_auth_method, :grant_type, :client_id, :client_secret, :access_token, :refresh_token, :scope
19
+ attr_reader :grant_type, :client_id, :client_secret, :access_token, :refresh_token, :scope
20
20
 
21
21
  def initialize(
22
22
  issuer:,
@@ -28,7 +28,7 @@ module HTTPX
28
28
  token_endpoint: nil,
29
29
  response_type: nil,
30
30
  grant_type: nil,
31
- token_endpoint_auth_method: "client_secret_basic"
31
+ token_endpoint_auth_method: nil
32
32
  )
33
33
  @issuer = URI(issuer)
34
34
  @client_id = client_id
@@ -43,10 +43,10 @@ module HTTPX
43
43
  end
44
44
  @access_token = access_token
45
45
  @refresh_token = refresh_token
46
- @token_endpoint_auth_method = String(token_endpoint_auth_method)
46
+ @token_endpoint_auth_method = String(token_endpoint_auth_method) if token_endpoint_auth_method
47
47
  @grant_type = grant_type || (@refresh_token ? "refresh_token" : "client_credentials")
48
48
 
49
- unless SUPPORTED_AUTH_METHODS.include?(@token_endpoint_auth_method)
49
+ unless @token_endpoint_auth_method.nil? || SUPPORTED_AUTH_METHODS.include?(@token_endpoint_auth_method)
50
50
  raise Error, "#{@token_endpoint_auth_method} is not a supported auth method"
51
51
  end
52
52
 
@@ -59,8 +59,12 @@ module HTTPX
59
59
  @token_endpoint || "#{@issuer}/token"
60
60
  end
61
61
 
62
+ def token_endpoint_auth_method
63
+ @token_endpoint_auth_method || "client_secret_basic"
64
+ end
65
+
62
66
  def load(http)
63
- return if @token_endpoint_auth_method && @grant_type && @scope
67
+ return if @grant_type && @scope
64
68
 
65
69
  metadata = http.get("#{@issuer}/.well-known/oauth-authorization-server").raise_for_status.json
66
70
 
@@ -123,11 +127,11 @@ module HTTPX
123
127
 
124
128
  # auth
125
129
  case oauth_session.token_endpoint_auth_method
126
- when "client_secret_basic"
127
- headers["authorization"] = Authentication::Basic.new(oauth_session.client_id, oauth_session.client_secret).authenticate
128
130
  when "client_secret_post"
129
131
  form_post["client_id"] = oauth_session.client_id
130
132
  form_post["client_secret"] = oauth_session.client_secret
133
+ when "client_secret_basic"
134
+ headers["authorization"] = Authentication::Basic.new(oauth_session.client_id, oauth_session.client_secret).authenticate
131
135
  end
132
136
 
133
137
  case grant_type
@@ -58,7 +58,7 @@ module HTTPX
58
58
 
59
59
  def option_max_retries(value)
60
60
  num = Integer(value)
61
- raise TypeError, ":max_retries must be positive" unless num.positive?
61
+ raise TypeError, ":max_retries must be positive" unless num >= 0
62
62
 
63
63
  num
64
64
  end
data/lib/httpx/pool.rb CHANGED
@@ -179,6 +179,7 @@ module HTTPX
179
179
  connection.once(:connect_error) do |err|
180
180
  if new_connection.connecting?
181
181
  new_connection.merge(connection)
182
+ connection.emit(:cloned, new_connection)
182
183
  connection.force_reset
183
184
  else
184
185
  connection.__send__(:handle_error, err)
@@ -195,6 +196,7 @@ module HTTPX
195
196
  if connection.connecting?
196
197
  # main connection has the requests
197
198
  connection.merge(new_connection)
199
+ new_connection.emit(:cloned, connection)
198
200
  new_connection.force_reset
199
201
  else
200
202
  new_connection.__send__(:handle_error, err)
@@ -187,10 +187,10 @@ module HTTPX
187
187
  next unless @large_packet.full?
188
188
 
189
189
  parse(@large_packet.to_s)
190
-
191
190
  @socket_type = @resolver_options.fetch(:socket_type, :udp)
192
191
  @large_packet = nil
193
- transition(:closed)
192
+ transition(:idle)
193
+ transition(:open)
194
194
  return
195
195
  else
196
196
  size = @read_buffer[0, 2].unpack1("n")
@@ -7,10 +7,18 @@ require "fileutils"
7
7
  require "forwardable"
8
8
 
9
9
  module HTTPX
10
- # Defines a HTTP response is handled internally, with a few properties exposed as attributes,
11
- # implements (indirectly, via the +body+) the IO write protocol to internally buffer payloads,
12
- # implements the IO reader protocol in order for users to buffer/stream it, acts as an enumerable
10
+ # Defines a HTTP response is handled internally, with a few properties exposed as attributes.
11
+ #
12
+ # It delegates the following methods to the corresponding HTTPX::Request:
13
+ #
14
+ # * HTTPX::Request#uri
15
+ # * HTTPX::Request#peer_address
16
+ #
17
+ # It implements (indirectly, via the +body+) the IO write protocol to internally buffer payloads.
18
+ #
19
+ # It implements the IO reader protocol in order for users to buffer/stream it, acts as an enumerable
13
20
  # (of payload chunks).
21
+ #
14
22
  class Response
15
23
  extend Forwardable
16
24
  include Callbacks
@@ -21,7 +29,13 @@ module HTTPX
21
29
  # an HTTPX::Headers object containing the response HTTP headers.
22
30
  attr_reader :headers
23
31
 
24
- # a HTTPX::Response::Body object wrapping the response body.
32
+ # a HTTPX::Response::Body object wrapping the response body. The following methods are delegated to it:
33
+ #
34
+ # * HTTPX::Response::Body#to_s
35
+ # * HTTPX::Response::Body#to_str
36
+ # * HTTPX::Response::Body#read
37
+ # * HTTPX::Response::Body#copy_to
38
+ # * HTTPX::Response::Body#close
25
39
  attr_reader :body
26
40
 
27
41
  # The HTTP protocol version used to fetch the response.
data/lib/httpx/session.rb CHANGED
@@ -138,7 +138,7 @@ module HTTPX
138
138
 
139
139
  # sets the callbacks on the +connection+ required to process certain specific
140
140
  # connection lifecycle events which deal with request rerouting.
141
- def set_connection_callbacks(connection, connections, options)
141
+ def set_connection_callbacks(connection, connections, options, cloned: false)
142
142
  connection.only(:misdirected) do |misdirected_request|
143
143
  other_connection = connection.create_idle(ssl: { alpn_protocols: %w[http/1.1] })
144
144
  other_connection.merge(connection)
@@ -154,6 +154,10 @@ module HTTPX
154
154
  other_connection = build_altsvc_connection(connection, connections, alt_origin, origin, alt_params, options)
155
155
  connections << other_connection if other_connection
156
156
  end
157
+ connection.only(:cloned) do |cloned_conn|
158
+ set_connection_callbacks(cloned_conn, connections, options, cloned: true)
159
+ connections << cloned_conn
160
+ end unless cloned
157
161
  end
158
162
 
159
163
  # returns an HTTPX::Connection for the negotiated Alternative Service (or none).
data/lib/httpx/timers.rb CHANGED
@@ -97,7 +97,10 @@ module HTTPX
97
97
  def elapse(elapsed)
98
98
  @interval -= elapsed
99
99
 
100
- @callbacks.each(&:call) if @interval <= 0
100
+ if @interval <= 0
101
+ cb = @callbacks.dup
102
+ cb.each(&:call)
103
+ end
101
104
 
102
105
  @interval
103
106
  end
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.2.2"
4
+ VERSION = "1.2.3"
5
5
  end
@@ -15,8 +15,6 @@ module HTTPX
15
15
  SUPPORTED_AUTH_METHODS: ::Array[token_auth_method]
16
16
 
17
17
  class OAuthSession
18
- attr_reader token_endpoint_auth_method: token_auth_method
19
-
20
18
  attr_reader grant_type: grant_type
21
19
 
22
20
  attr_reader client_id: String
@@ -33,6 +31,8 @@ module HTTPX
33
31
 
34
32
  def token_endpoint: () -> String
35
33
 
34
+ def token_endpoint_auth_method: () -> token_auth_method
35
+
36
36
  def load: (Session http) -> void
37
37
 
38
38
  def merge: (instance | Hash[untyped, untyped] other) -> instance
data/sig/session.rbs CHANGED
@@ -31,7 +31,7 @@ module HTTPX
31
31
 
32
32
  def send_request: (Request request, Array[Connection] connections, ?Options options) -> void
33
33
 
34
- def set_connection_callbacks: (Connection connection, Array[Connection] connections, Options options) -> void
34
+ def set_connection_callbacks: (Connection connection, Array[Connection] connections, Options options, ?cloned: bool) -> void
35
35
 
36
36
  def set_request_callbacks: (Request request) -> void
37
37
 
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.2.2
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tiago Cardoso
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-02 00:00:00.000000000 Z
11
+ date: 2024-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http-2-next
@@ -140,6 +140,7 @@ extra_rdoc_files:
140
140
  - doc/release_notes/1_2_0.md
141
141
  - doc/release_notes/1_2_1.md
142
142
  - doc/release_notes/1_2_2.md
143
+ - doc/release_notes/1_2_3.md
143
144
  files:
144
145
  - LICENSE.txt
145
146
  - README.md
@@ -251,6 +252,7 @@ files:
251
252
  - doc/release_notes/1_2_0.md
252
253
  - doc/release_notes/1_2_1.md
253
254
  - doc/release_notes/1_2_2.md
255
+ - doc/release_notes/1_2_3.md
254
256
  - lib/httpx.rb
255
257
  - lib/httpx/adapters/datadog.rb
256
258
  - lib/httpx/adapters/faraday.rb