httpx 0.8.1 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 473b3b919edef3fda28912548afc872fd45603dd805757bb19c58eb9d1fbf393
4
- data.tar.gz: 554c4b0ebff6f6f9293230c940f9096dc4bfe7361a3f0ba0d6217e2d75bd13e8
3
+ metadata.gz: 44d4a0720ab5167dbff45524a71c6950d271a82532e09ce3b3e01f0d348b3e55
4
+ data.tar.gz: 02cc85986aeb4290c62977b2388567990cf023fa1675d559fc8fbb597db2c434
5
5
  SHA512:
6
- metadata.gz: 9b393a0f4943af7fe478c45b9628f7a07bcfdaf3c59e743f893d21b76bee77100367851027ab597a39113f7c48d747eb2e994c0528a8697403ee8a3d8f6a9725
7
- data.tar.gz: 6c3744eb31f1beba7f98a016c175d6b8d886093ad86eaa8920f3147b9df4d348c006f42689496bd93d67c304d44f5e7d2e1d47f71acc30fed9842fe263bb5886
6
+ metadata.gz: 661fc0f5198c045779823ef3c256fad4cb19a84ac44c0e99eee2bb842809ad6cc4558b5ec2bb1b827a44b0c960daa07759d1b21466312527efe5bde1420af391
7
+ data.tar.gz: fe40c074d0ff47ca8dc7781272c836423c0f254b0b70c4a08f35b1d25d00ba58ba7906fb49d0848e5624f5cf91b6a94cdb3abb9a08ffdc459fa9c7cb81be802f
data/README.md CHANGED
@@ -10,19 +10,21 @@ Among its features, it supports:
10
10
 
11
11
  * HTTP/2 and HTTP/1.x protocol versions
12
12
  * Concurrent requests by default
13
- * Simple and chainable API (based on HTTP.rb, itself based on Python Requests)
13
+ * Simple and chainable API
14
14
  * Proxy Support (HTTP(S), Socks4/4a/5)
15
15
  * Simple Timeout System
16
- * Lightweight (explicit feature loading)
16
+ * Lightweight by default (require what you need)
17
17
 
18
- And among others
18
+ And also:
19
19
 
20
20
  * Compression (gzip, deflate, brotli)
21
21
  * Authentication (Basic Auth, Digest Auth)
22
+ * Expect 100-continue
23
+ * Multipart Requests
22
24
  * Cookies
23
25
  * HTTP/2 Server Push
24
26
  * H2C Upgrade
25
- * Redirect following
27
+ * Automatic follow redirects
26
28
 
27
29
  ## How
28
30
 
