148 Commits

Author SHA1 Message Date
HoneyryderChuck
17a26be1a9 added #bearer_auth helper in authentication pluginn 2023-07-02 22:23:07 +01:00
HoneyryderChuck
ee6c5b231f fix for multi-hostname resolution with aliases failing
context of the multiple alias hops was cleaned up from the context,
which broke next query access.
2023-06-29 17:48:59 +01:00
HoneyryderChuck
0555132740 integrate mutex_m in signatures 2023-06-12 20:42:57 +01:00
HoneyryderChuck
eb0291ed87 :circuit_breaker plugin: added support for .on_circuit_open callback
called when a circuit is open.

```ruby
HTTPX.plugin(:circuit_breaker).on_circuit_open do |req|
  # ... do smth
end
2023-06-12 20:42:57 +01:00
HoneyryderChuck
1475f9a2ec fix for happy eyeballs with early-resolved IPs
for instance, in multi-homed networks, ´/etc/hosts` will have both
    "127.0.0.1" and "::1" pointing from localhost; still only one of
    them may be reachable, if a server binds only to "127.0.0.1", for
    exammple. In such cases, the early exit placed to prevent the loop
    from b0777c61e was preventing the dual-stack IP resolve to pass the
    second set of responses, thereby potentiallly making only the
    unreachable IP accessible to the connection.
2023-06-12 20:10:27 +01:00
HoneyryderChuck
46ce583de3 fix Response::Body#read which rewinds on every call
As per the ruby IO reader protocol, which Response::Body was aimed at
suppoorting since the beginning, the call to #rewind was impeding it
from consuming the body buffer, and instead delivering the same
substring everytime.
2023-06-08 23:47:32 +01:00
HoneyryderChuck
0f988e3e9f adding session lifecycle callbacks 2023-05-31 20:06:59 +01:00
HoneyryderChuck
5655c602c7 the oauth plugin 2023-05-25 16:45:25 +01:00
HoneyryderChuck
cfac38dc62 added more typing, improved correctness of a few checks 2023-04-28 23:57:25 +01:00
HoneyryderChuck
bbf257477b Removing HTTPX::Registry and its usage internally
These internnal registries were a bit magical to use, difficult to
debug, not thread-safe, and overall a nuisance when it came to type
checking. So long.
2023-04-27 22:49:20 +01:00
HoneyryderChuck
387798fc1a refining soomme signatures 2023-04-26 23:05:45 +01:00
HoneyryderChuck
55d9139a59 native resolver: clean up candidate queries
dns resolution puts candidate queries in the pipeline, in case the first
one misses, but it wasn't cleaning them up in all situations.
2023-04-25 22:46:54 +01:00
HoneyryderChuck
d699526ec2 updated signatures of IO objects 2023-04-25 22:46:54 +01:00
HoneyryderChuck
6aacc9b0eb native resolver falls back to tcp dns when receiving truncated packet
yet another compliance fix for the DNS protocol; while udp is the
preferred transport, in case a truncated response is received, the
resolver will switch to tcp, and performm the DNS query again.

This introduces a new resolver option, `:socket_type`, which is `:udp`
by default.
2023-04-25 22:46:54 +01:00
HoneyryderChuck
a3add3c721 Merge branch 'fix-no-proxy' into 'master'
fix proxy discovery using proxy env vars

See merge request os85/httpx!242
2023-04-24 10:35:47 +00:00
HoneyryderChuck
9e355bc3d6 added improved type signatures to retries module 2023-04-18 01:08:39 +03:00
HoneyryderChuck
8105e1128e introduce :buffer_size option
this allows to tweak connection buffer sizes, which may help optimizing
memory usage, and in this case, test the resumable retries.

wip
2023-04-17 18:09:24 +03:00
HoneyryderChuck
312e8e83d3 store potentially existing partial response in ErrorResponse, whenever it gets instantiated 2023-04-17 17:19:41 +03:00
HoneyryderChuck
092e594a4b Request.verb is now an upcased string (ex: "GET")
The reference for a request verb is now the string which is used
everywhere else, instead of the symbol corresponding to it. This was an
artifact from the import from httprb, and there is no advantage in it,
since these strings are frozen in most use cases, and the
transformations from symbol to strings being performed everywhere are
prooof that keeping the atom isn't really bringing any benefit.
2023-04-17 16:54:31 +03:00
HoneyryderChuck
cbd695fb9c fix proxy discovery using proxy env vars
connections weren't being correctly initiated, as proxies were filtered
for the whole session based on URI.find_proxy for the first call. This
fixes it by:

