httpx 0.24.7 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +0 -48
  3. data/README.md +4 -13
  4. data/doc/release_notes/0_24_4.md +3 -3
  5. data/doc/release_notes/1_0_0.md +60 -0
  6. data/lib/httpx/adapters/datadog.rb +40 -141
  7. data/lib/httpx/adapters/faraday.rb +9 -52
  8. data/lib/httpx/adapters/webmock.rb +2 -7
  9. data/lib/httpx/altsvc.rb +4 -22
  10. data/lib/httpx/base64.rb +27 -0
  11. data/lib/httpx/chainable.rb +0 -23
  12. data/lib/httpx/connection.rb +11 -32
  13. data/lib/httpx/domain_name.rb +5 -12
  14. data/lib/httpx/errors.rb +0 -2
  15. data/lib/httpx/extensions.rb +0 -124
  16. data/lib/httpx/io/ssl.rb +26 -59
  17. data/lib/httpx/io/tcp.rb +27 -68
  18. data/lib/httpx/io/udp.rb +13 -48
  19. data/lib/httpx/io/unix.rb +1 -8
  20. data/lib/httpx/loggable.rb +4 -19
  21. data/lib/httpx/options.rb +24 -84
  22. data/lib/httpx/plugins/{authentication → auth}/basic.rb +1 -5
  23. data/lib/httpx/plugins/{authentication → auth}/digest.rb +2 -5
  24. data/lib/httpx/plugins/{authentication → auth}/ntlm.rb +1 -3
  25. data/lib/httpx/plugins/{authentication → auth}/socks5.rb +0 -2
  26. data/lib/httpx/plugins/auth.rb +25 -0
  27. data/lib/httpx/plugins/aws_sigv4.rb +0 -1
  28. data/lib/httpx/plugins/{basic_authentication.rb → basic_auth.rb} +5 -6
  29. data/lib/httpx/plugins/brotli.rb +50 -0
  30. data/lib/httpx/plugins/circuit_breaker/circuit.rb +40 -16
  31. data/lib/httpx/plugins/circuit_breaker/circuit_store.rb +16 -5
  32. data/lib/httpx/plugins/circuit_breaker.rb +11 -4
  33. data/lib/httpx/plugins/cookies/set_cookie_parser.rb +0 -2
  34. data/lib/httpx/plugins/cookies.rb +1 -1
  35. data/lib/httpx/plugins/{digest_authentication.rb → digest_auth.rb} +5 -5
  36. data/lib/httpx/plugins/follow_redirects.rb +21 -24
  37. data/lib/httpx/plugins/grpc/grpc_encoding.rb +82 -0
  38. data/lib/httpx/plugins/grpc/message.rb +7 -39
  39. data/lib/httpx/plugins/grpc.rb +19 -37
  40. data/lib/httpx/plugins/h2c.rb +0 -1
  41. data/lib/httpx/plugins/{ntlm_authentication.rb → ntlm_auth.rb} +5 -5
  42. data/lib/httpx/plugins/oauth.rb +2 -2
  43. data/lib/httpx/plugins/proxy/http.rb +0 -2
  44. data/lib/httpx/plugins/proxy/socks4.rb +0 -4
  45. data/lib/httpx/plugins/proxy/socks5.rb +1 -5
  46. data/lib/httpx/plugins/proxy.rb +3 -32
  47. data/lib/httpx/plugins/retries.rb +3 -4
  48. data/lib/httpx/plugins/stream.rb +4 -6
  49. data/lib/httpx/punycode.rb +9 -291
  50. data/lib/httpx/request/body.rb +145 -0
  51. data/lib/httpx/request.rb +2 -119
  52. data/lib/httpx/resolver/https.rb +1 -1
  53. data/lib/httpx/resolver/native.rb +6 -14
  54. data/lib/httpx/resolver/resolver.rb +1 -1
  55. data/lib/httpx/resolver/system.rb +11 -9
  56. data/lib/httpx/response/body.rb +206 -0
  57. data/lib/httpx/response/buffer.rb +90 -0
  58. data/lib/httpx/response.rb +5 -208
  59. data/lib/httpx/selector.rb +0 -2
  60. data/lib/httpx/session.rb +0 -10
  61. data/lib/httpx/transcoder/body.rb +0 -1
  62. data/lib/httpx/transcoder/deflate.rb +37 -0
  63. data/lib/httpx/transcoder/form.rb +52 -32
  64. data/lib/httpx/transcoder/gzip.rb +74 -0
  65. data/lib/httpx/transcoder/json.rb +2 -4
  66. data/lib/httpx/transcoder/multipart/decoder.rb +139 -0
  67. data/lib/httpx/{plugins → transcoder}/multipart/encoder.rb +3 -3
  68. data/lib/httpx/{plugins → transcoder}/multipart/mime_type_detector.rb +1 -1
  69. data/lib/httpx/{plugins → transcoder}/multipart/part.rb +3 -2
  70. data/lib/httpx/transcoder/multipart.rb +17 -0
  71. data/lib/httpx/transcoder/utils/body_reader.rb +46 -0
  72. data/lib/httpx/transcoder/utils/deflater.rb +72 -0
  73. data/lib/httpx/transcoder/xml.rb +0 -2
  74. data/lib/httpx/transcoder.rb +2 -2
  75. data/lib/httpx/utils.rb +10 -20
  76. data/lib/httpx/version.rb +1 -1
  77. data/lib/httpx.rb +0 -8
  78. data/sig/chainable.rbs +5 -6
  79. data/sig/connection.rbs +0 -1
  80. data/sig/errors.rbs +0 -3
  81. data/sig/httpx.rbs +2 -1
  82. data/sig/io/unix.rbs +1 -1
  83. data/sig/options.rbs +12 -8
  84. data/sig/plugins/{authentication → auth}/basic.rbs +0 -2
  85. data/sig/plugins/auth.rbs +13 -0
  86. data/sig/plugins/{basic_authentication.rbs → basic_auth.rbs} +2 -2
  87. data/sig/plugins/brotli.rbs +22 -0
  88. data/sig/plugins/circuit_breaker.rbs +7 -3
  89. data/sig/plugins/compression.rbs +0 -2
  90. data/sig/plugins/{digest_authentication.rbs → digest_auth.rbs} +2 -2
  91. data/sig/plugins/follow_redirects.rbs +0 -1
  92. data/sig/plugins/grpc/call.rbs +19 -0
  93. data/sig/plugins/grpc/grpc_encoding.rbs +33 -0
  94. data/sig/plugins/grpc/message.rbs +17 -0
  95. data/sig/plugins/grpc.rbs +2 -32
  96. data/sig/plugins/{ntlm_authentication.rbs → ntlm_auth.rbs} +2 -2
  97. data/sig/plugins/oauth.rbs +1 -1
  98. data/sig/plugins/proxy/socks4.rbs +2 -3
  99. data/sig/plugins/proxy/socks5.rbs +0 -1
  100. data/sig/plugins/proxy/ssh.rbs +1 -1
  101. data/sig/plugins/response_cache.rbs +5 -2
  102. data/sig/request/body.rbs +42 -0
  103. data/sig/request.rbs +1 -27
  104. data/sig/resolver/resolver.rbs +1 -1
  105. data/sig/response/body.rbs +52 -0
  106. data/sig/response/buffer.rbs +24 -0
  107. data/sig/response.rbs +0 -39
  108. data/sig/transcoder/body.rbs +4 -3
  109. data/sig/transcoder/deflate.rbs +11 -0
  110. data/sig/transcoder/form.rbs +5 -3
  111. data/sig/transcoder/gzip.rbs +24 -0
  112. data/sig/transcoder/json.rbs +4 -2
  113. data/sig/{plugins → transcoder}/multipart.rbs +3 -10
  114. data/sig/transcoder/utils/body_reader.rbs +15 -0
  115. data/sig/transcoder/utils/deflater.rbs +29 -0
  116. data/sig/transcoder.rbs +18 -2
  117. metadata +50 -36
  118. data/doc/release_notes/0_24_7.md +0 -10
  119. data/lib/httpx/plugins/authentication.rb +0 -24
  120. data/lib/httpx/plugins/compression/brotli.rb +0 -54
  121. data/lib/httpx/plugins/compression/deflate.rb +0 -54
  122. data/lib/httpx/plugins/compression/gzip.rb +0 -90
  123. data/lib/httpx/plugins/compression.rb +0 -165
  124. data/lib/httpx/plugins/multipart/decoder.rb +0 -137
  125. data/lib/httpx/plugins/multipart.rb +0 -96
  126. data/sig/plugins/authentication.rbs +0 -13
  127. data/sig/plugins/compression/brotli.rbs +0 -21
  128. data/sig/plugins/compression/deflate.rbs +0 -17
  129. data/sig/plugins/compression/gzip.rbs +0 -29
  130. /data/sig/plugins/{authentication → auth}/digest.rbs +0 -0
  131. /data/sig/plugins/{authentication → auth}/ntlm.rbs +0 -0
  132. /data/sig/plugins/{authentication → auth}/socks5.rbs +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 06e8fd5ae58c24b0e8d71267133209622fad2e16e2196403937f3d330330fc72
