httpx 0.21.0 → 0.22.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +53 -35
- data/doc/release_notes/0_10_0.md +2 -2
- data/doc/release_notes/0_11_0.md +3 -5
- data/doc/release_notes/0_12_0.md +5 -5
- data/doc/release_notes/0_13_0.md +4 -4
- data/doc/release_notes/0_14_0.md +2 -2
- data/doc/release_notes/0_16_0.md +3 -3
- data/doc/release_notes/0_17_0.md +1 -1
- data/doc/release_notes/0_18_0.md +4 -4
- data/doc/release_notes/0_18_2.md +1 -1
- data/doc/release_notes/0_19_0.md +1 -1
- data/doc/release_notes/0_20_0.md +1 -1
- data/doc/release_notes/0_21_0.md +7 -5
- data/doc/release_notes/0_21_1.md +12 -0
- data/doc/release_notes/0_22_0.md +13 -0
- data/doc/release_notes/0_22_1.md +11 -0
- data/doc/release_notes/0_22_2.md +5 -0
- data/doc/release_notes/0_22_3.md +55 -0
- data/doc/release_notes/0_22_4.md +6 -0
- data/lib/httpx/adapters/datadog.rb +1 -1
- data/lib/httpx/adapters/faraday.rb +12 -4
- data/lib/httpx/adapters/sentry.rb +6 -2
- data/lib/httpx/connection/http2.rb +1 -1
- data/lib/httpx/connection.rb +34 -6
- data/lib/httpx/errors.rb +2 -0
- data/lib/httpx/extensions.rb +10 -1
- data/lib/httpx/io/tcp.rb +2 -1
- data/lib/httpx/io/udp.rb +4 -5
- data/lib/httpx/options.rb +2 -2
- data/lib/httpx/plugins/authentication.rb +1 -1
- data/lib/httpx/plugins/aws_sigv4.rb +2 -2
- data/lib/httpx/plugins/basic_authentication.rb +1 -1
- data/lib/httpx/plugins/circuit_breaker/circuit.rb +1 -1
- data/lib/httpx/plugins/circuit_breaker.rb +1 -1
- data/lib/httpx/plugins/compression/gzip.rb +1 -1
- data/lib/httpx/plugins/compression.rb +4 -4
- data/lib/httpx/plugins/cookies.rb +1 -1
- data/lib/httpx/plugins/digest_authentication.rb +3 -1
- data/lib/httpx/plugins/expect.rb +4 -3
- data/lib/httpx/plugins/follow_redirects.rb +8 -1
- data/lib/httpx/plugins/grpc/message.rb +1 -1
- data/lib/httpx/plugins/grpc.rb +1 -1
- data/lib/httpx/plugins/h2c.rb +1 -1
- data/lib/httpx/plugins/multipart/decoder.rb +7 -57
- data/lib/httpx/plugins/multipart.rb +2 -2
- data/lib/httpx/plugins/ntlm_authentication.rb +3 -1
- data/lib/httpx/plugins/persistent.rb +1 -1
- data/lib/httpx/plugins/proxy/http.rb +4 -2
- data/lib/httpx/plugins/proxy.rb +1 -1
- data/lib/httpx/plugins/push_promise.rb +1 -1
- data/lib/httpx/plugins/rate_limiter.rb +3 -1
- data/lib/httpx/plugins/response_cache.rb +1 -1
- data/lib/httpx/plugins/retries.rb +3 -2
- data/lib/httpx/plugins/stream.rb +0 -2
- data/lib/httpx/plugins/upgrade.rb +3 -1
- data/lib/httpx/plugins/webdav.rb +2 -0
- data/lib/httpx/pool.rb +41 -2
- data/lib/httpx/request.rb +1 -1
- data/lib/httpx/resolver/https.rb +16 -2
- data/lib/httpx/resolver/native.rb +28 -26
- data/lib/httpx/resolver/resolver.rb +9 -8
- data/lib/httpx/resolver.rb +8 -0
- data/lib/httpx/response.rb +8 -0
- data/lib/httpx/transcoder/xml.rb +0 -2
- data/lib/httpx/transcoder.rb +1 -1
- data/lib/httpx/utils.rb +30 -0
- data/lib/httpx/version.rb +1 -1
- data/lib/httpx.rb +6 -0
- data/sig/connection.rbs +3 -1
- data/sig/plugins/multipart.rbs +0 -2
- data/sig/pool.rbs +3 -1
- data/sig/resolver/https.rbs +3 -2
- data/sig/resolver/native.rbs +2 -1
- data/sig/resolver/resolver.rbs +3 -1
- data/sig/resolver.rbs +1 -1
- data/sig/response.rbs +4 -1
- data/sig/utils.rbs +2 -0
- metadata +21 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d5e3e33caae5726e0c7630721296abac27073ed1fc071a7bb8c9467a2b1b2e0
|
4
|
+
data.tar.gz: f4344aee8002ecbe64d6e3321e1ca9f18507e2fd70223890211e05ab15967479
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c42940a7467f91f66779bdf26b83043fb99b17033d69cee7d7656946abc03a064f1b9952889b3c783b757429d5cc6d476575ff9ab347524738152f846c3ea91
|
7
|
+
data.tar.gz: 6199caed20de123a10af893a85c2657cc4b4bfb6645592a5155743e74a37ff754d3fcf404c8bb28582bead974b35c6f872d40d8b5ac77806bdc4b34992847e7a
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
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/
|
5
|
-
[![coverage report](https://gitlab.com/
|
4
|
+
[![pipeline status](https://gitlab.com/os85/httpx/badges/master/pipeline.svg)](https://gitlab.com/os85/httpx/pipelines?page=1&scope=all&ref=master)
|
5
|
+
[![coverage report](https://gitlab.com/os85/httpx/badges/master/coverage.svg?job=coverage)](https://os85.gitlab.io/httpx/coverage/#_AllFiles)
|
6
6
|
|
7
7
|
HTTPX is an HTTP client library for the Ruby programming language.
|
8
8
|
|
@@ -19,13 +19,17 @@ And also:
|
|
19
19
|
|
20
20
|
* Compression (gzip, deflate, brotli)
|
21
21
|
* Streaming Requests
|
22
|
-
* Authentication (Basic Auth, Digest Auth)
|
22
|
+
* Authentication (Basic Auth, Digest Auth, NTLM)
|
23
23
|
* Expect 100-continue
|
24
24
|
* Multipart Requests
|
25
|
-
*
|
25
|
+
* Advanced Cookie handling
|
26
26
|
* HTTP/2 Server Push
|
27
|
-
*
|
27
|
+
* HTTP/1.1 Upgrade (support for "h2c", "h2")
|
28
28
|
* Automatic follow redirects
|
29
|
+
* GRPC
|
30
|
+
* WebDAV
|
31
|
+
* Circuit Breaker
|
32
|
+
* HTTP-based response cache
|
29
33
|
* International Domain Names
|
30
34
|
|
31
35
|
## How
|
@@ -36,7 +40,14 @@ Here are some simple examples:
|
|
36
40
|
HTTPX.get("https://nghttp2.org").to_s #=> "<!DOCT...."
|
37
41
|
```
|
38
42
|
|
39
|
-
And that's the simplest one there is.
|
43
|
+
And that's the simplest one there is. But you can also do:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
HTTPX.post("http://example.com", form: { user: "john", password: "pass" })
|
47
|
+
|
48
|
+
http = HTTPX.with(headers: { "x-my-name" => "joe" })
|
49
|
+
http.patch(("http://example.com/file", body: File.open("path/to/file")) # request body is streamed
|
50
|
+
```
|
40
51
|
|
41
52
|
If you want to do some more things with the response, you can get an `HTTPX::Response`:
|
42
53
|
|
@@ -50,7 +61,7 @@ puts body #=> #<HTTPX::Response ...
|
|
50
61
|
You can also send as many requests as you want simultaneously:
|
51
62
|
|
52
63
|
```ruby
|
53
|
-
page1, page2, page3
|
64
|
+
page1, page2, page3 =`HTTPX.get("https://news.ycombinator.com/news", "https://news.ycombinator.com/news?p=2", "https://news.ycombinator.com/news?p=3")
|
54
65
|
```
|
55
66
|
|
56
67
|
## Installation
|
@@ -73,43 +84,53 @@ and then just require it in your program:
|
|
73
84
|
require "httpx"
|
74
85
|
```
|
75
86
|
|
76
|
-
##
|
87
|
+
## What makes it the best ruby HTTP client
|
77
88
|
|
78
|
-
In Ruby, HTTP client implementations are a known cheap commodity. Why this one?
|
79
89
|
|
80
|
-
### Concurrency
|
90
|
+
### Concurrency, HTTP/2 support
|
81
91
|
|
82
|
-
|
92
|
+
`httpx` supports HTTP/2 (for "https" requests, it'll automatically do ALPN negotiation). However if the server supports HTTP/1.1, it will use HTTP pipelining, falling back to 1 request at a time if the server doesn't support it either (and it'll use Keep-Alive connections, unless the server does not support).
|
83
93
|
|
84
|
-
|
94
|
+
If you passed multiple URIs, it'll perform all of the requests concurrently, by mulitplexing on the necessary sockets (and it'll batch requests to the same socket when the origin is the same):
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
HTTPX.get(
|
98
|
+
"https://news.ycombinator.com/news",
|
99
|
+
"https://news.ycombinator.com/news?p=2",
|
100
|
+
"https://google.com/q=me"
|
101
|
+
) # first two requests will be multiplexed on the same socket.
|
102
|
+
```
|
85
103
|
|
86
104
|
### Clean API
|
87
105
|
|
88
106
|
`httpx` builds all functions around the `HTTPX` module, so that all calls can compose of each other. Here are a few examples:
|
89
107
|
|
90
108
|
```ruby
|
91
|
-
response = HTTPX.get("https://www.google.com")
|
92
|
-
response = HTTPX.post("https://www.nghttp2.org/httpbin/post",
|
109
|
+
response = HTTPX.get("https://www.google.com", params: { q: "me" })
|
110
|
+
response = HTTPX.post("https://www.nghttp2.org/httpbin/post", form: {name: "John", age: "22"})
|
93
111
|
response = HTTPX.plugin(:basic_authentication)
|
94
112
|
.basic_authentication("user", "pass")
|
95
113
|
.get("https://www.google.com")
|
114
|
+
|
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"})
|
117
|
+
http.get("https://example.com") # the above options will apply
|
118
|
+
http.post("https://example2.com", form: {name: "John", age: "22"}) # same, plus the form POST body
|
96
119
|
```
|
97
120
|
|
98
121
|
### Lightweight
|
99
122
|
|
100
|
-
It ships with a plugin
|
101
|
-
|
102
|
-
It means that it loads the bare minimum to perform requests, and the user has to explicitly load the plugins, in order to get the features he/she needs.
|
123
|
+
It ships with most features published as a plugin, making vanilla `httpx` lightweight and dependency-free, while allowing you to "pay for what you use"
|
103
124
|
|
104
|
-
|
125
|
+
The plugin system is similar to the ones used by [sequel](https://github.com/jeremyevans/sequel), [roda](https://github.com/jeremyevans/roda) or [shrine](https://github.com/janko-m/shrine).
|
105
126
|
|
106
|
-
### DNS
|
127
|
+
### Advanced DNS features
|
107
128
|
|
108
|
-
`HTTPX` ships with custom DNS resolver implementations, including a DNS-over-HTTPS resolver.
|
129
|
+
`HTTPX` ships with custom DNS resolver implementations, including a native Happy Eyeballs resolver immplementation, and a DNS-over-HTTPS resolver.
|
109
130
|
|
110
|
-
##
|
131
|
+
## User-driven test suite
|
111
132
|
|
112
|
-
The test suite runs against [httpbin proxied over nghttp2](https://nghttp2.org/httpbin/), so
|
133
|
+
The test suite runs against [httpbin proxied over nghttp2](https://nghttp2.org/httpbin/), so actual requests are performed during tests.
|
113
134
|
|
114
135
|
## Supported Rubies
|
115
136
|
|
@@ -118,27 +139,24 @@ All Rubies greater or equal to 2.1, and always latest JRuby and Truffleruby.
|
|
118
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.
|
119
140
|
|
120
141
|
## Resources
|
121
|
-
| |
|
122
|
-
| ------------- |
|
123
|
-
| Website | https://honeyryderchuck.gitlab.io/httpx/
|
124
|
-
| Documentation | https://honeyryderchuck.gitlab.io/httpx/rdoc/
|
125
|
-
| Wiki | https://gitlab.
|
126
|
-
| CI | https://gitlab.com/
|
142
|
+
| | |
|
143
|
+
| ------------- | ------------------------------------------------------ |
|
144
|
+
| Website | https://honeyryderchuck.gitlab.io/httpx/ |
|
145
|
+
| Documentation | https://honeyryderchuck.gitlab.io/httpx/rdoc/ |
|
146
|
+
| Wiki | https://honeyryderchuck.gitlab.io/httpx/wiki/home.html |
|
147
|
+
| CI | https://gitlab.com/os85/httpx/pipelines |
|
148
|
+
| Rubygems | https://rubygems.org/gems/httpx |
|
127
149
|
|
128
150
|
## Caveats
|
129
151
|
|
130
152
|
### ALPN support
|
131
153
|
|
132
|
-
|
133
|
-
|
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).
|
135
|
-
|
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.
|
154
|
+
ALPN negotiation is required for "auto" HTTP/2 "https" requests. This is available in ruby since version 2.3 .
|
137
155
|
|
138
156
|
### Known bugs
|
139
157
|
|
140
|
-
* Doesn't work with ruby 2.4.0 for Windows (see [#36](https://gitlab.com/
|
141
|
-
* Using `total_timeout` along with the `:persistent` plugin [does not work as you might expect](https://gitlab.com/
|
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).
|
142
160
|
|
143
161
|
## Versioning Policy
|
144
162
|
|
data/doc/release_notes/0_10_0.md
CHANGED
@@ -15,7 +15,7 @@ http.get(stream_api_endpoint, stream: true).each_line do |line|
|
|
15
15
|
end
|
16
16
|
```
|
17
17
|
|
18
|
-
https://gitlab.com/
|
18
|
+
https://gitlab.com/os85/httpx/-/wikis/Stream
|
19
19
|
|
20
20
|
### Rate Limiter
|
21
21
|
|
@@ -27,7 +27,7 @@ HTTPX.plugin(:rate_limiter).get(rate_limited_api_endpoint)
|
|
27
27
|
# waits 3 seconds before retrying
|
28
28
|
```
|
29
29
|
|
30
|
-
https://gitlab.com/
|
30
|
+
https://gitlab.com/os85/httpx/-/wikis/Rate-Limiter
|
31
31
|
|
32
32
|
### Ruby 3
|
33
33
|
|
data/doc/release_notes/0_11_0.md
CHANGED
@@ -21,7 +21,7 @@ stub_http_request(:get, "https://www.google.com").and_return(status: 200, body:
|
|
21
21
|
|
22
22
|
```
|
23
23
|
|
24
|
-
Read more about it in the [webmock integration documentation](https://
|
24
|
+
Read more about it in the [webmock integration documentation](https://os85.gitlab.io/httpx/wiki/Webmock-Adapter).
|
25
25
|
|
26
26
|
### Datadog Adapter
|
27
27
|
|
@@ -40,7 +40,7 @@ A trace will be emitted for every request, so this should be an interesting visu
|
|
40
40
|
|
41
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
42
|
|
43
|
-
Read more about it in the [datadog integration documentation](https://
|
43
|
+
Read more about it in the [datadog integration documentation](https://os85.gitlab.io/httpx/wiki/Datadog-Adapter).
|
44
44
|
|
45
45
|
## Improvements
|
46
46
|
|
@@ -52,7 +52,7 @@ Read more about it in the [datadog integration documentation](https://honeyryder
|
|
52
52
|
HTTPX.plugin(:multipart).post(uri, form: {file: File.new("path/to/file")})
|
53
53
|
```
|
54
54
|
|
55
|
-
Read more about it in the [multipart plugin documentation](https://
|
55
|
+
Read more about it in the [multipart plugin documentation](https://os85.gitlab.io/httpx/wiki/Multipart-Uploads), including also about why this was made.
|
56
56
|
|
57
57
|
### Expect Plugin
|
58
58
|
|
@@ -72,5 +72,3 @@ response = session.get(proxy_ip, headers: { "host" => upstream_hostname }, ssl:
|
|
72
72
|
## Bugfixes
|
73
73
|
|
74
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
|
-
|
data/doc/release_notes/0_12_0.md
CHANGED
@@ -6,19 +6,19 @@
|
|
6
6
|
|
7
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
8
|
|
9
|
-
See how to use it here: https://gitlab.com/
|
9
|
+
See how to use it here: https://gitlab.com/os85/httpx/-/wikis/AWS-Sigv4#sessionaws_sigv4_authentication
|
10
10
|
|
11
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
12
|
|
13
|
-
See how to use it here: https://gitlab.com/
|
13
|
+
See how to use it here: https://gitlab.com/os85/httpx/-/wikis/AWS-Sigv4#sessionaws_sdk_authentication
|
14
14
|
|
15
|
-
Other FAQ: https://gitlab.com/
|
15
|
+
Other FAQ: https://gitlab.com/os85/httpx/-/wikis/AWS-Sigv4#faqs
|
16
16
|
|
17
17
|
### HTTP/2 support for JRuby
|
18
18
|
|
19
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
20
|
|
21
|
-
See how to use it here: https://gitlab.com/
|
21
|
+
See how to use it here: https://gitlab.com/os85/httpx/-/wikis/JRuby-Truffleruby-Other-Rubies#http2
|
22
22
|
|
23
23
|
## Improvements
|
24
24
|
|
@@ -52,4 +52,4 @@ They all contributed to a massive performance improvement, itself reflected in t
|
|
52
52
|
* Fixed TCP handshake Errno::INPROGRESS handling inside TLS connnections, which was causing the process to hang in a high handshake contention scenario;
|
53
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
54
|
* Fixed double event registry for DoH resolvers;
|
55
|
-
*
|
55
|
+
*
|
data/doc/release_notes/0_13_0.md
CHANGED
@@ -4,9 +4,9 @@
|
|
4
4
|
|
5
5
|
### Upgrade plugin
|
6
6
|
|
7
|
-
A new plugin, `:upgrade`, is now available. This plugin allows one to "hook" on HTTP/1.1's protocol upgrade mechanism (see: https://developer.mozilla.org/en-US/docs/Web/HTTP/Protocol_upgrade_mechanism), which is the mechanism that browsers use to initiate websockets (there is an example of how to use `httpx` to start a websocket client connection [in the tests](https://gitlab.com/
|
7
|
+
A new plugin, `:upgrade`, is now available. This plugin allows one to "hook" on HTTP/1.1's protocol upgrade mechanism (see: https://developer.mozilla.org/en-US/docs/Web/HTTP/Protocol_upgrade_mechanism), which is the mechanism that browsers use to initiate websockets (there is an example of how to use `httpx` to start a websocket client connection [in the tests](https://gitlab.com/os85/httpx/-/blob/master/test/support/requests/plugins/upgrade.rb))
|
8
8
|
|
9
|
-
You can read more about the `:upgrade` plugin in the [wiki](https://
|
9
|
+
You can read more about the `:upgrade` plugin in the [wiki](https://os85.gitlab.io/httpx/wiki/Connection-Upgrade).
|
10
10
|
|
11
11
|
It's the basis of two plugins:
|
12
12
|
|
@@ -14,13 +14,13 @@ It's the basis of two plugins:
|
|
14
14
|
|
15
15
|
This plugin was been rewritten on top of the `:upgrade` plugin, and handles upgrading a plaintext (non-"https") HTTP/1.1 connection, into an HTTP/2 connection.
|
16
16
|
|
17
|
-
https://
|
17
|
+
https://os85.gitlab.io/httpx/wiki/Connection-Upgrade#h2c
|
18
18
|
|
19
19
|
#### `:upgrade/h2`
|
20
20
|
|
21
21
|
This plugin handles when a server responds to a request with an `Upgrade: h2` header, does the following requests to the same origin via HTTP/2 prior knowledge (bypassing the necessity for ALPN negotiation, which is the whole point of the feature).
|
22
22
|
|
23
|
-
https://
|
23
|
+
https://os85.gitlab.io/httpx/wiki/Connection-Upgrade#h2
|
24
24
|
|
25
25
|
### `:addresses` option
|
26
26
|
|
data/doc/release_notes/0_14_0.md
CHANGED
@@ -17,7 +17,7 @@ helloworld_svc = helloworld_stub.rpc(:SayHello, HelloRequest, HelloReply)
|
|
17
17
|
result = helloworld_svc.say_hello(HelloRequest.new(name: "Jack")) #=> HelloReply: "Hello Jack"
|
18
18
|
```
|
19
19
|
|
20
|
-
You can read more about the `:grpc` plugin in the [wiki](https://
|
20
|
+
You can read more about the `:grpc` plugin in the [wiki](https://os85.gitlab.io/httpx/wiki/GRPC).
|
21
21
|
|
22
22
|
### :origin
|
23
23
|
|
@@ -37,7 +37,7 @@ httpbin.get("/httpbin/get") #=> #<Response:5420 HTTP/2.0 @status=200 ....
|
|
37
37
|
* setting an unexpected option will now raise an `HTTPX::Error` with an helpful message, instead of a confusing `NoMethodError`:
|
38
38
|
|
39
39
|
```ruby
|
40
|
-
HTTPX.with(foo: "bar")
|
40
|
+
HTTPX.with(foo: "bar")
|
41
41
|
# before
|
42
42
|
#=> NoMethodError
|
43
43
|
# after
|
data/doc/release_notes/0_16_0.md
CHANGED
@@ -16,7 +16,7 @@ response.body.to_s #=> ""
|
|
16
16
|
|
17
17
|
The justification for this behaviour probably had to do with avoiding keeping huge payloads around, but it got a bit lost in git history. It became a feature, not a bug.
|
18
18
|
|
19
|
-
However, I got an [issue report](https://gitlab.com/
|
19
|
+
However, I got an [issue report](https://gitlab.com/os85/httpx/-/issues/143) that made me change my mind about this behaviour (tl;dr: it broke pattern matching when matching against response bodies more than once).
|
20
20
|
|
21
21
|
So now, you can call `.to_s` how many times you want!
|
22
22
|
|
@@ -62,7 +62,7 @@ stub.get_feature(# ...
|
|
62
62
|
|
63
63
|
### OptionsMethods for plugins
|
64
64
|
|
65
|
-
https://gitlab.com/
|
65
|
+
https://gitlab.com/os85/httpx/-/wikis/Custom-Plugins
|
66
66
|
|
67
67
|
You can now define an `OptionsMethods` module under your custom plugin to define your own methods. The tl;dr is, that, given the following module below, a new `:bar` option will be available (and the method will be used to set it):
|
68
68
|
|
@@ -80,7 +80,7 @@ HTTPX.plugin(CustomPlugin).with(bar: 2)
|
|
80
80
|
|
81
81
|
The behaviour of the cookies jar from the `:cookies` plugin was a bit unpredictable in certain conditions, for instance if a "Cookie" header would be passed directly via `.with(headers: {"Cookie" => "a=1"})` and there'd be a value for it already (in same cases, it'd be fully ignored). This would even get worse, if the session had a jar, and a specific set of cookies would be passed to a request(i.e.: `session_with_cookies.get("http://url.get", headers: {"Cookies" => "..."}`).
|
82
82
|
|
83
|
-
The behaviour was fixed, and is now specced under https://gitlab.com/
|
83
|
+
The behaviour was fixed, and is now specced under https://gitlab.com/os85/httpx/-/blob/master/test/support/requests/plugins/cookies.rb .
|
84
84
|
|
85
85
|
## Bugfixes
|
86
86
|
|
data/doc/release_notes/0_17_0.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
### Response mime type decoders (#json, #form)
|
6
6
|
|
7
|
-
https://gitlab.com/
|
7
|
+
https://gitlab.com/os85/httpx/-/wikis/Response-Handling#response-decoding
|
8
8
|
|
9
9
|
Two new methods, `#json` and `#form`, were added to `HTTPX::Response`. As the name implies, they'll decode the raw payload into ruby objects you can work with.
|
10
10
|
|
data/doc/release_notes/0_18_0.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
### Response Cache
|
6
6
|
|
7
|
-
https://gitlab.com/
|
7
|
+
https://gitlab.com/os85/httpx/-/wikis/Response-Cache
|
8
8
|
|
9
9
|
The `:response_cache` plugin handles transparent usage of HTTP caching and conditional requests to improve performance and bandwidth usage.
|
10
10
|
|
@@ -22,7 +22,7 @@ r1.body == r2.body #=> true
|
|
22
22
|
|
23
23
|
On the `:retries` plugin, jitter calculation is now applied to the value in seconds defined by user after which a request should be retried (i.e. if `:retry_after` option is set to `2`, the retry interval may be `1.5422312` seconds, for example). This is important to avoid cases of synchronized "thundering herd", where server rejects requests, but they all get retried at the same time because the retry interval is exactly the same.
|
24
24
|
|
25
|
-
You can override the jitter calculation function by using the [:retry_jitter](https://gitlab.com/
|
25
|
+
You can override the jitter calculation function by using the [:retry_jitter](https://gitlab.com/os85/httpx/-/wikis/Retries#retry_jitter) option:
|
26
26
|
|
27
27
|
```ruby
|
28
28
|
HTTPX.plugin(:retries, retry_after: 2, retry_jitter: ->(interval) { interval + rand }) # interval is 3
|
@@ -44,7 +44,7 @@ end
|
|
44
44
|
|
45
45
|
## Improvements
|
46
46
|
|
47
|
-
* `webmock` adapter: added support for "stub_http_request#to_timeout" (https://gitlab.com/
|
47
|
+
* `webmock` adapter: added support for "stub_http_request#to_timeout" (https://gitlab.com/os85/httpx/-/merge_requests/165).
|
48
48
|
|
49
49
|
## timers not a dependency
|
50
50
|
|
@@ -57,7 +57,7 @@ The functionality provided by the `timers` gem was replaced by a simpler custom
|
|
57
57
|
|
58
58
|
## Bugfixes
|
59
59
|
|
60
|
-
* Fixed Error class declaration on response decoders when mime type is invalid (https://gitlab.com/
|
60
|
+
* Fixed Error class declaration on response decoders when mime type is invalid (https://gitlab.com/os85/httpx/-/merge_requests/166).
|
61
61
|
* `ErrorResponse#to_s` now removes ANSI escape sequences from error backtraces.
|
62
62
|
* Persistent connections were kept around both in the pool and in the selector; the first is necessary, but the second caused busy loop scenarios all over; they are now removed when no requests are being handled.
|
63
63
|
* Connections which failed connection handshake were removed from the pool, but not from the selector list, causing busy loop scenarios in a few cases; this has been fixed.
|
data/doc/release_notes/0_18_2.md
CHANGED
@@ -7,4 +7,4 @@
|
|
7
7
|
|
8
8
|
## Chore
|
9
9
|
|
10
|
-
The quirk of using the `:persistent` plugin with `:total_timeout` has been documented: https://gitlab.com/
|
10
|
+
The quirk of using the `:persistent` plugin with `:total_timeout` has been documented: https://gitlab.com/os85/httpx/-/wikis/Timeouts#total_timeout.
|
data/doc/release_notes/0_19_0.md
CHANGED
@@ -28,7 +28,7 @@ Connection coalescing has also been enabled for proxied connections (also `CONNE
|
|
28
28
|
|
29
29
|
### curl-to-httpx
|
30
30
|
|
31
|
-
widget in [project website](https://
|
31
|
+
widget in [project website](https://os85.gitlab.io/httpx/) to turn curl commands into the equivalent `httpx` code.
|
32
32
|
|
33
33
|
## Bugfixes
|
34
34
|
|
data/doc/release_notes/0_20_0.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
### Sentry integration
|
6
6
|
|
7
|
-
Documentation: https://gitlab.com/
|
7
|
+
Documentation: https://gitlab.com/os85/httpx/-/wikis/Sentry-Adapter
|
8
8
|
|
9
9
|
`httpx` ships with integration for `sentry-ruby` to provide HTTP request specific breadcrumbs and tracing. It can be enabled via:
|
10
10
|
|
data/doc/release_notes/0_21_0.md
CHANGED
@@ -4,12 +4,12 @@
|
|
4
4
|
|
5
5
|
### `:write_timeout`, `:read_timeout` and `:request_timeout`
|
6
6
|
|
7
|
-
https://gitlab.com/
|
7
|
+
https://gitlab.com/os85/httpx/-/wikis/Timeouts
|
8
8
|
|
9
9
|
The following timeouts are now supported:
|
10
10
|
|
11
11
|
* `:write_timeout`: total time (in seconds) to write a request to the server;
|
12
|
-
* `:read_timeout`: total time (in seconds) to read
|
12
|
+
* `:read_timeout`: total time (in seconds) to read a response from the server;
|
13
13
|
* `:request_timeout`: tracks both of the above (time to write the request and read a response);
|
14
14
|
|
15
15
|
```ruby
|
@@ -22,10 +22,12 @@ None of them has a default value, in order not to break integrations, but that'l
|
|
22
22
|
|
23
23
|
### Circuit Breaker plugin
|
24
24
|
|
25
|
-
https://gitlab.com/
|
25
|
+
https://gitlab.com/os85/httpx/-/wikis/Circuit-Breaker
|
26
26
|
|
27
27
|
The `:circuit_breaker` plugin wraps around errors happening when performing HTTP requests, and support options for setting maximum number of attempts before circuit opens (`:circuit_breaker_max_attempts`), period after which attempts should be reset (`:circuit_breaker_reset_attempts_in`), timespan until circuit half-opens (`circuit_breaker_break_in`), respective half-open drip rate (`:circuit_breaker_half_open_drip_rate`), and a callback to do your own check on whether a response has failed, in case you want HTTP level errors to be marked as failed attempts (`:circuit_breaker_break_on`).
|
28
28
|
|
29
|
+
Read the wiki for more info about the defaults.
|
30
|
+
|
29
31
|
```ruby
|
30
32
|
http = HTTPX.plugin(:circuit_breaker)
|
31
33
|
# that's it!
|
@@ -34,7 +36,7 @@ http.get(...
|
|
34
36
|
|
35
37
|
### WebDAV plugin
|
36
38
|
|
37
|
-
https://gitlab.com/
|
39
|
+
https://gitlab.com/os85/httpx/-/wikis/WebDav
|
38
40
|
|
39
41
|
The `:webdav` introduces some "convenience" methods to perform common WebDAV operations.
|
40
42
|
|
@@ -49,7 +51,7 @@ res = webdav.copy("/file.html", "/newdir/copy.html")
|
|
49
51
|
|
50
52
|
### XML transcoder, `:xml` option and `response.xml`
|
51
53
|
|
52
|
-
A new transcoder was added fot the XML mime type, which requires `"nokogiri"` to be installed
|
54
|
+
A new transcoder was added fot the XML mime type, which requires `"nokogiri"` to be installed. It can both serialize Nokogiri nodes in a request, and parse response content into nokogiri nodes:
|
53
55
|
|
54
56
|
```ruby
|
55
57
|
response = HTTPX.post("https://xml-server.com", xml: Nokogiri::XML("<xml ..."))
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# 0.21.1
|
2
|
+
|
3
|
+
## Bugfixes
|
4
|
+
|
5
|
+
* fix: protecting tcp connect phase against low-level syscall errors
|
6
|
+
* such as network unreachable, which can happen if connectivity is lost meanwhile.
|
7
|
+
* native resolver: fix for nameserver switch not happening in case of DNS timeout.
|
8
|
+
* when more than a nameserver was advertised by the system.
|
9
|
+
|
10
|
+
## Chore
|
11
|
+
|
12
|
+
* Removing usage of deprecated `Random::DEFAULT.rand` (using `Random.rand` instead)-
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# 0.22.0
|
2
|
+
|
3
|
+
## Improvements
|
4
|
+
|
5
|
+
### Happy Eyeballs v2 finalized
|
6
|
+
|
7
|
+
Until now, httpx was issuing concurrent DNS requests, but it'd only start connecting to the first, and then on the following by the right order, but sequentially.
|
8
|
+
|
9
|
+
`httpx` will now establish connections concurrently to both IPv6 and IPv4 addresses of a given domain; the first one to succeed terminates the other. Successful connection means completion of both TCP and TLS (when applicable) handshakes.
|
10
|
+
|
11
|
+
### HTTPX::Response::Body#encoding
|
12
|
+
|
13
|
+
A new method, `#encoding`, can be called on response bodies. It'll return the encoding of the response payload.
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# 0.22.1
|
2
|
+
|
3
|
+
## Bugfixes
|
4
|
+
|
5
|
+
* `:retries` plugin: fix `HTTPX::Response#response to point to last possible response in the redirection chain.
|
6
|
+
* `:stream` plugin: Make `HTTPX::Session#request` public (as it is inn the main class) .
|
7
|
+
* return 100 responses if the request didn't specifically ask for "100-continue" negotiation (via the "expect" header).
|
8
|
+
|
9
|
+
## Improvements
|
10
|
+
|
11
|
+
Wrap low-level socket errors in a `HTTPX::ConnectionError` exception.
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# 0.22.3
|
2
|
+
|
3
|
+
## Features
|
4
|
+
|
5
|
+
### HTTPX::Response::Body#filename
|
6
|
+
|
7
|
+
A new method, `.filename` can be called on response bodies, to get the filename referenced by the server for the received payload (usually in the "Content-Disposition" header).
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
response = HTTPX.get(url)
|
11
|
+
response.raise_for_status
|
12
|
+
filename = response.body.filename
|
13
|
+
# you can do, for example:
|
14
|
+
response.body.copy_to("/home/files/#{filename}")
|
15
|
+
```
|
16
|
+
|
17
|
+
## Improvements
|
18
|
+
|
19
|
+
### Loading integrations by default
|
20
|
+
|
21
|
+
Integrations will be loaded by default, as long as the dependency being integrated is already available:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require "ddtrace"
|
25
|
+
require "httpx"
|
26
|
+
|
27
|
+
HTTPX.get(... # request will be traced via the datadog integration
|
28
|
+
```
|
29
|
+
|
30
|
+
### Faraday: better error handling
|
31
|
+
|
32
|
+
The `faraday` adapter will not raise errors anymore, when used in parallel mode. This fixes the difference in behaviour with the equivalent `typhoeus` parallel adapter, which does not raise errors in such cases as well. This behaviour will exclude 4xx and 5xx HTTP responses, which will not be considered errors in the `faraday` adapter.
|
33
|
+
|
34
|
+
If errors occur in parallel mode, these'll be available in `env[:error]`. Users can check it in two ways:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
response.status == 0
|
38
|
+
# or
|
39
|
+
!response.env[:error].nil?
|
40
|
+
```
|
41
|
+
|
42
|
+
## Bugfixes
|
43
|
+
|
44
|
+
* unix socket: handle the error when the path for the unix sock is invalid, which was causing an endless loop.
|
45
|
+
|
46
|
+
### IPv6 / Happy eyeballs v2
|
47
|
+
|
48
|
+
* the `native` resolver will now use IPv6 nameservers with zone identifier to perform DNS queries. This bug was being ignored prior to ruby 3.1 due to some pre-filtering on the nameservere which were covering misuse of the `uri` dependency for this use case.
|
49
|
+
* Happy Eyeballs v2 handshake error on connection establishment for the first IP will now ignore it, in case an ongoing connecting for the second IP is happening. This fixes a case where both IPv4 and IPv6 addresses are served for a given domain, but only one of them can be connected to (i.e. if connection via IPv6 fails, the IPv4 one should still proceed to completion).
|
50
|
+
* the `native` resolver won't try querying DNS name candidates, if the resolver sends an empty answer with an error code different from "domain not found".
|
51
|
+
* fix error of Happy Eyeballs v2 handshake, where the resulting connection would coalesce with an already open one for the same IP **before** requests were merged to the coalesced connection, resulting in no requests being sent and the client hanging.
|
52
|
+
|
53
|
+
## Chore
|
54
|
+
|
55
|
+
* fixed error message on wrong type of parameter for the `compression_threshold_size` option from the `:compression` plugin.
|
@@ -0,0 +1,6 @@
|
|
1
|
+
# 0.22.4
|
2
|
+
|
3
|
+
## Bugfixes
|
4
|
+
|
5
|
+
* fix happy eyeballs v2 bug where, once the first connection would be established, the remaining one would still end up in the coalescing loop, thereby closing itself via the `:tcp_open` callback.
|
6
|
+
* fix for faraday plugin parallel mode, where it'd hang if no requests would be made in the parallel block (@catlee)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
if defined?(
|
3
|
+
if defined?(DDTrace) && DDTrace::VERSION::STRING >= "1.0.0"
|
4
4
|
require "datadog/tracing/contrib/integration"
|
5
5
|
require "datadog/tracing/contrib/configuration/settings"
|
6
6
|
require "datadog/tracing/contrib/patcher"
|
@@ -169,6 +169,8 @@ module Faraday
|
|
169
169
|
end
|
170
170
|
|
171
171
|
def run
|
172
|
+
return unless @handlers.last
|
173
|
+
|
172
174
|
env = @handlers.last.env
|
173
175
|
|
174
176
|
session = HTTPX.session.with(options_from_env(env))
|
@@ -210,9 +212,13 @@ module Faraday
|
|
210
212
|
if parallel?(env)
|
211
213
|
handler = env[:parallel_manager].enqueue(env)
|
212
214
|
handler.on_response do |response|
|
213
|
-
response.
|
214
|
-
|
215
|
-
|
215
|
+
if response.is_a?(::HTTPX::Response)
|
216
|
+
save_response(env, response.status, response.body.to_s, response.headers, response.reason) do |response_headers|
|
217
|
+
response_headers.merge!(response.headers)
|
218
|
+
end
|
219
|
+
else
|
220
|
+
env[:error] = response.error
|
221
|
+
save_response(env, 0, "", {}, nil)
|
216
222
|
end
|
217
223
|
end
|
218
224
|
return handler
|
@@ -229,6 +235,7 @@ module Faraday
|
|
229
235
|
request.response_on_data = env.request.on_data if env.request.stream_response?
|
230
236
|
|
231
237
|
response = session.request(request)
|
238
|
+
# do not call #raise_for_status for HTTP 4xx or 5xx, as faraday has a middleware for that.
|
232
239
|
response.raise_for_status unless response.is_a?(::HTTPX::Response)
|
233
240
|
save_response(env, response.status, response.body.to_s, response.headers, response.reason) do |response_headers|
|
234
241
|
response_headers.merge!(response.headers)
|
@@ -242,7 +249,8 @@ module Faraday
|
|
242
249
|
Errno::EHOSTUNREACH,
|
243
250
|
Errno::EINVAL,
|
244
251
|
Errno::ENETUNREACH,
|
245
|
-
Errno::EPIPE
|
252
|
+
Errno::EPIPE,
|
253
|
+
::HTTPX::ConnectionError => e
|
246
254
|
raise CONNECTION_FAILED_ERROR, e
|
247
255
|
end
|
248
256
|
|