* applying it to all used uris;
* falling back to proxy options instead;
* apply no_proxy option in case it's used, using
  `URI::Generic.use_proxy?
2023-03-30 22:08:32 +01:00
HoneyryderChuck
a218463c73 Merge branch 'fix-for-dns-candidate-queries' into 'master'
fix: native resolver only tries candidate names when server indicates

See merge request os85/httpx!236
2023-01-21 17:11:26 +00:00
HoneyryderChuck
af261006a3 fix: native resolver only tries candidate names when server indicates
domain not found

since httpx supports candidate calculations for dns queries, candidates
were always traversed when no answers were back. However, the DNS
message response contains a code set by the server, indicating whether
we should consider the domain existing **but** has no adderss, and
unexisting; candidates should only be queried in the latter.
2023-01-21 16:52:25 +00:00
HoneyryderChuck
a5101870a5 fix for Happy Eyeballs v2 on failed connection
Implemementing the following fixes:

* connections are now marked by IP family of the IO;
* connection "mergeable" status dependent on matching origin when conn
  is already open;
* on a connection error, in case it happened while connection, an event
  is emitted, rather than handling it; if there is another connection
  for the same origin still doing the handshake, the error is ignored;
  if not, the error is handled;
* a new event, `:tcp_open`, is emitted when the tcp socket conn is
  established; this allows for concurrent handshakes to be promptly
  terminated, instead of being dependent on TLS handshake;
* connection cloning now happens early, as connection is set for
  resolving; this way, 2-way callbacks are set as early as possible;
2023-01-21 00:51:03 +00:00
HoneyryderChuck
db939b56d2 Adding HTTPX::Response::Body#filename
This returns the filename advertised in the content-disposition header.
It reuses the same logic which existed for parsing multipart responses,
which itself was based on `rack`'s.
2022-12-29 01:09:14 +00:00
HoneyryderChuck
c9527f962d finishing Happy Eyeballs v2
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.

With this change, httpx will now continue the process by connecting
concurrently to both IPv6 and IPv4, and close the other connection once
one is established. This means both TCP and TLS (when applicable) need
to succeed before the second connection is cancelled.
2022-12-21 01:04:05 +00:00
HoneyryderChuck
325f7141c8 promoting HTTPX::Response::Body#encoding to public API 2022-12-21 00:46:14 +00:00
HoneyryderChuck
535a30db25 fixing issues around typing 2022-08-13 16:34:02 +01:00
HoneyryderChuck
8f8febc10e sig fixes 2022-08-08 22:19:20 +01:00
HoneyryderChuck
c31ded54e1 circuit breaker plugin 2022-08-07 22:24:57 +01:00
HoneyryderChuck
71cb66e287 added missing options sig 2022-08-07 14:43:29 +01:00
HoneyryderChuck
3f9c165d51 added request_timeout 2022-08-06 23:20:21 +01:00
HoneyryderChuck
452657c805 Added the read_timeout and write_timeout timeouts
These are deadline oriented for the request and response, i.e. a write
timeout tracks the full time it takes to write the request, whereas the
read timeout does the same for receiving the response.

For back-compat, they're infinite by default. v1 may change that, and
will have to provide a safe fallback for endless "stream" requests and
responses.
2022-08-06 22:30:46 +01:00
HoneyryderChuck
25b949cf66 Added support for multiple JSON parsers
When available, httpx will either use `multi_json`, `oj`, or `yajl`,
before it falls back to default `json`.
2022-08-05 22:57:06 +01:00
HoneyryderChuck
43016795f3 introducing the :no_proxy option
can be passed in the `:proxy` option hash, and receives domains, as
strings, which requests should not go through the proxy.
2022-08-05 22:37:52 +01:00
HoneyryderChuck
8359d6b007 Merge branch 'issue-200' into 'master'
response_cache: fixes and improvements

Closes #200

See merge request honeyryderchuck/httpx!216
2022-08-01 17:50:21 +00:00
HoneyryderChuck
61c36c4ef9 response cache: caching several instances for the same URL
by relying on vary header, this should have the effect of not
overflowinng, and doing what the user wants.
2022-08-01 18:40:21 +01:00
HoneyryderChuck
b0777c61e5 fix for loop on resolution and retry on new connection
A certain behaviour was observed, when performing some tests using the
hackernews script, where after a failed request on a non-initiated
connection, a new DNS resolution would be emitted, although the
connection still had other IPs to try on. This led to a cascading
behaviour where the DNS response would fill up the connection with the
same repeated IPs and trigger coalescing, which would loop indefinitely
after emitting the resolve event.

This was fixed by not allowing DNS resolution on already resolved names,
to propagate to connections which already contain the advertised IPs.

This seems to address the github issue 5, which description matches the
observed behaviour.
2022-07-31 19:07:41 +01:00
HoneyryderChuck
32a81f2025 fix: response cache now also takes verb into account when caching
The previous strategy was working only with URLs. This strategy would
fall flat if the same url could be used with several HTTP verbs.
2022-07-31 17:03:30 +01:00
HoneyryderChuck
6c911768fe fixing selector timeout errors closing all connections and ignoring
resolvers

All kinds of errors happening during the select loop, will be handled as
abrupt select loop errors, and terminate all connections; this also
includes timmeout errors. This is not ideal, for some reasons:
connection timeout errors happening on the loop close all connections,
although it may be only triggered for one (or a subset of) connection
for which the timeout should trigger; second, errors on the DS channel
propagate errors to connections indirectly (the emission mentioned
above), wrongly (connections for different hostnames not yet queried,
will also fail with timeout), and won't clean the resolver state (so
subsequent queries will be done for the same hostname which failed in
the first place).

This fix is a first step to solving this problem. It does not totally
address the first, but i'll fix dealing with errors from the second
use-case.
2022-06-22 02:09:26 +03:00
HoneyryderChuck
ecab7951c9 bugfix for unregistering connections timing out while resolving
A subtle bug slipped through the cracks, where if a resolve timeout
error happened, the connection would remain in the pool. Subsequent
requests to the same domain would activate it, although no requests
would go through it; the actual desired behaviour is to outright remove
it from the pool on such errors.

This was achieved by registering the "unregister_connection" callback
earlier. However, the connection accounting step would only trigger if
taking it out of the selector worked, meaning it had been registered
before.
2022-06-21 02:20:32 +03:00
HoneyryderChuck
675a2aa547 do not allow downgrading from https to http during altsvc handshake 2022-05-23 00:17:49 +01:00
HoneyryderChuck
c86f4be1a7 reworking auth APIs for a future 1.0 refactoring 2022-05-08 17:23:07 +01:00
HoneyryderChuck
be06032649 adding APIs for running other proxy auth schemes, and adapting internals to work with it 2022-05-07 18:20:07 +01:00
HoneyryderChuck
817a10a537 scoping http auth schemes out of its plugins, made them usable in proxy
In order to expose other auth schemes in proxy, the basic, digest and
ntlm modules were extracted from the plugins, these being left with the
request management. So now, an extra parameter, `:scheme`, can be
passed (it'll be "basic" for http and "socks5" for socks5 by default,
can also be "digest" or "ntlm", haven't tested those yet).
2022-05-07 13:57:10 +01:00
HoneyryderChuck
64f8ebcf51 exposing original hostname in errors when there's a dns error in a candidate name for resolution 2022-03-28 12:51:35 +01:00
HoneyryderChuck
53ee7ae225 native resolver: support resolv.conf search and ndots params 2022-03-20 02:25:39 +00:00
HoneyryderChuck
c989a14435 native resolver fix: do not signal interests when there's nothing to do (was generating bursty IO) 2022-03-06 15:40:48 +00:00
HoneyryderChuck
6f7f7933c3 proc no lambda 2022-01-17 00:59:01 +02:00
HoneyryderChuck
037994514b reworked early_resolve to work with dual-stack
for multi-backed resolvers, resolving is attempted before sending it to
    the resolver. in this way, cached, local or ip resolves get
    propagated to the proper resolver by ip family, instead of the
    previous mess.

    the system resolver doesn't do these shenanigans (trust getaddrinfo)
2022-01-17 00:56:09 +02:00
HoneyryderChuck
554957f6ca initial reimplementation of the system resolver, now using getaddrinfo
the ruby `resolver` library does everthing in ruby, and sequentially
(first ipv4 then ipv6 resolution). we already have native for that, and
getaddrinfo should be considered the ideal way to use DNS (potentially
in the future, it becomes the default resolver).
2022-01-16 22:54:56 +02:00