4
- data.tar.gz: 2684eb339c078326609390667a8c9522225fdf56ff2fdece7571022c110d96fc
3
+ metadata.gz: 40c3560dd37c1fc898a5e0beb5a73148285cdae564ee285552aaf4ccb42bc06a
4
+ data.tar.gz: 0463ddfdb74f304264c28c513cac13c05d0b0bfc6089a7466d251c8cd94e8782
5
5
  SHA512:
6
- metadata.gz: fc776c73232482381b6c8861cd6b743b16e2ccd03a8aa2764ccb30668c6e13ca3a560b51d66f0569cbf1f0d71c2ad101ad04e3b1c187336496b6424633b12e41
7
- data.tar.gz: aaa3cbf6a87825896331a2cd0aa2604e82738510507cade210092fcbb060456765750ed3e13af1395fc1cc998abf0c6222eda776f27d152e9e46c406ed3cce4d
6
+ metadata.gz: 7a041d6c249f44a8f3c8c0fe4d776722b08e704ef76ba1b6e6a9791a0f7f1dbd191f7c2aa6f8f621ef2a4cb70af51c8ed7ec81653b28e9fd669f8da3687c0423
7
+ data.tar.gz: 8071a59d3a00d64981625cdb7e37dbd5749d3baaa597bb78bf8d777559cd6faadd012c6fbad1482a93dfafe5da47650f3059b72665823e197529655ab73c30eb
data/LICENSE.txt CHANGED
@@ -189,51 +189,3 @@
189
189
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
190
190
  See the License for the specific language governing permissions and
