3.7 KiB
0.21.0
Features
:write_timeout
, :read_timeout
and :request_timeout
https://gitlab.com/honeyryderchuck/httpx/-/wikis/Timeouts
The following timeouts are now supported:
:write_timeout
: total time (in seconds) to write a request to the server;:read_timeout
: total time (in seconds) to read a response from the server;:request_timeout
: tracks both of the above (time to write the request and read a response);
HTTPX.with(timeout: { request_timeout: 60}).get(...
Just like :connect_timeout
, the new timeouts are deadline-oriented, rather than op-oriented, meaning that they do not reset on each socket operation (as most ruby HTTP clients do).
None of them has a default value, in order not to break integrations, but that'll change in a future v1, where they'll become the default timeouts.
Circuit Breaker plugin
https://gitlab.com/honeyryderchuck/httpx/-/wikis/Circuit-Breaker
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
).
Read the wiki for more info about the defaults.
http = HTTPX.plugin(:circuit_breaker)
# that's it!
http.get(...
WebDAV plugin
https://gitlab.com/honeyryderchuck/httpx/-/wikis/WebDav
The :webdav
introduces some "convenience" methods to perform common WebDAV operations.
webdav = HTTPX.plugin(:webdav, origin: "http://webdav-server")
.plugin(:digest_authentication).digest_auth("user", "pass")
res = webdav.put("/file.html", body: "this is the file body")
res = webdav.copy("/file.html", "/newdir/copy.html")
# ...
XML transcoder, :xml
option and response.xml
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:
response = HTTPX.post("https://xml-server.com", xml: Nokogiri::XML("<xml ..."))
response.xml #=> #(Document:0x16e4 { name = "document", children = ...
Improvements
:proxy
plugin: :no_proxy
option
Support was added, in the :proxy
plugin, to declare domains, either via regexp patterns, or strings, for which requests should bypass the proxy.
http = HTTPX.plugin(:proxy).with_proxy(
uri: "http://10.10.0.1:51432",
no_proxy: ["gitlab.local", /*.google.com/]
)
http.get("https://duckduckgo.com/?q=httpx") #=> proxied
http.get("https://google.com/?q=httpx") #=> not proxied
http.get("https://gitlab.com") #=> proxied
http.get("https://gitlab.local") #=> not proxied
OOTB support for other JSON libraries
If one of multi_json
, oj
or yajl
is available, all httpx
operations doing JSON parsing or dumping will use it (the json
standard library will be used otherwise).
require "oj"
require "httpx"
response = HTTPX.post("https://somedomain.json", json: { "foo" => "bar" }) # will use "oj"
puts response.json # will use "oj"
Bugfixes
:expect
plugin::expect_timeout
can accept floats (not just integers).
Chore
- DoH
:https
resolver: support was removed for the "application/dns-json" mime-type (it was only supported in practice by the Google DoH resolver, which has since added support for the standardized "application/dns-message").