httpx 0.24.5 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) 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/0_24_6.md +5 -0
  6. data/doc/release_notes/1_0_0.md +60 -0
  7. data/lib/httpx/adapters/datadog.rb +28 -97
  8. data/lib/httpx/adapters/faraday.rb +9 -52
  9. data/lib/httpx/adapters/webmock.rb +2 -7
  10. data/lib/httpx/altsvc.rb +4 -22
  11. data/lib/httpx/base64.rb +27 -0
  12. data/lib/httpx/chainable.rb +2 -25
  13. data/lib/httpx/connection.rb +11 -32
  14. data/lib/httpx/domain_name.rb +5 -12
  15. data/lib/httpx/errors.rb +0 -2
  16. data/lib/httpx/extensions.rb +0 -124
  17. data/lib/httpx/io/ssl.rb +26 -59
  18. data/lib/httpx/io/tcp.rb +27 -68
  19. data/lib/httpx/io/udp.rb +13 -48
  20. data/lib/httpx/io/unix.rb +1 -8
  21. data/lib/httpx/loggable.rb +4 -19
  22. data/lib/httpx/options.rb +24 -84
  23. data/lib/httpx/plugins/{authentication → auth}/basic.rb +1 -5
  24. data/lib/httpx/plugins/{authentication → auth}/digest.rb +2 -5
  25. data/lib/httpx/plugins/{authentication → auth}/ntlm.rb +1 -3
  26. data/lib/httpx/plugins/{authentication → auth}/socks5.rb +0 -2
  27. data/lib/httpx/plugins/auth.rb +25 -0
  28. data/lib/httpx/plugins/aws_sigv4.rb +0 -1
  29. data/lib/httpx/plugins/{basic_authentication.rb → basic_auth.rb} +5 -6
  30. data/lib/httpx/plugins/brotli.rb +50 -0
  31. data/lib/httpx/plugins/circuit_breaker/circuit.rb +40 -16
  32. data/lib/httpx/plugins/circuit_breaker/circuit_store.rb +16 -5
  33. data/lib/httpx/plugins/circuit_breaker.rb +11 -4
  34. data/lib/httpx/plugins/cookies/set_cookie_parser.rb +0 -2
  35. data/lib/httpx/plugins/cookies.rb +1 -1
  36. data/lib/httpx/plugins/{digest_authentication.rb → digest_auth.rb} +5 -5
  37. data/lib/httpx/plugins/follow_redirects.rb +21 -24
  38. data/lib/httpx/plugins/grpc/grpc_encoding.rb +82 -0
  39. data/lib/httpx/plugins/grpc/message.rb +7 -39
  40. data/lib/httpx/plugins/grpc.rb +15 -21
  41. data/lib/httpx/plugins/h2c.rb +0 -1
  42. data/lib/httpx/plugins/{ntlm_authentication.rb → ntlm_auth.rb} +5 -5
  43. data/lib/httpx/plugins/oauth.rb +2 -2
  44. data/lib/httpx/plugins/proxy/http.rb +0 -2
  45. data/lib/httpx/plugins/proxy/socks4.rb +0 -4
  46. data/lib/httpx/plugins/proxy/socks5.rb +1 -5
  47. data/lib/httpx/plugins/proxy.rb +3 -32
  48. data/lib/httpx/plugins/retries.rb +3 -4
  49. data/lib/httpx/plugins/stream.rb +4 -6
  50. data/lib/httpx/punycode.rb +9 -291
  51. data/lib/httpx/request/body.rb +145 -0
  52. data/lib/httpx/request.rb +2 -119
  53. data/lib/httpx/resolver/https.rb +1 -1
  54. data/lib/httpx/resolver/native.rb +6 -14
  55. data/lib/httpx/resolver/resolver.rb +1 -1
  56. data/lib/httpx/resolver/system.rb +11 -9
  57. data/lib/httpx/response/body.rb +206 -0
  58. data/lib/httpx/response/buffer.rb +90 -0
  59. data/lib/httpx/response.rb +5 -208
  60. data/lib/httpx/selector.rb +0 -2
  61. data/lib/httpx/session.rb +3 -10
  62. data/lib/httpx/transcoder/body.rb +0 -1
  63. data/lib/httpx/transcoder/deflate.rb +37 -0
  64. data/lib/httpx/transcoder/form.rb +52 -32
  65. data/lib/httpx/transcoder/gzip.rb +74 -0
  66. data/lib/httpx/transcoder/json.rb +2 -4
  67. data/lib/httpx/transcoder/multipart/decoder.rb +139 -0
  68. data/lib/httpx/{plugins → transcoder}/multipart/encoder.rb +3 -3
  69. data/lib/httpx/{plugins → transcoder}/multipart/mime_type_detector.rb +1 -1
  70. data/lib/httpx/{plugins → transcoder}/multipart/part.rb +3 -2
  71. data/lib/httpx/transcoder/multipart.rb +17 -0
  72. data/lib/httpx/transcoder/utils/body_reader.rb +46 -0
  73. data/lib/httpx/transcoder/utils/deflater.rb +72 -0
  74. data/lib/httpx/transcoder/xml.rb +0 -2
  75. data/lib/httpx/transcoder.rb +2 -2
  76. data/lib/httpx/utils.rb +10 -20
  77. data/lib/httpx/version.rb +1 -1
  78. data/lib/httpx.rb +0 -8
  79. data/sig/chainable.rbs +5 -6
  80. data/sig/connection.rbs +0 -1
  81. data/sig/errors.rbs +0 -3
  82. data/sig/httpx.rbs +2 -1
  83. data/sig/io/unix.rbs +1 -1
  84. data/sig/options.rbs +12 -8
  85. data/sig/plugins/{authentication → auth}/basic.rbs +0 -2
  86. data/sig/plugins/auth.rbs +13 -0
  87. data/sig/plugins/{basic_authentication.rbs → basic_auth.rbs} +2 -2
  88. data/sig/plugins/brotli.rbs +22 -0
  89. data/sig/plugins/circuit_breaker.rbs +7 -3
  90. data/sig/plugins/compression.rbs +0 -2
  91. data/sig/plugins/{digest_authentication.rbs → digest_auth.rbs} +2 -2
  92. data/sig/plugins/follow_redirects.rbs +0 -1
  93. data/sig/plugins/grpc/call.rbs +19 -0
  94. data/sig/plugins/grpc/grpc_encoding.rbs +33 -0
  95. data/sig/plugins/grpc/message.rbs +17 -0
  96. data/sig/plugins/grpc.rbs +2 -32
  97. data/sig/plugins/{ntlm_authentication.rbs → ntlm_auth.rbs} +2 -2
  98. data/sig/plugins/oauth.rbs +1 -1
  99. data/sig/plugins/proxy/socks4.rbs +2 -3
  100. data/sig/plugins/proxy/socks5.rbs +0 -1
  101. data/sig/plugins/proxy/ssh.rbs +1 -1
  102. data/sig/plugins/response_cache.rbs +5 -2
  103. data/sig/request/body.rbs +42 -0
  104. data/sig/request.rbs +1 -27
  105. data/sig/resolver/resolver.rbs +1 -1
  106. data/sig/response/body.rbs +52 -0
  107. data/sig/response/buffer.rbs +24 -0
  108. data/sig/response.rbs +0 -39
  109. data/sig/session.rbs +2 -0
  110. data/sig/transcoder/body.rbs +4 -3
  111. data/sig/transcoder/deflate.rbs +11 -0
  112. data/sig/transcoder/form.rbs +5 -3
  113. data/sig/transcoder/gzip.rbs +24 -0
  114. data/sig/transcoder/json.rbs +4 -2
  115. data/sig/{plugins → transcoder}/multipart.rbs +3 -10
  116. data/sig/transcoder/utils/body_reader.rbs +15 -0
  117. data/sig/transcoder/utils/deflater.rbs +29 -0
  118. data/sig/transcoder.rbs +18 -2
  119. metadata +52 -34
  120. data/lib/httpx/plugins/authentication.rb +0 -24
  121. data/lib/httpx/plugins/compression/brotli.rb +0 -54
  122. data/lib/httpx/plugins/compression/deflate.rb +0 -54
  123. data/lib/httpx/plugins/compression/gzip.rb +0 -90
  124. data/lib/httpx/plugins/compression.rb +0 -165
  125. data/lib/httpx/plugins/multipart/decoder.rb +0 -137
  126. data/lib/httpx/plugins/multipart.rb +0 -96
  127. data/sig/plugins/authentication.rbs +0 -13
  128. data/sig/plugins/compression/brotli.rbs +0 -21
  129. data/sig/plugins/compression/deflate.rbs +0 -17
  130. data/sig/plugins/compression/gzip.rbs +0 -29
  131. /data/sig/plugins/{authentication → auth}/digest.rbs +0 -0
  132. /data/sig/plugins/{authentication → auth}/ntlm.rbs +0 -0
  133. /data/sig/plugins/{authentication → auth}/socks5.rbs +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b3d9a59fa9d9cc1908f3135c38d9a8cb132312c0539795d3a341d87da3755d23