191
191
  limitations under the License.
192
-
193
-
194
- * lib/httpx/domain_name.rb
195
-
196
- This file is derived from the implementation of punycode available at
197
- here:
198
-
199
- https://www.verisign.com/en_US/channel-resources/domain-registry-products/idn-sdks/index.xhtml
200
-
201
- Copyright (C) 2000-2002 Verisign Inc., All rights reserved.
202
-
203
- Redistribution and use in source and binary forms, with or
204
- without modification, are permitted provided that the following
205
- conditions are met:
206
-
207
- 1) Redistributions of source code must retain the above copyright
208
- notice, this list of conditions and the following disclaimer.
209
-
210
- 2) Redistributions in binary form must reproduce the above copyright
211
- notice, this list of conditions and the following disclaimer in
212
- the documentation and/or other materials provided with the
213
- distribution.
214
-
215
- 3) Neither the name of the VeriSign Inc. nor the names of its
216
- contributors may be used to endorse or promote products derived
217
- from this software without specific prior written permission.
218
-
219
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
220
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
221
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
222
- FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
223
- COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
224
- INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
225
- BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
226
- OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
227
- AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
228
- LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
229
- ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
230
- POSSIBILITY OF SUCH DAMAGE.
231
-
232
- This software is licensed under the BSD open source license. For more
233
- information visit www.opensource.org.
234
-
235
- Authors:
236
- John Colosi (VeriSign)
237
- Srikanth Veeramachaneni (VeriSign)
238
- Nagesh Chigurupati (Verisign)
239
- Praveen Srinivasan(Verisign)
data/README.md CHANGED
@@ -19,7 +19,7 @@ And also:
19
19
 
20
20
  * Compression (gzip, deflate, brotli)
21
21
  * Streaming Requests
22
- * Authentication (Basic Auth, Digest Auth, NTLM)
22
+ * Auth (Basic Auth, Digest Auth, NTLM)
23
23
  * Expect 100-continue
24
24
  * Multipart Requests
25
25
  * Advanced Cookie handling
@@ -113,7 +113,7 @@ response = HTTPX.plugin(:basic_authentication)
113
113
  .get("https://www.google.com")
114
114
 
115
115
  # more complex client objects can be cached, and are thread-safe
116
- http = HTTPX.plugin(:compression).plugin(:expect).with(headers: { "x-pvt-token" => "TOKEN"})
116
+ http = HTTPX.plugin(:expect).with(headers: { "x-pvt-token" => "TOKEN"})
117
117
  http.get("https://example.com") # the above options will apply
118
118
  http.post("https://example2.com", form: {name: "John", age: "22"}) # same, plus the form POST body
