httpx 0.10.2 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -5
  3. data/doc/release_notes/0_11_0.md +76 -0
  4. data/doc/release_notes/0_11_1.md +5 -0
  5. data/doc/release_notes/0_11_2.md +5 -0
  6. data/doc/release_notes/0_11_3.md +5 -0
  7. data/doc/release_notes/0_12_0.md +55 -0
  8. data/lib/httpx.rb +2 -1
  9. data/lib/httpx/adapters/datadog.rb +205 -0
  10. data/lib/httpx/adapters/faraday.rb +4 -8
  11. data/lib/httpx/adapters/webmock.rb +123 -0
  12. data/lib/httpx/altsvc.rb +1 -0
  13. data/lib/httpx/chainable.rb +1 -1
  14. data/lib/httpx/connection.rb +63 -15
  15. data/lib/httpx/connection/http1.rb +16 -5
  16. data/lib/httpx/connection/http2.rb +36 -29
  17. data/lib/httpx/domain_name.rb +1 -3
  18. data/lib/httpx/errors.rb +2 -0
  19. data/lib/httpx/headers.rb +1 -0
  20. data/lib/httpx/io.rb +16 -3
  21. data/lib/httpx/io/ssl.rb +7 -13
  22. data/lib/httpx/io/tcp.rb +9 -8
  23. data/lib/httpx/io/tls.rb +218 -0
  24. data/lib/httpx/io/tls/box.rb +365 -0
  25. data/lib/httpx/io/tls/context.rb +199 -0
  26. data/lib/httpx/io/tls/ffi.rb +390 -0
  27. data/lib/httpx/io/udp.rb +4 -3
  28. data/lib/httpx/parser/http1.rb +4 -4
  29. data/lib/httpx/plugins/aws_sdk_authentication.rb +81 -0
  30. data/lib/httpx/plugins/aws_sigv4.rb +218 -0
  31. data/lib/httpx/plugins/compression.rb +1 -1
  32. data/lib/httpx/plugins/compression/deflate.rb +2 -5
  33. data/lib/httpx/plugins/cookies/set_cookie_parser.rb +1 -1
  34. data/lib/httpx/plugins/expect.rb +33 -8
  35. data/lib/httpx/plugins/internal_telemetry.rb +93 -0
  36. data/lib/httpx/plugins/multipart.rb +42 -35
  37. data/lib/httpx/plugins/multipart/encoder.rb +110 -0
  38. data/lib/httpx/plugins/multipart/mime_type_detector.rb +64 -0
  39. data/lib/httpx/plugins/multipart/part.rb +34 -0
  40. data/lib/httpx/plugins/proxy.rb +1 -1
  41. data/lib/httpx/plugins/proxy/http.rb +1 -1
  42. data/lib/httpx/plugins/proxy/socks4.rb +8 -0
  43. data/lib/httpx/plugins/proxy/socks5.rb +11 -2
  44. data/lib/httpx/plugins/push_promise.rb +5 -4
  45. data/lib/httpx/plugins/retries.rb +1 -1
  46. data/lib/httpx/plugins/stream.rb +3 -5
  47. data/lib/httpx/pool.rb +0 -1
  48. data/lib/httpx/registry.rb +1 -7
  49. data/lib/httpx/request.rb +32 -12
  50. data/lib/httpx/resolver.rb +7 -4
  51. data/lib/httpx/resolver/https.rb +7 -13
  52. data/lib/httpx/resolver/native.rb +10 -6
  53. data/lib/httpx/resolver/system.rb +1 -1
  54. data/lib/httpx/response.rb +9 -2
  55. data/lib/httpx/selector.rb +6 -0
  56. data/lib/httpx/session.rb +40 -20
  57. data/lib/httpx/transcoder.rb +6 -4
  58. data/lib/httpx/transcoder/body.rb +3 -5
  59. data/lib/httpx/version.rb +1 -1
  60. data/sig/connection/http1.rbs +2 -2
  61. data/sig/connection/http2.rbs +8 -7
  62. data/sig/headers.rbs +3 -0
  63. data/sig/plugins/aws_sdk_authentication.rbs +17 -0
  64. data/sig/plugins/aws_sigv4.rbs +65 -0
  65. data/sig/plugins/multipart.rbs +27 -4
  66. data/sig/plugins/push_promise.rbs +1 -1
  67. data/sig/request.rbs +1 -1
  68. data/sig/resolver/https.rbs +2 -0
  69. data/sig/response.rbs +1 -1
  70. data/sig/session.rbs +1 -1
  71. data/sig/transcoder.rbs +2 -2
  72. data/sig/transcoder/body.rbs +2 -0
  73. data/sig/transcoder/form.rbs +7 -1
  74. data/sig/transcoder/json.rbs +3 -1
  75. metadata +50 -47
  76. data/sig/missing.rbs +0 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2dee09976c993c9a7cb840410ce8758e68faaae6d13d1101a0cf207b59eebdd4