4
- data.tar.gz: 8e88ca75fceac380b8fbb31fa627f3a30a2b938e2527baffbc2db00db64b76e5
3
+ metadata.gz: 40c3560dd37c1fc898a5e0beb5a73148285cdae564ee285552aaf4ccb42bc06a
4
+ data.tar.gz: 0463ddfdb74f304264c28c513cac13c05d0b0bfc6089a7466d251c8cd94e8782
5
5
  SHA512:
6
- metadata.gz: fe80712332209f6b188eca10aea16f0d1cb02b8af18682e6efda3844cd5d5de9e99cb0829cf162433fe85f7a070865808caa32a69df3ebe84b7dd483c105315f
7
- data.tar.gz: 1ec1dd55a8ec80bceaab32a39dfa2e325f01f83c5e512be5c74feb8f4049ef9f34431ab6d33d00ad4b6fcf906d7883a0420e91a0663f2eb4fdd6ddb632b4d351
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,5 @@
1
+ # 0.24.6
2
+
3
+ ## Bugfixes
4
+
5
+ * fix Session class assertions not prepared for class overrides, which could break some plugins which override the Session class on load (such as `datadog` or `webmock` adapters).
@@ -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
27
-
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
10
+ METADATA_MODULE = Datadog::Tracing::Metadata
32
11
 