119
119
  ```
@@ -134,9 +134,9 @@ The test suite runs against [httpbin proxied over nghttp2](https://nghttp2.org/h
134
134
 
135
135
  ## Supported Rubies
136
136
 
137
- All Rubies greater or equal to 2.1, and always latest JRuby and Truffleruby.
137
+ All Rubies greater or equal to 2.7, and always latest JRuby and Truffleruby.
138
138
 
139
- **Note**: This gem is tested against all latest patch versions, i.e. if you're using 2.2.0 and you experience some issue, please test it against 2.2.10 (latest patch version of 2.2) before creating an issue.
139
+ **Note**: This gem is tested against all latest patch versions, i.e. if you're using 3.2.0 and you experience some issue, please test it against 3.2.$latest before creating an issue.
140
140
 
141
141
  ## Resources
142
142
  | | |
@@ -149,15 +149,6 @@ All Rubies greater or equal to 2.1, and always latest JRuby and Truffleruby.
149
149
 
150
150
  ## Caveats
151
151
 
152
- ### ALPN support
153
-
154
- ALPN negotiation is required for "auto" HTTP/2 "https" requests. This is available in ruby since version 2.3 .
155
-
156
- ### Known bugs
157
-
158
- * Doesn't work with ruby 2.4.0 for Windows (see [#36](https://gitlab.com/os85/httpx/issues/36)).
159
- * Using `total_timeout` along with the `:persistent` plugin [does not work as you might expect](https://gitlab.com/os85/httpx/-/wikis/Timeouts#total_timeout).
160
-
161
152
  ## Versioning Policy
162
153
 
163
154
  Although 0.x software, `httpx` is considered API-stable and production-ready, i.e. current API or options may be subject to deprecation and emit log warnings, but can only effectively be removed in a major version change.
@@ -8,11 +8,11 @@
8
8
  * whenever possible, `httpx` sessions will recycle used connections so that, in the case of TLS connections, the first session will keep being reusedd, thereby diminishing the overhead of subsequent TLS handshakes on the same host.
9
9
  * TLS sessions are only reused in the scope of the same `httpx` session, unless the `:persistent` plugin is used, in which case, the persisted `httpx` session will always try to resume TLS sessions.
10
10
 
11
- ## Bugfixess
11
+ ## Bugfixes
12
12
 
13
13
  * When explicitly using IP addresses in the URL host, TLS handshake will now verify tif he IP address is included in the certificate.
14
14
  * IP address will keep not be used for SNI, as per RFC 6066, section 3.
15
15
  * ex: `http.get("https://10.12.0.12/get")`
16
- * if you want the prior behavior, set `HTTPX.with(ssl: {verify_hostname: faalse})`
16
+ * if you want the prior behavior, set `HTTPX.with(ssl: {verify_hostname: false})`
17
17
  * Turn TLS hostname verification on for `jruby` (it's turned off by default).
18
- * if you want the prior behavior, set `HTTPX.with(ssl: {verify_hostname: faalse})`
18
+ * if you want the prior behavior, set `HTTPX.with(ssl: {verify_hostname: false})`
@@ -0,0 +1,60 @@
1
+ # 1.0.0
2
+
3
+ ## Breaking changes
4
+
5
+ * the minimum supported ruby version is 2.7.0 .
6
+ * The fallback support for IDNA 2003 has been removed. If you require this feature, install the [idnx gem](https://github.com/HoneyryderChuck/idnx), which `httpx` automatically integrates with when available (and supports IDNA 2008).
7
+ * `:total_timeout` option has been removed (no session-wide timeout supported, use `:request_timeout`).
8
+ * `:read_timeout` and `:write_timeout` are now set to 60 seconds by default, and preferred over `:operation_timeout`;
9
+ * the exception being in the `:stream` plugin, as the response is theoretically endless (so `:read_timeout` is unset).
10
+ * The `:multipart` plugin is removed, as its functionality and API are now loaded by default (no API changes).
11
+ * The `:compression` plugin is removed, as its functionality and API are now loaded by default (no API changes).
12
+ * `:compression_threshold_size` was removed (formats in `"content-encoding"` request header will always encode the request body).
13
+ * the new `:compress_request_body` and `:decompress_response_body` can be set to `false` to (respectively) disable compression of passed input body, or decompression of the response body.
14
+ * `:retries` plugin: the `:retry_on` condition will **not** replace default retriable error checks, it will now instead be triggered **only if** no retryable error has been found.
15
+
16
+ ### plugins
17
+
18
+ * `:authentication` plugin becomes `:auth`.
19
+ * `.authentication` helper becomes `.authorization`.
20
+ * `:basic_authentication` plugin becomes `:basic_auth`.
21
+ * `:basic_authentication` helper is removed.
22
+ * `:digest_authentication` plugin becomes `:digest_auth`.
23
+ * `:digest_authentication` helper is removed.
24
+ * `:ntlm_authentication` plugin becomes `:ntlm_auth`.
25
+ * `:ntlm_authentication` helper is removed.
26
+ * OAuth plugin: `:oauth_authentication` helper is rename to `:oauth_auth`.
27
+ * `:compression/brotli` plugin becomes `:brotli`.
28
+
29
+ ### Support removed for deprecated APIs
30
+
31
+ * The deprecated `HTTPX::Client` constant lookup has been removed (use `HTTPX::Session` instead).
32
+ * The deprecated `HTTPX.timeout({...})` function has been removed (use `HTTPX.with(timeout: {...})` instead).
33
+ * The deprecated `HTTPX.headers({...})` function has been removed (use `HTTPX.with(headers: {...})` instead).
34
+ * The deprecated `HTTPX.plugins(...)` function has been removed (use `HTTPX.plugin(...).plugin(...)...` instead).
35
+ * The deprecated `:transport_options` option, which was only valid for UNIX connections, has been removed (use `:addresses` instead).
36
+ * The deprecated `def_option(...)` function, previously used to define additional options in plugins, has been removed (use `def option_$new_option)` instead).
37
+ * The deprecated `:loop_timeout` timeout option has been removed.
38
+ * `:stream` plugin: the deprecated `HTTPX::InstanceMethods::StreamResponse` has been removed (use `HTTPX::StreamResponse` instead).
39
+ * The deprecated usage of symbols to indicate HTTP verbs (i.e. `HTTPX.request(:get, ...)` or `HTTPX.build_request(:get, ...)`) is not supported anymore (use the upcase string always, i.e. `HTTPX.request("GET", ...)` or `HTTPX.build_request("GET", ...)`, instead).
40
+ * The deprecated `HTTPX::ErrorResponse#status` method has been removed (use `HTTPX::ErrorResponse#error` instead).
41
+
42
+ ### dependencies
43
+
44
+ * `http-2-next` minimum supported version is 1.0.0.
45
+ * `:datadog` adapter only supports `ddtrace` gem 1.x or higher.
46
+ * `:faraday` adapter only supports `faraday` gem 1.x or higher.
47
+
48
+ ## Improvements
49
+
50
+ * `circuit_breaker`: the drip rate of real request during the "half-open" stage of a circuit will reliably distribute real requests (as per the drip rate) over the `max_attempts`, before the circuit is closed.
51
+
52
+ ## Bugfixes
53
+
54
+ * Tempfiles are now correctly identified as file inputs for multipart requests.
55
+ * fixed `proxy` plugin behaviour when loaded with the `follow_redirects` plugin and processing a 305 response (request needs to be retried on a different proxy).
56
+
57
+ ## Chore
58
+
59
+ * `:grpc` plugin: connection won't buffer requests before HTTP/2 handshake is commpleted, i.e. works the same as plain `httpx` HTTP/2 connection establishment.
60
+ * if you are relying on this, you can keep the old behavior this way: `HTTPX.plugin(:grpc, http2_settings: { wait_for_handshake: false })`.
@@ -1,51 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- if defined?(DDTrace) && DDTrace::VERSION::STRING >= "1.0.0"
4
- require "datadog/tracing/contrib/integration"
5
- require "datadog/tracing/contrib/configuration/settings"
6
- require "datadog/tracing/contrib/patcher"
3
+ require "datadog/tracing/contrib/integration"
4
+ require "datadog/tracing/contrib/configuration/settings"
5
+ require "datadog/tracing/contrib/patcher"
7
6
 