4
- data.tar.gz: 444e4c0373f4c3faed53b1b2238e338aaac70af61b24657b2b79ce3f509bffde
3
+ metadata.gz: 5770fadc8d4604ccb0fb274c7fc157802315f68c749a83973ee5596fee8effb1
4
+ data.tar.gz: 4f24cca053093be31636405dcb740f5c6b2599197d9ebdfb90cbf127e86a5ffc
5
5
  SHA512:
6
- metadata.gz: 4d113f172d81c88f155b0bc00c1a42c76fc01c6eed31df693c2ed5c43190e4887c6331492b33acb3104c16de49ec34023fd3c22eb199bfa363392af5fd8ce414
7
- data.tar.gz: defb46daafc3fba4f13e765531b61892e5fedd96de9ffdd4ab0e10132ac4df3a5e99e94baf032578cef2919c29069ac3c080c25e56b93907e8451c573a245972
6
+ metadata.gz: 48fe64207a82e2b8db91b73cc6252ff48ea624e57dcbcbfa30e5f6986e1936e61bbdc83cece34c470dd6e318f41845a306a57e2b5c8710084444b6193786a1eb
7
+ data.tar.gz: 70b43fc624a8452187a730e39f55d9e92d16438babbd76aa2346c5b3dd0c2cad7f8e5e787f7c4ab1917c52ed750c7656f2f6c5e92a2ec0fce9cc0a76e5994d1e
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # HTTPX: A Ruby HTTP library for tomorrow... and beyond!
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/httpx.svg)](http://rubygems.org/gems/httpx)
4
- [![pipeline status](https://gitlab.com/honeyryderchuck/httpx/badges/master/pipeline.svg)](https://gitlab.com/honeyryderchuck/httpx/commits/master)
4
+ [![pipeline status](https://gitlab.com/honeyryderchuck/httpx/badges/master/pipeline.svg)](https://gitlab.com/honeyryderchuck/httpx/pipelines?page=1&scope=all&ref=master)
5
5
  [![coverage report](https://gitlab.com/honeyryderchuck/httpx/badges/master/coverage.svg?job=coverage)](https://honeyryderchuck.gitlab.io/httpx/coverage/#_AllFiles)
6
6
 
7
7
  HTTPX is an HTTP client library for the Ruby programming language.
@@ -85,7 +85,15 @@ However if the server supports HTTP/1.1, it will try to use HTTP pipelining, fal
85
85
 
86
86
  ### Clean API
87
87
 
88
- `HTTPX` acknowledges the ease-of-use of the [http gem](https://github.com/httprb/http) API (itself inspired by python [requests](http://docs.python-requests.org/en/latest/) library). It therefore aims at reusing the same facade, extending it for the use cases which the http gem doesn't support.
88
+ `httpx` builds all functions around the `HTTPX` module, so that all calls can compose of each other. Here are a few examples:
89
+
90
+ ```ruby
91
+ response = HTTPX.get("https://www.google.com")
92
+ response = HTTPX.post("https://www.nghttp2.org/httpbin/post", params: {name: "John", age: "22"})
93
+ response = HTTPX.plugin(:basic_authentication)
94
+ .basic_authentication("user", "pass")
95
+ .get("https://www.google.com")
96
+ ```
89
97
 
90
98
  ### Lightweight
91
99
 
@@ -105,7 +113,7 @@ The test suite runs against [httpbin proxied over nghttp2](https://nghttp2.org/h
105
113
 
106
114
  ## Supported Rubies
107
115
 
108
- All Rubies greater or equal to 2.1, and always latest JRuby.
116
+ All Rubies greater or equal to 2.1, and always latest JRuby and Truffleruby.
109
117
 
110
118
  **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.
111
119
 
@@ -125,7 +133,7 @@ All Rubies greater or equal to 2.1, and always latest JRuby.
125
133
 
126
134
  If your requirement is to run requests over HTTP/2 and TLS, make sure you run a version of the gem which compiles OpenSSL 1.0.2 (Ruby 2.3 and higher are guaranteed to).
127
135
 
128
- JRuby's `openssl` is based on Bouncy Castle, which is massively outdated and still doesn't implement ALPN. So HTTP/2 over TLS/ALPN negotiation is off until JRuby figures this out.
136
+ In order to use HTTP/2 under JRuby, [check this link](https://gitlab.com/honeyryderchuck/httpx/-/wikis/JRuby-Truffleruby-Other-Rubies) to know what to do.
129
137
 
130
138
  ### Known bugs
131
139
 
@@ -135,7 +143,7 @@ Doesn't work with ruby 2.4.0 for Windows (see [#36](https://gitlab.com/honeyryde
135
143
 
136
144
  * Discuss your contribution in an issue
137
145
  * Fork it
138
- * Make your changes, add some test
146
+ * Make your changes, add some tests
139
147
  * Ensure all tests pass (`bundle exec rake test`)
140
148
  * Open a Merge Request (that's Pull Request in Github-ish)
141
149
  * Wait for feedback
@@ -0,0 +1,76 @@
1
+ # 0.11.0
2
+
3
+ ## Features
4
+
5
+ ### Webmock Adapter
6
+
7
+ `httpx` can now be integrated with `webmock`, a popular HTTP requests stubbing library.
8
+
9
+ ```ruby
10
+ # minitest
11
+ require "webmock/minitest"
12
+ require "httpx/adapters/webmock"
13
+
14
+ # in rspec
15
+ require "webmock/rspec"
16
+ require "httpx/adapters/webmock"
17
+
18
+ # and now you're free for mocking
19
+ WebMock.enable!
20
+ stub_http_request(:get, "https://www.google.com").and_return(status: 200, body: "here's google")
21
+
22
+ ```
23
+
24
+ Read more about it in the [webmock integration documentation](https://honeyryderchuck.gitlab.io/httpx/wiki/Webmock-Adapter).
25
+
26
+ ### Datadog Adapter
27
+
28
+ `httpx` ships with integration for [ddtrace, datadog's official tracing client](https://github.com/DataDog/dd-trace-rb). You just need to initialize it the following way:
29
+
30
+ ```ruby
31
+ require "ddtrace"
32
+ require "httpx/adapters/datadog"
33
+
34
+ Datadog.configure do |c|
35
+ c.use :httpx
36
+ end
37
+ ```
38
+
39
+ A trace will be emitted for every request, so this should be an interesting visualization if concurrent requests are sent.
40
+
41
+ Customization options and traces are similar to what [the net-http adapter provides](https://docs.datadoghq.com/tracing/setup_overview/setup/ruby/#nethttp).
42
+
43
+ Read more about it in the [datadog integration documentation](https://honeyryderchuck.gitlab.io/httpx/wiki/Datadog-Adapter).
44
+
45
+ ## Improvements
46
+
47
+ ### Own multipart request encoder
48
+
49
+ `httpx` now ships with its own multipart formdata encoder, and does not rely on `http-form_data` anymore:
50
+
51
+ ```ruby
52
+ HTTPX.plugin(:multipart).post(uri, form: {file: File.new("path/to/file")})
53
+ ```
54
+
55
+ Read more about it in the [multipart plugin documentation](https://honeyryderchuck.gitlab.io/httpx/wiki/Multipart-Uploads), including also about why this was made.
56
+
57
+ ### Expect Plugin
58
+
59
+ The `:expect` plugin now works reliably when the server does not support the `expect: 100-continue` header, i.e. it'll upload the body after a certain timeout. Building onn that, two behaviours are now implemented:
60
+
61
+ * A cache of domains which did not respond to the `expect` header is now kept, so that subsequent requests can skip the timeout and immediately upload the payload.
62
+ * If the "100 Continue" response arrives **after** the timeout expired and the body has been uploaded, the domain is removed from the cache, and subsequent requests will send the `expect` header.
63
+
64
+ ### SNI/Host options
65
+
66
+ Some extension of the API was applied in order to support custom TLS negotiation parameters. You can now pass `:hostname` under the `:ssl` options, and this will be used for the SNI part of the TLS negotiation. This is useful in scenarios where a proxy certificate doesn't apply for the host one wants to send the request to:
67
+
68
+ ```ruby
69
+ response = session.get(proxy_ip, headers: { "host" => upstream_hostname }, ssl: { hostname: sni_hostname }
70
+ ```
71
+
72
+ ## Bugfixes
73
+
74
+ A default 5 second timeout is in-place when using the DNS `:system` resolver, as it was found out that. when using the `resolv` library, the DNS query will not be retried otherwise. You can change this setting py passing `resolver_options: { timeouts: ANOTHER_TIMEOUT}`. In the future, this may become another timeout option, however.
75
+
76
+
@@ -0,0 +1,5 @@
1
+ # 0.11.1
2
+
3
+ ## Bugfixes
4
+
5
+ Fixed a bug related to the `:compression` plugin trying to process a last empty DATA frame from an HTTP/2 response, after it had been closed.
@@ -0,0 +1,5 @@
1
+ # 0.11.2
2
+
3
+ ## Bugfixes
4
+
5
+ The `:cookies` plugin wasn't able to parse `Expires` values, as it was using `Time.httpdate` to parse timestamps, which is RFC 2616-compliant, whereas cookies datetime values need to be RFC 6265-compliant.
@@ -0,0 +1,5 @@
1
+ # 0.11.3
2
+
3
+ ## Bugfixes
4
+
5
+ `EOFError` was being thrown when HTTP/1.1 non-chunked responses which don't contain a "content-length" header. The RFC mandates that the socket should be consumed until the server closes it, so a patch was implemented, to return the available response in such cases.
@@ -0,0 +1,55 @@
1
+ # 0.12.0
2
+
3
+ ## Features
4
+
5
+ ### AWS Sigv4 Authentication Plugin
6
+
7
+ A new plugin, `:aws_sigv4`, is now shipped with `httpx`. It implements the [AWS Signature Version 4 request signing process](https://docs.aws.amazon.com/general/latest/gr/signature-version-4.html), a well documented way of authenticating requests to AWS services, which has since been adopted by other cloud providers, such as Google Cloud Storage.
8
+
9
+ See how to use it here: https://gitlab.com/honeyryderchuck/httpx/-/wikis/AWS-Sigv4#sessionaws_sigv4_authentication
10
+
11
+ For convenience, there's a derivative plugin, `:aws_sdk_authentication`, which builds on top of `:aws_sigv4`, and integrates with the `aws-sdk-core` gem, maintained by AWS, to resolve the authentication credentials (p.ex. if you support ephemeral access keys).
12
+
13
+ See how to use it here: https://gitlab.com/honeyryderchuck/httpx/-/wikis/AWS-Sigv4#sessionaws_sdk_authentication
14
+
15
+ Other FAQ: https://gitlab.com/honeyryderchuck/httpx/-/wikis/AWS-Sigv4#faqs
16
+
17
+ ### HTTP/2 support for JRuby
18
+
19
+ `jruby-openssl` doesn't support ALPN protocol negotiation, nor are there plans to implement, which limited the seamless HTTP/2 usage in `httpx`. A new connection adapter was therefore added specifically for JRuby, where ssl/tls connections will be handled using ffi-based openssl bindings, provided you bundle `ffi-compiler` and `concurrent-ruby`, and install a TLS/1.2-compatible `openssl` package.
20
+
21
+ See how to use it here: https://gitlab.com/honeyryderchuck/httpx/-/wikis/JRuby-Truffleruby-Other-Rubies#http2
22
+
23
+ ## Improvements
24
+
25
+
26
+ ### truffleruby support
27
+
28
+ `httpx` supports and tests against `truffleruby` (known to run tests since v20.3, passing all tests since v21).
29
+
30
+ ### Performance
31
+
32
+ Several optimizations were introduced:
33
+
34
+ * Reduction in read/write system calls;
35
+ * more usage of `String#byteslice` in parsing (instead of string mutation);
36
+ * Avoid selection on connections with no outstanding requests;
37
+
38
+ They all contributed to a massive performance improvement, itself reflected in test runs, which need half the time they used to to complete.
39
+
40
+ ### APIs
41
+
42
+ * `HTTPX::ErrorResponse#to_s` now uses the exception full message, instead of just the backtrace.
43
+
44
+ ## Bugfixes
45
+
46
+ * HTTP/2 stream protocol errors do not cause the process to hang (instead, error responnses are yielded);
47
+ * Fixed body stream bugs on retries when error causing retry would happen mid-transfer;
48
+ * Fixed `:multipart` plugin body rewind on retries to start the transfer from the beginning;
49
+ * Fixed auto-load of `:proxy` plugin when `HTTPS_PROXY` or `HTTP_PROXY` is set;
50
+ * Errno::EPIPE errors mid transfer now cause `httpx` to read from the server and get the appropriate HTTP error response;
51
+ * Make sure that all requests have an error responnse if the error happens early;
52
+ * Fixed TCP handshake Errno::INPROGRESS handling inside TLS connnections, which was causing the process to hang in a high handshake contention scenario;
53
+ * Do not call the event loop if there's nothing to listen on (the DoH resolver was being listened on even if there was nothing to be request);
54
+ * Fixed double event registry for DoH resolvers;
55
+ *
data/lib/httpx.rb CHANGED
@@ -19,7 +19,6 @@ require "httpx/headers"
19
19
  require "httpx/request"
20
20
  require "httpx/response"
21
21
  require "httpx/chainable"
22
- require "httpx/session"
23
22
 
24
23
  # Top-Level Namespace
25
24
  #
@@ -59,3 +58,5 @@ module HTTPX
59
58
 
60
59
  extend Chainable
61
60
  end
61
+
62
+ require "httpx/session"
@@ -0,0 +1,205 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ddtrace/contrib/integration"
4
+ require "ddtrace/contrib/rest_client/configuration/settings"
5
+ require "ddtrace/contrib/rest_client/patcher"
6
+
7
+ module Datadog
8
+ module Contrib
9
+ module HTTPX
10
+ # HTTPX Datadog Plugin
11
+ #
12
+ # Enables tracing for httpx requests. A span will be created for each individual requests,
13
+ # and it'll trace since the moment it is fed to the connection, until the moment the response is
14
+ # fed back to the session.
15
+ #
16
+ module Plugin
17
+ class RequestTracer
18
+ SPAN_REQUEST = "httpx.request"
19
+
20
+ def initialize(request)
21
+ @request = request
22
+ end
23
+
24
+ def call
25
+ return if skip_tracing?
26
+
27
+ @request.on(:response, &method(:finish))
28
+
29
+ verb = @request.verb.to_s.upcase
30
+ uri = @request.uri
31
+
32
+ @span = datadog_pin.tracer.trace(SPAN_REQUEST)
33
+ service_name = datadog_config[:split_by_domain] ? uri.host : datadog_pin.service_name
34
+
35
+ begin
36
+ @span.service = service_name
37
+ @span.span_type = Datadog::Ext::HTTP::TYPE_OUTBOUND
38
+ @span.resource = verb
39
+
40
+ Datadog::HTTPPropagator.inject!(@span.context, @request.headers) if datadog_pin.tracer.enabled && !skip_distributed_tracing?
41
+
42
+ # Add additional request specific tags to the span.
43
+
44
+ @span.set_tag(Datadog::Ext::HTTP::URL, @request.path)
45
+ @span.set_tag(Datadog::Ext::HTTP::METHOD, verb)
46
+
47
+ @span.set_tag(Datadog::Ext::NET::TARGET_HOST, uri.host)
48
+ @span.set_tag(Datadog::Ext::NET::TARGET_PORT, uri.port.to_s)
49
+
50
+ # Tag as an external peer service
51
+ @span.set_tag(Datadog::Ext::Integration::TAG_PEER_SERVICE, @span.service)
52
+
53
+ # Set analytics sample rate
54
+ if Contrib::Analytics.enabled?(datadog_config[:analytics_enabled])
55
+ Contrib::Analytics.set_sample_rate(@span, datadog_config[:analytics_sample_rate])
56
+ end
57
+ rescue StandardError => e
58
+ Datadog.logger.error("error preparing span for http request: #{e}")
59
+ end
60
+ rescue StandardError => e
61
+ Datadog.logger.debug("Failed to start span: #{e}")
62
+ end
63
+
64
+ def finish(response)
65
+ return unless @span
66
+
67
+ if response.respond_to?(:error)
68
+ @span.set_error(response.error)
69
+ else
70
+ @span.set_tag(Datadog::Ext::HTTP::STATUS_CODE, response.status.to_s)
71
+
72
+ @span.set_error(::HTTPX::HTTPError.new(response)) if response.status >= 400 && response.status <= 599
73
+ end
74
+
75
+ @span.finish
76
+ end
77
+
78
+ private
79
+
80
+ def skip_tracing?
81
+ return true if @request.headers.key?(Datadog::Ext::Transport::HTTP::HEADER_META_TRACER_VERSION)
82
+
83
+ return false unless @datadog_pin
84
+
85
+ span = @datadog_pin.tracer.active_span
86
+
87
+ return true if span && (span.name == SPAN_REQUEST)
88
+
89
+ false
90
+ end
91
+
92
+ def skip_distributed_tracing?
93
+ return !datadog_pin.config[:distributed_tracing] if datadog_pin.config && datadog_pin.config.key?(:distributed_tracing)
94
+
95
+ !Datadog.configuration[:httpx][:distributed_tracing]
96
+ end
97
+
98
+ def datadog_pin
99
+ @datadog_pin ||= begin
100
+ service = datadog_config[:service_name]
101
+ tracer = datadog_config[:tracer]
102
+
103
+ Datadog::Pin.new(
104
+ service,
105
+ app: "httpx",
106
+ app_type: Datadog::Ext::AppTypes::WEB,
107
+ tracer: -> { tracer }
108
+ )
109
+ end
110
+ end
111
+
112
+ def datadog_config
113
+ @datadog_config ||= Datadog.configuration[:httpx, @request.uri.host]
114
+ end
115
+ end
116
+
117
+ module ConnectionMethods
118
+ def send(request)
119
+ RequestTracer.new(request).call
120
+ super
121
+ end
122
+ end
123
+ end
124
+
125
+ module Configuration
126
+ # Default settings for httpx
127
+ #
128
+ class Settings < Datadog::Contrib::Configuration::Settings
129
+ option :service_name, default: "httpx"
130
+ option :distributed_tracing, default: true
131
+ option :split_by_domain, default: false
132
+
133
+ option :enabled do |o|
134
+ o.default { env_to_bool("DD_TRACE_HTTPX_ENABLED", true) }
135
+ o.lazy
136
+ end
137
+
138
+ option :analytics_enabled do |o|
139
+ o.default { env_to_bool(%w[DD_TRACE_HTTPX_ANALYTICS_ENABLED DD_HTTPX_ANALYTICS_ENABLED], false) }
140
+ o.lazy
141
+ end
142
+
143
+ option :analytics_sample_rate do |o|
144
+ o.default { env_to_float(%w[DD_TRACE_HTTPX_ANALYTICS_SAMPLE_RATE DD_HTTPX_ANALYTICS_SAMPLE_RATE], 1.0) }
145
+ o.lazy
146
+ end
147
+
148
+ option :error_handler, default: Datadog::Tracer::DEFAULT_ON_ERROR
149
+ end
150
+ end
151
+
152
+ # Patcher enables patching of 'httpx' with datadog components.
153
+ #
154
+ module Patcher
155
+ include Datadog::Contrib::Patcher
156
+
157
+ module_function
158
+
159
+ def target_version
160
+ Integration.version
161
+ end
162
+
163
+ # loads a session instannce with the datadog plugin, and replaces the
164
+ # base HTTPX::Session with the patched session class.
165
+ def patch
166
+ datadog_session = ::HTTPX.plugin(Plugin)
167
+
168
+ ::HTTPX.send(:remove_const, :Session)
169
+ ::HTTPX.send(:const_set, :Session, datadog_session.class)
170
+ end
171
+ end
172
+
173
+ # Datadog Integration for HTTPX.
174
+ #
175
+ class Integration
176
+ include Contrib::Integration
177
+
178
+ # MINIMUM_VERSION = Gem::Version.new('0.11.0')
179
+ MINIMUM_VERSION = Gem::Version.new("0.10.2")
180
+
181
+ register_as :httpx
182
+
183
+ def self.version
184
+ Gem.loaded_specs["httpx"] && Gem.loaded_specs["httpx"].version
185
+ end
186
+
187
+ def self.loaded?
188
+ defined?(::HTTPX::Request)
189
+ end
190
+
191
+ def self.compatible?
192
+ super && version >= MINIMUM_VERSION
193
+ end
194
+
195
+ def default_configuration
196
+ Configuration::Settings.new
197
+ end
198
+
199
+ def patcher
200
+ Patcher
201
+ end
202
+ end
203
+ end
204
+ end
205
+ end
@@ -65,7 +65,6 @@ module Faraday
65
65
  plugin(:compression)
66
66
  plugin(:persistent)
67
67
 
68
- # :nocov:
69
68
  module ReasonPlugin
70
69
  if RUBY_VERSION < "2.5"
71
70
  def self.load_dependencies(*)
@@ -88,7 +87,6 @@ module Faraday
88
87
  end
89
88
  end
90
89
  end
91
- # :nocov:
92
90
  plugin(ReasonPlugin)
93
91
  end
94
92
 
@@ -125,11 +123,9 @@ module Faraday
125
123
  end
126
124
 
127
125
  def method_missing(meth, *args, &blk)
128
- if @env && @env.respond_to?(meth)
129
- @env.__send__(meth, *args, &blk)
130
- else
131
- super
132
- end
126
+ return super unless @env && @env.respond_to?(meth)
127
+
128
+ @env.__send__(meth, *args, &blk)
133
129
  end
134
130
  end
135
131
 
@@ -199,7 +195,7 @@ module Faraday
199
195
  response_headers.merge!(response.headers)
200
196
  end
201
197
  @app.call(env)
202
- rescue OpenSSL::SSL::SSLError => e
198
+ rescue ::HTTPX::TLSError => e
203
199
  raise SSL_ERROR, e
204
200
  rescue Errno::ECONNABORTED,
205
201
  Errno::ECONNREFUSED,