@@ -0,0 +1,7 @@
1
+ # Genesis Release
2
+
3
+ This is the first release of `httpx`.
4
+
5
+ It accomplishes all the API and feature goals necessary to its first use, which is testing server implementations.
6
+
7
+ From here on, the sky is the limit.
@@ -0,0 +1,9 @@
1
+ # 0.0.2
2
+
3
+ * Hot-Fixed a flaw from the first version which was breaking https calls (SNI was broken).
4
+
5
+ * Added a few test hackernews scraping scripts, which will be used for trouble-shooting/benchmarking.
6
+
7
+ * Refactored/Fixed closing connections (HTTP/2 connections were buffering but not sending the GOAWAY frame)
8
+
9
+
@@ -0,0 +1,9 @@
1
+ # 0.0.3
2
+
3
+ * Added `HTTPX::Response#raise_for_status`. If there was an error response, it will raise it's exception. If the HTTP response has a 4xx or 5xx error, it will raise an `HTTPX::HTTPError` exception (this feature was inspired by a similar feature in python requests library).
4
+
5
+ * Added `HTTPX::Client#wrap`, which allows to use the client inside a block and keep connections open, without resorting to the initializer only.
6
+
7
+ * TCP connection establishment errors are now wrapped in error responses, like other possible errors.
8
+
9
+ * SSL non-blocking connection API is now in use (it was previously using the blocking connect API, and was breaking the hackernews script from time to time. Now I'm looking at you, DNS).
@@ -0,0 +1,7 @@
1
+ # 0.0.4
2
+
3
+ * Added ANSI coloring to the debugging output (when in TTY mode).
4
+
5
+ * `HTTPX::HTTPError` exceptions now carry the full response object, instead of just the status (so the user can inspect the body and headers if it so desires).
6
+
7
+ * Fixed a bug related with HTTP/1 multiple requests on a domain which closed connections not being able to open a new socket to the domain.
@@ -0,0 +1,5 @@
1
+ # 0.0.5
2
+
3
+ * Fixed HTTP/1 pipelining (it's working again).
4
+
5
+ * Fixed multiple requests to the same domain over https (SSL sockets weren't being properly reopened).
@@ -0,0 +1,9 @@
1
+ # 0.1.0
2
+
3
+ * Follow Redirects Plugin: Added `:follow_insecure_redirects` option, which will not follow https-to-http redirects.
4
+
5
+ * Allow optional option `:transport`. TCP sockets are the default tranport, but by passing `:unix`, one can also define it as a UNIX socket.
6
+
7
+ * Added Retries Plugin, which will retry a request a certain amount of times, provided that the request is safe.
8
+
9
+ * Proxy Plugin: allow multiple proxies to be passed. The client will perform requests on the first proxy successfully connected.
@@ -0,0 +1,5 @@
1
+ # 0.2.0
2
+
3
+ * Custom Resolvers: Non-blocking DNS Resolver, DNS-over-HTTPS Resolver
4
+
5
+ * HTTP/2 connection coalescing
@@ -0,0 +1,16 @@
1
+ # 0.2.1
2
+
3
+ * fixed setting timeouts using the chainable API
4
+
5
+ * Basic Auth: proper user/password escaping
6
+
7
+ * Improved multi-request support, by allowing to pass request-specific options for multiple requests
8
+
9
+ ```ruby
10
+ tokens = ["TOKEN1", "TOKEN2", "TOKEN3"]
11
+ uri = "https://example.com/protected"
12
+
13
+ requests = tokens.map { |token| [uri, {headers: {'authorization': token} }] }
14
+
15
+ responses = HTTPX.get(*requests)
16
+ ```
@@ -0,0 +1,12 @@
1
+ # 0.3.0
2
+
3
+ * removed `http_parser.rb`, which is unmaintained, builds an old version of node's parser, and doesn't work on JRuby 9.2; also, better support over HTTP/1 features.
4
+
5
+ * Alt-Svc support (all remaining origin requests will be routed there); Supports both `Alt-Svc` header and the `altsvc` HTTP/2 frame.
6
+
7
+ * moved multipart requests support to a separate plugin, which removed `http_form_data` as a hard dependency (you'll still need it for the plugin though).
8
+
9
+ * new `HTTP.wrap { |client| }` method.
10
+
11
+ * We have a cheatsheet! 
12
+
@@ -0,0 +1,6 @@
1
+ # 0.3.1
2
+
3
+ * improved DNS resolution error handling (decoding/encoding errors, system resolver)
4
+
5
+ * hotfix: Native/HTTPS resolver not retrying same record type after cache expired, effectively not working after some time for long-running processes
6
+
@@ -0,0 +1,51 @@
1
+ # 0.4.0
2
+
3
+ * Feature: SSH proxy plugin -> send requests over ssh gateway;
4
+
5
+ ```ruby
6
+ HTTPX.plugin(:"proxy/ssh").
7
+ with_proxy(uri: "ssh://localhost:2222",
8
+ username: "root",
9
+ auth_methods: %w[publickey],
10
+ host_key: "ssh-rsa",
11
+ keys: %w[test/support/ssh/ssh_host_ed25519_key]).get(URI)
12
+ ```
13
+
14
+ * Feature: Faraday Adapter
15
+
16
+ * refactoring: cookies plugin API simplification (this is a breaking change!):
17
+
18
+ ```ruby
19
+ session = HTTPX.plugin(:cookies)
20
+ session.with_cookies("a" => "b").get(...
21
+ session.cookies #=> session current cookie store, persists/updates session cookies as requests are processed
22
+ session.wrap do |session|
23
+ session.get(..) #=> "Set-Cookie"
24
+ ...
25
+ end #=> after this, cookie store resets to the state previous to wrap
26
+ ```
27
+
28
+ Removed `Session#cookie_store`
29
+
30
+ ```ruby
31
+ client = HTTPX.plugin(:cookies)
32
+ redirect_response = client.get(URI) #=> ... 302 ... Set-Cookie: "blablalba" ...
33
+ # this sets the cookies
34
+ # GET .... Cookie: "blablabla" ....
35
+ response = client.get(URI) #=> ... 200 ...
36
+ # also, setting cookies:
37
+
38
+ client.cookies("a" => "b").get(URI) # ... Cookie: "a=b" ...
39
+
40
+ #also seamlessly integrates with redirect follows
41
+ client = HTTPX.plugins(:follow_redirects, :cookies)
42
+ response = client.get(URI) #=> ... 200 ...
43
+ ```
44
+
45
+ * refactoring: connection pool now thread-local, improves thread-safety;
46
+
47
+ * bugfix: leaking dns query when passing IO object as option;
48
+
49
+ * bugfix: now multiple different resolvers are supported;
50
+
51
+ * support: JRuby is again supported (as usual, only latest stable is guaranteed)
@@ -0,0 +1,3 @@
1
+ # 0.4.1
2
+
3
+ This was a fix release for some issues around exceptions on requests, and to make the faraday adapter work well with ssl.
@@ -0,0 +1,15 @@
1
+ # 0.5.0
2
+
3
+ This release is a minor bump only because it introduces a new dependency:
4
+
5
+ ## the `timers` gem
6
+
7
+ We've introduced the [`timers` gem](https://github.com/socketry/timers) as a dependency to deal with total timeouts, thereby making the timeout object only a container of values to be refactored. This was in itself a small gain for such a big addition, but other future time-based features can be best built upon it than the existing work.
8
+
9
+
10
+ ## Bugfixes
11
+
12
+ * the altsvc header wasn't properly parsed, and was breaking requests to google. Don't break requests to google!
13
+ * Added support for faraday 0.16;
14
+ * Made the IO selector less flaky;
15
+ * Fixed the homepage, which was being displayed without styles;
@@ -0,0 +1,14 @@
1
+ # 0.5.1
2
+
3
+ ## Improvements
4
+
5
+ * Fixed flakiness of test suite introduced in the 0.4 versions;
6
+ * compression plugin:
7
+ * do not send `accept-encoding` header when `range` is present;
8
+ * Remove from `content-encoding` if body stream decodes it;
9
+ * Added `HTTPX::Response::Body#encodings` to return the decoded encoding(s);
10
+
11
+ ## Bugfixes
12
+
13
+ * non-UTF-8 bodies weren't being properly handled, which led to a loop report (`slice` -> `byteslice`);
14
+ * connection reuse now also happens for requests with body (it was only working with `GET`s and other bodyless requests before);
@@ -0,0 +1,5 @@
1
+ # 0.6.0
2
+
3
+ ## Improvements
4
+
5
+ * Switches `http-2` gem with `http-2-next`, a fork with a focus on spec compliance.
@@ -0,0 +1,6 @@
1
+ # 0.6.1
2
+
3
+ ## Bugfixes
4
+
5
+ * If an http2 connection error happened before streams were open, errors weren't propagated, and there was an infinite loop.
6
+ * Bumping `http-2-next`, fixes the flow control issue causing requests to cloudfront to fail.
@@ -0,0 +1,6 @@
1
+ # 0.6.2
2
+
3
+ ## Bugfixes
4
+
5
+ * Remove escaping of request uri;
6
+ * strip header value (if value have newline, for example);
@@ -0,0 +1,13 @@
1
+ # 0.6.3
2
+
3
+ ## Improvements
4
+
5
+ * HTTP/2 `ORIGIN` frame support (https://tools.ietf.org/html/draft-ietf-httpbis-origin-frame-06);
6
+ * Added functional tests for HTTP/2 connection coalescing (and fixed it, as it hasn't been working for a while);
7
+ * Added functional tests for `Alt-Svc` header support;
8
+
9
+ ## Bugfixes
10
+
11
+ * fixing alternative service redirection if `alt-svc` header pointed to the current peer;
12
+ * fixing `alt-svc` support when ruby version does not support ALPN negotation;
13
+
@@ -0,0 +1,21 @@
1
+ # 0.6.4
2
+
3
+ This release takes where the last left off, and makes a concerted effort to improve both the test coverage and the number of features for which there are functional tests.
4
+
5
+ ## Improvements
6
+
7
+ * Running Ruby 2.7 with no warnings;
8
+
9
+ * Test suite now has functional tests for:
10
+ * authentication on proxies (http, socks4a, socks5);
11
+ * DNS-over-HTTPS;
12
+ * connect timeouts (still a bit flaky though);
13
+
14
+ * Improved test coverage of project to 90%;
15
+
16
+ * building website/blog with Jekyll 4;
17
+
18
+ ## Bugfixes
19
+
20
+ * fixed regressions on HTTP, SOCKS4a and SOCKS5 proxy authentication;
21
+ * fixed DNS-over-HTTPS implementation to be compliant with the latest RFC;
@@ -0,0 +1,22 @@
1
+ # 0.6.5
2
+
3
+ This release fixes important bugs, and automates the PKI for the test suite.
4
+
5
+ ## Features
6
+
7
+ * `resolver_options` can now receive a `:cache` flag (default: `true`). This bypasses caching and forces the lookup;
8
+
9
+ ## Improvements
10
+
11
+ * Building the TLS certs necessary for the test suite has been scripted, after the initial certs expired and brought the CI to a halt;
12
+ * All DNS resolvers have a functional test, both for the happy as well as the error case;
13
+ * Added functional tests for HTTP and HTTPS proxy with authentication, making all proxy options now tested with authentication;
14
+
15
+
16
+ ## Bugfixes
17
+
18
+ * native and https DNS resolvers weren't usable after a resolving error;
19
+ * system DNS resolver could halt the system after a dns resolving error;
20
+ * fixed system halt on HTTP proxy authentication error;
21
+
22
+
@@ -0,0 +1,19 @@
1
+ # 0.6.6
2
+
3
+ ## Features
4
+
5
+ * The `retries` plugin receives two new options:
6
+ * `retry_on`: a callable that receives the failed response as an argument; the return value will determine whether there'll be a retried request.
7
+ * `retry_after`: time (in seconds) after which there request will be retried. Can be an integer or a callable that receives the request and returns an integer (one can do exponential back-off like that, for example).
8
+ * Added support for DNS-over-HTTPS GET requests as per the latest spec.
9
+
10
+ ## Improvements
11
+
12
+ * `HTTPX.plugins` got deprecated; basically, it's great until you have to pass options to a plugin, and then it just works (not). The recommended way to load multiple plugins is `HTTPX.plugin(...).plugin(...)`.
13
+
14
+
15
+ ## Bugfixes
16
+
17
+ * fixed a proxy bug where an `Alt-Svc` response header would make the client try to connect. Just like connection coalescing and the ORIGIN frame, it ignores it when going through a proxy.
18
+
19
+
@@ -0,0 +1,5 @@
1
+ # 0.6.7
2
+
3
+ ## Bugfixes
4
+
5
+ * An error was reported when using the follow plugin allowing insecure redirects: if the insecure redirect would be for the same host, and the original request was performed with HTTP/2, the library would try to coalesce the request, and blocks the reactor. A check was made to ensure that connection only coalesces if both are https connections.
@@ -0,0 +1,46 @@
1
+ # 0.7.0
2
+
3
+
4
+ ## Features
5
+
6
+ New option: `:max_requests`. This is a connection-level option signalizing how many requests can be performed on a connection. Although the HTTP/1 parser defined this well, in HTTP/2 this wasn't very clear, so: by definition, the remote MAX_CONCURRENT_STREAMS setting will be used to define it, unless the user explicitly passed the option. You can also pass `:max_requests => Float::INFINITY` if you know that the server allows more requests than that on a connection.
7
+
8
+ New plugin: `:expect`.
9
+
10
+ Although there was support for `expect: 100-continue` header already when passed, this plugin can:
11
+
12
+ * automatically set the header on requests with body;
13
+ * execute the flow;
14
+ * recover from 417 status errors (i.e. try again without it);
15
+ * send body after X seconds if no 100 response came;
16
+
17
+ Suport for `with_` methods for the session. As long as the suffix is a valid attribute, it's just like that:
18
+
19
+ ```ruby
20
+ HTTPX.with_timeout(...).with_ssl(...)
21
+ # same as:
22
+ # HTTPX.with(timeout: ..., ssl: ...)
23
+ ```
24
+
25
+ ## Improvements
26
+
27
+ ### Connections
28
+
29
+ The following improvements make the `persistent` plugin way more resilient:
30
+
31
+ * Better balancing of HTTP/2 connections by distributing requests among X connections depending of how many requests they can process.
32
+ * Exhausted connections can off-load to a new same-origin connection (such as, when the server negotiates less `MAX_CONCURRENT_STREAMS` than what's expected).
33
+
34
+ ### Timeouts
35
+
36
+ (Timeouts will be one of the main improvements from the 0.7.x series)
37
+
38
+ `:total_timeout` is now a connection-level directive, which means that this feature will actually make more sense and account for all requests in a block at the same time, instead of one-by-one.
39
+
40
+ ### Options
41
+
42
+ Option setters were being bypassed, therefore a lot of the type-checks defined there weren't effectively being picked upon, which could have led to weird user errors.
43
+
44
+ ## Bugfixes
45
+
46
+ * fixed the `push_promise` plugin integration (wasn't working well since `http-2-next` was adopted);
@@ -0,0 +1,27 @@
1
+ # 0.8.0
2
+
3
+
4
+ ## Features
5
+
6
+ * `keep_alive_timeout`: for persistent connections, the keep alive timeout will set the connection to be closed if not reused for a request **after** the last received response;
7
+
8
+ ## Improvements
9
+
10
+ * using `max_requests` for HTTP/1 pipelining as well;
11
+ * `retries` plugin now works with plain HTTP responses (not just error responses);
12
+ * reduced the number of string allocations from log labels;
13
+ * performance: a lot of improvements were made to optimize the "waiting for IO events" phase, which dramatically reduced the CPU usage and make the performance of the library more on-par with other ruby HTTP gems for the 1-shot request scenario.
14
+
15
+
16
+ ## Bugfixes
17
+
18
+ * fixed `HTTPX::Response#copy_to`;
19
+ * fixed `compression` plugin not properly compressing request bodies using `gzip`;
20
+ * fixed `compression` plugin not handling `content-encoding: identity` payloads;
21
+ * do not overwrite user-defined `max_requests`on HTTP2 connection handshake;
22
+ * `retries` plugin: connection was blocking when a request with body was retried;
23
+ * `alt-svc: clear` response header was causing the process to hang;
24
+
25
+ ## Tests
26
+
27
+ * Code coverage improved to 91%;
@@ -0,0 +1,8 @@
1
+ # 0.8.1
2
+
3
+
4
+ ## Bugfixes
5
+
6
+ * fixing HTTP/2 handshake IO interests calculation;
7
+ * fixed the double ctrl+f issue when terminating an ongoing HTTP/2 request;
8
+ * fixed connection comparison when passing headers;
@@ -0,0 +1,7 @@
1
+ # 0.8.2
2
+
3
+ ## Features
4
+
5
+ * `:expect` plugin now supports a new option, `:expect_threshold_size`, meaning: the byte size threshold below which no `expect` header will be sent with requests with payload.
6
+ * `:compression` plugin now supports a new option, `:compression_threshold_size`, meaning: the bytesize threshold below which request payload won't be compressed before being sent.
7
+ * for HTTP/2 connections, when `keep_alive_timeout` expires, a `PING` frame is used to check connection availability; if successful, the connection will be reused.
@@ -88,8 +88,6 @@ module HTTPX
88
88
 
89
89
  return false if exhausted?
90
90
 
91
- return false if @keep_alive_timer && @keep_alive_timer.fires_in.negative?
92
-
93
91
  (
94
92
  (
95
93
  @origins.include?(uri.origin) &&
@@ -107,8 +105,6 @@ module HTTPX
107
105
 
108
106
  return false if exhausted?
109
107
 
110
- return false if @keep_alive_timer && @keep_alive_timer.fires_in.negative?
111
-
112
108
  !(@io.addresses & connection.addresses).empty? && @options == connection.options
113
109
  end
114
110
 
@@ -229,8 +225,19 @@ module HTTPX
229
225
  def send(request)
230
226
  if @parser && !@write_buffer.full?
231
227
  request.headers["alt-used"] = @origin.authority if match_altsvcs?(request.uri)
228
+ if @keep_alive_timer
229
+ # when pushing a request into an existing connection, we have to check whether there
230
+ # is the possibility that the connection might have extended the keep alive timeout.
231
+ # for such cases, we want to ping for availability before deciding to shovel requests.
232
+ if @keep_alive_timer.fires_in.negative?
233
+ @pending << request
234
+ parser.ping
235
+ return
236
+ end
237
+
238
+ @keep_alive_timer.pause
239
+ end
232
240
  @inflight += 1
233
- @keep_alive_timer.pause if @keep_alive_timer
234
241
  parser.send(request)
235
242
  else
236
243
  @pending << request
@@ -361,6 +368,8 @@ module HTTPX
361
368
  emit(:altsvc, alt_origin, origin, alt_params)
362
369
  end
363
370
 
371
+ parser.on(:pong, &method(:send_pending))
372
+
364
373
  parser.on(:promise) do |request, stream|
365
374
  request.emit(:promise, parser, stream)
366
375
  end
@@ -469,8 +478,8 @@ module HTTPX
469
478
  else
470
479
  @keep_alive_timer = @timers.after(@keep_alive_timeout) do
471
480
  unless @inflight.zero?
472
- log { "(#{object_id})) keep alive timeout expired, closing..." }
473
- reset
481
+ log { "(#{@origin}): keep alive timeout expired" }
482
+ parser.ping
474
483
  end
475
484
  end
476
485
  end
@@ -78,6 +78,7 @@ module HTTPX
78
78
  break if idx >= requests_limit
79
79
  next if request.state == :done
80
80
 
81
+ request.headers["connection"] ||= request.options.persistent || idx < requests_limit - 1 ? "keep-alive" : "close"
81
82
  handle(request)
82
83
  end
83
84
  end
@@ -170,6 +171,11 @@ module HTTPX
170
171
  end
171
172
  end
172
173
 
174
+ def ping
175
+ emit(:reset)
176
+ emit(:exhausted)
177
+ end
178
+
173
179
  private
174
180
 
175
181
  def manage_connection(response)
@@ -206,7 +212,14 @@ module HTTPX
206
212
  def disable_pipelining
207
213
  return if @requests.empty?
208
214
 
209
- @requests.each { |r| r.transition(:idle) }
215
+ @requests.each do |r|
216
+ r.transition(:idle)
217
+
218
+ # when we disable pipelining, we still want to try keep-alive.
219
+ # only when keep-alive with one request fails, do we fallback to
220
+ # connection: close.
221
+ r.headers["connection"] = "close" if @max_concurrent_requests == 1
222
+ end
210
223
  # server doesn't handle pipelining, and probably
211
224
  # doesn't support keep-alive. Fallback to send only
212
225
  # 1 keep alive request.
@@ -216,7 +229,7 @@ module HTTPX
216
229
 
217
230
  def set_request_headers(request)
218
231
  request.headers["host"] ||= request.authority
219
- request.headers["connection"] ||= "keep-alive"
232
+ request.headers["connection"] ||= request.options.persistent ? "keep-alive" : "close"
220
233
  if !request.headers.key?("content-length") &&
221
234
  request.body.bytesize == Float::INFINITY
222
235
  request.chunk!
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "securerandom"
3
4
  require "io/wait"
4
5
  require "http/2/next"
5
6
 
@@ -25,6 +26,7 @@ module HTTPX
25
26
  @pending = []
26
27
  @streams = {}
27
28
  @drains = {}
29
+ @pings = []
28
30
  @buffer = buffer
29
31
  @handshake_completed = false
30
32
  init_connection
@@ -53,8 +55,8 @@ module HTTPX
53
55
  init_connection
54
56
  end
55
57
 
56
- def close
57
- @connection.goaway unless @connection.state == :closed
58
+ def close(*args)
59
+ @connection.goaway(*args) unless @connection.state == :closed
58
60
  emit(:close)
59
61
  end
60
62
 
@@ -109,6 +111,13 @@ module HTTPX
109
111
  end
110
112
  end
111
113
 
114
+ def ping
115
+ ping = SecureRandom.gen_random(8)
116
+ @connection.ping(ping)
117
+ ensure
118
+ @pings << ping
119
+ end
120
+
112
121
  private
113
122
 
114
123
  def send_pending
@@ -143,6 +152,7 @@ module HTTPX
143
152
  @connection.on(:promise, &method(:on_promise))
144
153
  @connection.on(:altsvc) { |frame| on_altsvc(frame[:origin], frame) }
145
154
  @connection.on(:settings_ack, &method(:on_settings))
155
+ @connection.on(:ack, &method(:on_pong))
146
156
  @connection.on(:goaway, &method(:on_close))
147
157
  #
148
158
  # Some servers initiate HTTP/2 negotiation right away, some don't.
@@ -306,6 +316,14 @@ module HTTPX
306
316
  emit(:origin, origin)
307
317
  end
308
318
 
319
+ def on_pong(ping)
320
+ if !@pings.delete(ping)
321
+ close(:protocol_error, "ping payload did not match")
322
+ else
323
+ emit(:pong)
324
+ end
325
+ end
326
+
309
327
  def respond_to_missing?(meth, *args)
310
328
  @connection.respond_to?(meth, *args) || super
311
329
  end
@@ -14,13 +14,23 @@ module HTTPX
14
14
  #
15
15
  module Compression
16
16
  extend Registry
17
- def self.load_dependencies(klass)
18
- klass.plugin(:"compression/gzip")
19
- klass.plugin(:"compression/deflate")
20
- end
21
17
 
22
- def self.extra_options(options)
23
- options.merge(headers: { "accept-encoding" => Compression.registry.keys })
18
+ class << self
19
+ def load_dependencies(klass)
20
+ klass.plugin(:"compression/gzip")
21
+ klass.plugin(:"compression/deflate")
22
+ end
23
+
24
+ def extra_options(options)
25
+ Class.new(options.class) do
26
+ def_option(:compression_threshold_size) do |bytes|
27
+ bytes = Integer(bytes)
28
+ raise Error, ":expect_threshold_size must be positive" unless bytes.positive?
29
+
30
+ bytes
31
+ end
32
+ end.new(options).merge(headers: { "accept-encoding" => Compression.registry.keys })
33
+ end
24
34
  end
25
35
 
26
36
  module RequestMethods
@@ -32,10 +42,16 @@ module HTTPX
32
42
  end
33
43
 
34
44
  module RequestBodyMethods
35
- def initialize(*)
45
+ def initialize(*, options)
36
46
  super
37
47
  return if @body.nil?
38
48
 
49
+ if (threshold = options.compression_threshold_size)
50
+ unless unbounded_body?
51
+ return if @body.bytesize < threshold
52
+ end
53
+ end
54
+
39
55
  @headers.get("content-encoding").each do |encoding|
40
56
  next if encoding == "identity"
41
57
 
@@ -18,14 +18,27 @@ module HTTPX
18
18
 
19
19
  seconds
20
20
  end
21
+
22
+ def_option(:expect_threshold_size) do |bytes|
23
+ bytes = Integer(bytes)
24
+ raise Error, ":expect_threshold_size must be positive" unless bytes.positive?
25
+
26
+ bytes
27
+ end
21
28
  end.new(options).merge(expect_timeout: EXPECT_TIMEOUT)
22
29
  end
23
30
 
24
31
  module RequestBodyMethods
25
- def initialize(*)
32
+ def initialize(*, options)
26
33
  super
27
34
  return if @body.nil?
28
35
 
36
+ if (threshold = options.expect_threshold_size)
37
+ unless unbounded_body?
38
+ return if @body.bytesize < threshold
39
+ end
40
+ end
41
+
29
42
  @headers["expect"] = "100-continue"
30
43
  end
31
44
  end
@@ -1,19 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "resolv"
4
+ require "httpx/resolver/resolver_mixin"
5
+ require "httpx/resolver/system"
6
+ require "httpx/resolver/native"
7
+ require "httpx/resolver/https"
4
8
 
5
9
  module HTTPX
6
10
  module Resolver
7
- autoload :ResolverMixin, "httpx/resolver/resolver_mixin"
8
- autoload :System, "httpx/resolver/system"
9
- autoload :Native, "httpx/resolver/native"
10
- autoload :HTTPS, "httpx/resolver/https"
11
-
12
11
  extend Registry
13
12
 
14
- register :system, :System
15
- register :native, :Native
16
- register :https, :HTTPS
13
+ register :system, System
14
+ register :native, Native
15
+ register :https, HTTPS
17
16
 
18
17
  @lookup_mutex = Mutex.new
19
18
  @lookups = Hash.new { |h, k| h[k] = [] }
@@ -197,7 +197,7 @@ module HTTPX
197
197
 
198
198
  def build_request(verb, uri, options)
199
199
  rklass = @options.request_class
200
- request = rklass.new(verb, uri, @options.merge(options))
200
+ request = rklass.new(verb, uri, @options.merge(options).merge(persistent: @persistent))
201
201
  request.on(:response, &method(:on_response).curry[request])
202
202
  request.on(:promise, &method(:on_promise))
203
203
  request
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HTTPX
4
- VERSION = "0.8.1"
4
+ VERSION = "0.8.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: httpx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tiago Cardoso
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-23 00:00:00.000000000 Z
11
+ date: 2020-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http-2-next
@@ -77,10 +77,64 @@ email:
77
77
  - cardoso_tiago@hotmail.com
78
78
  executables: []
79
79
  extensions: []
80
- extra_rdoc_files: []
80
+ extra_rdoc_files:
81
+ - LICENSE.txt
82
+ - README.md
83
+ - doc/release_notes/0_0_1.md
84
+ - doc/release_notes/0_1_0.md
85
+ - doc/release_notes/0_0_5.md
86
+ - doc/release_notes/0_0_4.md
87
+ - doc/release_notes/0_6_5.md
88
+ - doc/release_notes/0_6_1.md
89
+ - doc/release_notes/0_7_0.md
90
+ - doc/release_notes/0_6_0.md
91
+ - doc/release_notes/0_8_2.md
92
+ - doc/release_notes/0_6_4.md
93
+ - doc/release_notes/0_6_3.md
94
+ - doc/release_notes/0_8_1.md
95
+ - doc/release_notes/0_5_0.md
96
+ - doc/release_notes/0_6_7.md
97
+ - doc/release_notes/0_4_1.md
98
+ - doc/release_notes/0_5_1.md
99
+ - doc/release_notes/0_6_6.md
100
+ - doc/release_notes/0_4_0.md
101
+ - doc/release_notes/0_6_2.md
102
+ - doc/release_notes/0_8_0.md
103
+ - doc/release_notes/0_3_0.md
104
+ - doc/release_notes/0_2_1.md
105
+ - doc/release_notes/0_0_3.md
106
+ - doc/release_notes/0_0_2.md
107
+ - doc/release_notes/0_3_1.md
108
+ - doc/release_notes/0_2_0.md
81
109
  files:
82
110
  - LICENSE.txt
83
111
  - README.md
112
+ - doc/release_notes/0_0_1.md
113
+ - doc/release_notes/0_0_2.md
114
+ - doc/release_notes/0_0_3.md
115
+ - doc/release_notes/0_0_4.md
116
+ - doc/release_notes/0_0_5.md
117
+ - doc/release_notes/0_1_0.md
118
+ - doc/release_notes/0_2_0.md
119
+ - doc/release_notes/0_2_1.md
120
+ - doc/release_notes/0_3_0.md
121
+ - doc/release_notes/0_3_1.md
122
+ - doc/release_notes/0_4_0.md
123
+ - doc/release_notes/0_4_1.md
124
+ - doc/release_notes/0_5_0.md
125
+ - doc/release_notes/0_5_1.md
126
+ - doc/release_notes/0_6_0.md
127
+ - doc/release_notes/0_6_1.md
128
+ - doc/release_notes/0_6_2.md
129
+ - doc/release_notes/0_6_3.md
130
+ - doc/release_notes/0_6_4.md
131
+ - doc/release_notes/0_6_5.md
132
+ - doc/release_notes/0_6_6.md
133
+ - doc/release_notes/0_6_7.md
134
+ - doc/release_notes/0_7_0.md
135
+ - doc/release_notes/0_8_0.md
136
+ - doc/release_notes/0_8_1.md
137
+ - doc/release_notes/0_8_2.md
84
138
  - lib/httpx.rb
85
139
  - lib/httpx/adapters/faraday.rb
86
140
  - lib/httpx/altsvc.rb