8
- TRACING_MODULE = Datadog::Tracing
9
- else
10
-
11
- require "ddtrace/contrib/integration"
12
- require "ddtrace/contrib/configuration/settings"
13
- require "ddtrace/contrib/patcher"
14
-
15
- TRACING_MODULE = Datadog
16
- end
17
-
18
- module TRACING_MODULE # rubocop:disable Naming/ClassAndModuleCamelCase
7
+ module Datadog::Tracing
19
8
  module Contrib
20
9
  module HTTPX
21
- if defined?(::DDTrace) && ::DDTrace::VERSION::STRING >= "1.0.0"
22
- METADATA_MODULE = TRACING_MODULE::Metadata
23
-
24
- TYPE_OUTBOUND = TRACING_MODULE::Metadata::Ext::HTTP::TYPE_OUTBOUND
25
-
26
- TAG_PEER_SERVICE = TRACING_MODULE::Metadata::Ext::TAG_PEER_SERVICE
10
+ METADATA_MODULE = Datadog::Tracing::Metadata
27
11
 
28
- TAG_URL = TRACING_MODULE::Metadata::Ext::HTTP::TAG_URL
29
- TAG_METHOD = TRACING_MODULE::Metadata::Ext::HTTP::TAG_METHOD
30
- TAG_TARGET_HOST = TRACING_MODULE::Metadata::Ext::NET::TAG_TARGET_HOST
31
- TAG_TARGET_PORT = TRACING_MODULE::Metadata::Ext::NET::TAG_TARGET_PORT
12
+ TYPE_OUTBOUND = Datadog::Tracing::Metadata::Ext::HTTP::TYPE_OUTBOUND
32
13
 
33
- TAG_STATUS_CODE = TRACING_MODULE::Metadata::Ext::HTTP::TAG_STATUS_CODE
14
+ TAG_PEER_SERVICE = Datadog::Tracing::Metadata::Ext::TAG_PEER_SERVICE
34
15
 
35
- else
16
+ TAG_URL = Datadog::Tracing::Metadata::Ext::HTTP::TAG_URL
17
+ TAG_METHOD = Datadog::Tracing::Metadata::Ext::HTTP::TAG_METHOD
18
+ TAG_TARGET_HOST = Datadog::Tracing::Metadata::Ext::NET::TAG_TARGET_HOST
19
+ TAG_TARGET_PORT = Datadog::Tracing::Metadata::Ext::NET::TAG_TARGET_PORT
36
20
 
37
- METADATA_MODULE = Datadog
38
-
39
- TYPE_OUTBOUND = TRACING_MODULE::Ext::HTTP::TYPE_OUTBOUND
40
- TAG_PEER_SERVICE = TRACING_MODULE::Ext::Integration::TAG_PEER_SERVICE
41
- TAG_URL = TRACING_MODULE::Ext::HTTP::URL
42
- TAG_METHOD = TRACING_MODULE::Ext::HTTP::METHOD
43
- TAG_TARGET_HOST = TRACING_MODULE::Ext::NET::TARGET_HOST
44
- TAG_TARGET_PORT = TRACING_MODULE::Ext::NET::TARGET_PORT
45
- TAG_STATUS_CODE = Datadog::Ext::HTTP::STATUS_CODE
46
- PROPAGATOR = TRACING_MODULE::HTTPPropagator
47
-
48
- end
21
+ TAG_STATUS_CODE = Datadog::Tracing::Metadata::Ext::HTTP::TAG_STATUS_CODE
49
22
 
50
23
  # HTTPX Datadog Plugin
51
24
  #
@@ -64,14 +37,18 @@ module TRACING_MODULE # rubocop:disable Naming/ClassAndModuleCamelCase
64
37
  end
65
38
 
66
39
  def call
67
- return unless tracing_enabled?
40
+ return unless Datadog::Tracing.enabled?
68
41
 
69
42
  @request.on(:response, &method(:finish))
70
43
 
71
44
  verb = @request.verb
72
45
  uri = @request.uri
73
46
 
74
- @span = build_span
47
+ @span = Datadog::Tracing.trace(
48
+ SPAN_REQUEST,
49
+ service: service_name(@request.uri.host, configuration, Datadog.configuration_for(self)),
50
+ span_type: TYPE_OUTBOUND
51
+ )
75
52
 
76
53
  @span.resource = verb
77
54
 
@@ -86,7 +63,8 @@ module TRACING_MODULE # rubocop:disable Naming/ClassAndModuleCamelCase
86
63
  # Tag as an external peer service
87
64
  @span.set_tag(TAG_PEER_SERVICE, @span.service)
88
65
 
89
- propagate_headers if @configuration[:distributed_tracing]
66
+ Datadog::Tracing::Propagation::HTTP.inject!(Datadog::Tracing.active_trace,
67
+ @request.headers) if @configuration[:distributed_tracing]
90
68
 