33
- TAG_STATUS_CODE = TRACING_MODULE::Metadata::Ext::HTTP::TAG_STATUS_CODE
12
+ TYPE_OUTBOUND = Datadog::Tracing::Metadata::Ext::HTTP::TYPE_OUTBOUND
34
13
 
35
- else
14
+ TAG_PEER_SERVICE = Datadog::Tracing::Metadata::Ext::TAG_PEER_SERVICE
36
15
 
37
- METADATA_MODULE = Datadog
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
38
20
 
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
@@ -203,10 +141,10 @@ module TRACING_MODULE # rubocop:disable Naming/ClassAndModuleCamelCase
203
141
  o.lazy
204
142
  end
205
143
 
206
- if defined?(TRACING_MODULE::Contrib::SpanAttributeSchema)
144
+ if defined?(Datadog::Tracing::Contrib::SpanAttributeSchema)
207
145
  option :service_name do |o|
208
146
  o.default do
209
- TRACING_MODULE::Contrib::SpanAttributeSchema.fetch_service_name(
147
+ Datadog::Tracing::Contrib::SpanAttributeSchema.fetch_service_name(
210
148
  "DD_TRACE_HTTPX_SERVICE_NAME",
211
149
  "httpx"
212
150
  )
@@ -231,7 +169,7 @@ module TRACING_MODULE # rubocop:disable Naming/ClassAndModuleCamelCase
231
169
  # Patcher enables patching of 'httpx' with datadog components.
232
170
  #
233
171
  module Patcher
234
- include TRACING_MODULE::Contrib::Patcher
172
+ include Datadog::Tracing::Contrib::Patcher
235
173
 
236
174
  module_function
237
175
 
@@ -254,7 +192,6 @@ module TRACING_MODULE # rubocop:disable Naming/ClassAndModuleCamelCase
254
192
  class Integration
255
193
  include Contrib::Integration
256
194
 
257
- # MINIMUM_VERSION = Gem::Version.new('0.11.0')
258
195
  MINIMUM_VERSION = Gem::Version.new("0.10.2")
259
196
 
260
197
  register_as :httpx
@@ -271,14 +208,8 @@ module TRACING_MODULE # rubocop:disable Naming/ClassAndModuleCamelCase
271
208
  super && version >= MINIMUM_VERSION
272
209
  end
273
210
 
274
- if defined?(::DDTrace) && ::DDTrace::VERSION::STRING >= "1.0.0"
275
- def new_configuration
276
- Configuration::Settings.new
277
- end
278
- else
279
- def default_configuration
280
- Configuration::Settings.new
281
- end
211
+ def new_configuration
212
+ Configuration::Settings.new
282
213
  end
283
214
 
284
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
@@ -48,23 +36,12 @@ module HTTPX
48
36
  end
49
37
 
50
38
  def plugin(pl, options = nil, &blk)
51
- klass = is_a?(Session) ? self.class : Session
39
+ klass = is_a?(S) ? self.class : Session
52
40
  klass = Class.new(klass)
53
41
  klass.instance_variable_set(:@default_options, klass.default_options.merge(default_options))
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?(Session) ? 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
@@ -82,7 +59,7 @@ module HTTPX
82
59
  end
83
60
 
84
61
  def branch(options, &blk)
85
- return self.class.new(options, &blk) if is_a?(Session)
62
+ return self.class.new(options, &blk) if is_a?(S)
86
63
 
87
64
  Session.new(options, &blk)
88
65
  end