91
69
  # Set analytics sample rate
92
70
  if Contrib::Analytics.enabled?(@configuration[:analytics_enabled])
@@ -113,48 +91,8 @@ module TRACING_MODULE # rubocop:disable Naming/ClassAndModuleCamelCase
113
91
 
114
92
  private
115
93
 
116
- if defined?(::DDTrace) && ::DDTrace::VERSION::STRING >= "1.0.0"
117
-
118
- def build_span
119
- TRACING_MODULE.trace(
120
- SPAN_REQUEST,
121
- service: service_name(@request.uri.host, configuration, Datadog.configuration_for(self)),
122
- span_type: TYPE_OUTBOUND
123
- )
124
- end
125
-
126
- def propagate_headers
127
- TRACING_MODULE::Propagation::HTTP.inject!(TRACING_MODULE.active_trace, @request.headers)
128
- end
129
-
130
- def configuration
131
- @configuration ||= Datadog.configuration.tracing[:httpx, @request.uri.host]
132
- end
133
-
134
- def tracing_enabled?
135
- TRACING_MODULE.enabled?
136
- end
137
- else
138
- def build_span
139
- service_name = configuration[:split_by_domain] ? @request.uri.host : configuration[:service_name]
140
- configuration[:tracer].trace(
141
- SPAN_REQUEST,
142
- service: service_name,
143
- span_type: TYPE_OUTBOUND
144
- )
145
- end
146
-
147
- def propagate_headers
148
- Datadog::HTTPPropagator.inject!(@span.context, @request.headers)
149
- end
150
-
151
- def configuration
152
- @configuration ||= Datadog.configuration[:httpx, @request.uri.host]
153
- end
154
-
155
- def tracing_enabled?
156
- configuration[:tracer].enabled
157
- end
94
+ def configuration
95
+ @configuration ||= Datadog.configuration.tracing[:httpx, @request.uri.host]
158
96
  end
159
97
  end
160
98
 
@@ -179,7 +117,7 @@ module TRACING_MODULE # rubocop:disable Naming/ClassAndModuleCamelCase
179
117
  module Configuration
180
118
  # Default settings for httpx
181
119
  #
182
- class Settings < TRACING_MODULE::Contrib::Configuration::Settings
120
+ class Settings < Datadog::Tracing::Contrib::Configuration::Settings
183
121
  DEFAULT_ERROR_HANDLER = lambda do |response|
184
122
  Datadog::Ext::HTTP::ERROR_RANGE.cover?(response.status)
185
123
  end
@@ -188,45 +126,25 @@ module TRACING_MODULE # rubocop:disable Naming/ClassAndModuleCamelCase
188
126
  option :distributed_tracing, default: true
189
127
  option :split_by_domain, default: false
190
128
 
191
- if DDTrace::VERSION::STRING >= "1.13.0"
192
- option :enabled do |o|
193
- o.type :bool
194
- o.env "DD_TRACE_HTTPX_ENABLED"
195
- o.default true
196
- end
197
-
198
- option :analytics_enabled do |o|
199
- o.type :bool
200
- o.env "DD_TRACE_HTTPX_ANALYTICS_ENABLED"
201
- o.default false
202
- end
203
-
204
- option :analytics_sample_rate do |o|
205
- o.type :float
206
- o.env "DD_TRACE_HTTPX_ANALYTICS_SAMPLE_RATE"
207
- o.default 1.0
208
- end
209
- else
210
- option :enabled do |o|
211
- o.default { env_to_bool("DD_TRACE_HTTPX_ENABLED", true) }
212
- o.lazy
213
- end
129
+ option :enabled do |o|
130
+ o.default { env_to_bool("DD_TRACE_HTTPX_ENABLED", true) }
131
+ o.lazy
132
+ end
214
133
 
215
- option :analytics_enabled do |o|
216
- o.default { env_to_bool(%w[DD_TRACE_HTTPX_ANALYTICS_ENABLED DD_HTTPX_ANALYTICS_ENABLED], false) }
217
- o.lazy
218
- end
134
+ option :analytics_enabled do |o|
135
+ o.default { env_to_bool(%w[DD_TRACE_HTTPX_ANALYTICS_ENABLED DD_HTTPX_ANALYTICS_ENABLED], false) }
136
+ o.lazy
137
+ end
219
138
 
220
- option :analytics_sample_rate do |o|
221
- o.default { env_to_float(%w[DD_TRACE_HTTPX_ANALYTICS_SAMPLE_RATE DD_HTTPX_ANALYTICS_SAMPLE_RATE], 1.0) }
222
- o.lazy
223
- end
139
+ option :analytics_sample_rate do |o|
140
+ o.default { env_to_float(%w[DD_TRACE_HTTPX_ANALYTICS_SAMPLE_RATE DD_HTTPX_ANALYTICS_SAMPLE_RATE], 1.0) }
141
+ o.lazy
224
142
  end
225
143
 
226
- if defined?(TRACING_MODULE::Contrib::SpanAttributeSchema)
144
+ if defined?(Datadog::Tracing::Contrib::SpanAttributeSchema)
227
145
  option :service_name do |o|
228
146
  o.default do
229
- TRACING_MODULE::Contrib::SpanAttributeSchema.fetch_service_name(
147
+ Datadog::Tracing::Contrib::SpanAttributeSchema.fetch_service_name(
230
148
  "DD_TRACE_HTTPX_SERVICE_NAME",
231
149
  "httpx"
232
150
  )
@@ -244,26 +162,14 @@ module TRACING_MODULE # rubocop:disable Naming/ClassAndModuleCamelCase
244
162
 
245
163
  option :distributed_tracing, default: true
246
164
 
247
- if DDTrace::VERSION::STRING >= "1.15.0"
248
- option :error_handler do |o|
249
- o.type :proc
250
- o.default_proc(&DEFAULT_ERROR_HANDLER)
251
- end
252
- elsif DDTrace::VERSION::STRING >= "1.13.0"
253
- option :error_handler do |o|
254
- o.type :proc
255
- o.experimental_default_proc(&DEFAULT_ERROR_HANDLER)
256
- end
257
- else
258
- option :error_handler, default: DEFAULT_ERROR_HANDLER
259
- end
165
+ option :error_handler, default: DEFAULT_ERROR_HANDLER
260
166
  end
261
167
  end
262
168
 
263
169
  # Patcher enables patching of 'httpx' with datadog components.
264
170
  #
265
171
  module Patcher
266
- include TRACING_MODULE::Contrib::Patcher
172
+ include Datadog::Tracing::Contrib::Patcher
267
173
 
268
174
  module_function
269
175
 
@@ -286,7 +192,6 @@ module TRACING_MODULE # rubocop:disable Naming/ClassAndModuleCamelCase
286
192
  class Integration
287
193
  include Contrib::Integration
288
194
 
289
- # MINIMUM_VERSION = Gem::Version.new('0.11.0')
290
195
  MINIMUM_VERSION = Gem::Version.new("0.10.2")
291
196
 
292
197
  register_as :httpx
@@ -303,14 +208,8 @@ module TRACING_MODULE # rubocop:disable Naming/ClassAndModuleCamelCase
303
208
  super && version >= MINIMUM_VERSION
304
209
  end
305
210
 
306
- if defined?(::DDTrace) && ::DDTrace::VERSION::STRING >= "1.0.0"
307
- def new_configuration
308
- Configuration::Settings.new
309
- end
310
- else
311
- def default_configuration
312
- Configuration::Settings.new
313
- end
211
+ def new_configuration
212
+ Configuration::Settings.new
314
213
  end
315
214
 
316
215
  def patcher
@@ -7,38 +7,11 @@ require "faraday"
7
7
  module Faraday
8
8
  class Adapter
9
9
  class HTTPX < Faraday::Adapter
10
- # :nocov:
11
- SSL_ERROR = if defined?(Faraday::SSLError)
12
- Faraday::SSLError
13
- else
14
- Faraday::Error::SSLError
15
- end
16
-
17
- CONNECTION_FAILED_ERROR = if defined?(Faraday::ConnectionFailed)
18
- Faraday::ConnectionFailed
19
- else
20
- Faraday::Error::ConnectionFailed
21
- end
22
- # :nocov:
23
-
24
- unless Faraday::RequestOptions.method_defined?(:stream_response?)
25
- module RequestOptionsExtensions
26
- refine Faraday::RequestOptions do
27
- def stream_response?
28
- false
29
- end
30
- end
31
- end
32
- using RequestOptionsExtensions
33
- end
34
-
35
10
  module RequestMixin
36
- using ::HTTPX::HashExtensions
37
-
38
11
  def build_connection(env)
39
12
  return @connection if defined?(@connection)
40
13
 
41
- @connection = ::HTTPX.plugin(:compression).plugin(:persistent).plugin(ReasonPlugin)
14
+ @connection = ::HTTPX.plugin(:persistent).plugin(ReasonPlugin)
42
15
  @connection = @connection.with(@connection_options) unless @connection_options.empty?
43
16
  connection_opts = options_from_env(env)
44
17
 
@@ -70,7 +43,7 @@ module Faraday
70
43
  def connect(env, &blk)
71
44
  connection(env, &blk)
72
45
  rescue ::HTTPX::TLSError => e
73
- raise SSL_ERROR, e
46
+ raise Faraday::SSLError, e
74
47
  rescue Errno::ECONNABORTED,
75
48
  Errno::ECONNREFUSED,
76
49
  Errno::ECONNRESET,
@@ -79,9 +52,7 @@ module Faraday
79
52
  Errno::ENETUNREACH,
80
53
  Errno::EPIPE,
81
54
  ::HTTPX::ConnectionError => e
82
- raise CONNECTION_FAILED_ERROR, e
83
- rescue ::HTTPX::TimeoutError => e
84
- raise Faraday::TimeoutError, e
55
+ raise Faraday::ConnectionFailed, e
85
56
  end
86
57
 
87
58
  def build_request(env)
@@ -159,24 +130,13 @@ module Faraday
159
130
  end
160
131
 
161
132
  module ReasonPlugin
162
- if RUBY_VERSION < "2.5"
163
- def self.load_dependencies(*)
164
- require "webrick"
165
- end
166
- else
167
- def self.load_dependencies(*)
168
- require "net/http/status"
169
- end
133
+ def self.load_dependencies(*)
134
+ require "net/http/status"
170
135
  end
136
+
171
137
  module ResponseMethods
172
- if RUBY_VERSION < "2.5"
173
- def reason
174
- WEBrick::HTTPStatus::StatusMessage.fetch(@status)
175
- end
176
- else
177
- def reason
178
- Net::HTTP::STATUS_CODES.fetch(@status)
179
- end
138
+ def reason
139
+ Net::HTTP::STATUS_CODES.fetch(@status)
180
140
  end
181
141
  end
182
142
  end
@@ -261,10 +221,7 @@ module Faraday
261
221
 
262
222
  # from Faraday::Adapter#request_timeout
263
223
  def request_timeout(type, options)
264
- key = Faraday::Adapter::TIMEOUT_KEYS.fetch(type) do
265
- msg = "Expected :read, :write, :open. Got #{type.inspect} :("
266
- raise ArgumentError, msg
267
- end
224
+ key = Faraday::Adapter::TIMEOUT_KEYS[type]
268
225
  options[key] || options[:timeout]
269
226
  end
270
227
  end
@@ -2,13 +2,8 @@
2
2
 
3
3
  module WebMock
4
4
  module HttpLibAdapters
5
- if RUBY_VERSION < "2.5"
6
- require "webrick/httpstatus"
7
- HTTP_REASONS = WEBrick::HTTPStatus::StatusMessage
8
- else
9
- require "net/http/status"
10
- HTTP_REASONS = Net::HTTP::STATUS_CODES
11
- end
5
+ require "net/http/status"
6
+ HTTP_REASONS = Net::HTTP::STATUS_CODES
12
7
 
13
8
  #
14
9
  # HTTPX plugin for webmock.
data/lib/httpx/altsvc.rb CHANGED
@@ -98,29 +98,11 @@ module HTTPX
98
98
  end
99
99
  end
100
100
 
101
- # :nocov:
102
- if RUBY_VERSION < "2.2"
103
- def parse_altsvc_origin(alt_proto, alt_origin)
104
- alt_scheme = parse_altsvc_scheme(alt_proto) or return
105
-
106
- alt_origin = alt_origin[1..-2] if alt_origin.start_with?("\"") && alt_origin.end_with?("\"")
107
- if alt_origin.start_with?(":")
108
- alt_origin = "#{alt_scheme}://dummy#{alt_origin}"
109
- uri = URI.parse(alt_origin)
110
- uri.host = nil
111
- uri
112
- else
113
- URI.parse("#{alt_scheme}://#{alt_origin}")
114
- end
115
- end
116
- else
117
- def parse_altsvc_origin(alt_proto, alt_origin)
118
- alt_scheme = parse_altsvc_scheme(alt_proto) or return
119
- alt_origin = alt_origin[1..-2] if alt_origin.start_with?("\"") && alt_origin.end_with?("\"")
101
+ def parse_altsvc_origin(alt_proto, alt_origin)
102
+ alt_scheme = parse_altsvc_scheme(alt_proto) or return
103
+ alt_origin = alt_origin[1..-2] if alt_origin.start_with?("\"") && alt_origin.end_with?("\"")
120
104
 
121
- URI.parse("#{alt_scheme}://#{alt_origin}")
122
- end
105
+ URI.parse("#{alt_scheme}://#{alt_origin}")
123
106
  end
124
- # :nocov:
125
107
  end
126
108
  end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ if RUBY_VERSION < "3.3.0"
4
+ require "base64"
5
+ elsif !defined?(Base64)
6
+ module HTTPX
7
+ # require "base64" will not be a default gem after ruby 3.4.0
8
+ module Base64
9
+ module_function
10
+
11
+ def decode64(str)
12
+ str.unpack1("m")
13
+ end
14
+
15
+ def strict_encode64(bin)
16
+ [bin].pack("m0")
17
+ end
18
+
19
+ def urlsafe_encode64(bin, padding: true)
20
+ str = strict_encode64(bin)
21
+ str.chomp!("==") or str.chomp!("=") unless padding
22
+ str.tr!("+/", "-_")
23
+ str
24
+ end
25
+ end
26
+ end
27
+ end
@@ -27,18 +27,6 @@ module HTTPX
27
27
  branch(default_options).request(*args, **options)
28
28
  end
29
29
 
30
- # :nocov:
31
- def timeout(**args)
32
- warn ":#{__method__} is deprecated, use :with_timeout instead"
33
- with(timeout: args)
34
- end
35
-
36
- def headers(headers)
37
- warn ":#{__method__} is deprecated, use :with_headers instead"
38
- with(headers: headers)
39
- end
40
- # :nocov:
41
-
42
30
  def accept(type)
43
31
  with(headers: { "accept" => String(type) })
44
32
  end
@@ -54,17 +42,6 @@ module HTTPX
54
42
  klass.plugin(pl, options, &blk).new
55
43
  end
56
44
 
57
- # deprecated
58
- # :nocov:
59
- def plugins(pls)
60
- warn ":#{__method__} is deprecated, use :plugin instead"
61
- klass = is_a?(S) ? self.class : Session
62
- klass = Class.new(klass)
63
- klass.instance_variable_set(:@default_options, klass.default_options.merge(default_options))
64
- klass.plugins(pls).new
65
- end
66
- # :nocov:
67
-
68
45
  def with(options, &blk)
69
46
  branch(default_options.merge(options), &blk)
70
47
  end