Commit Graph

512 Commits

Author SHA1 Message Date
Martin Algesten
50fd1fe14e Update deps 2023-08-11 09:21:10 +02:00
ToBinio
37b5f4721f into vec<u8> 2023-08-11 09:05:20 +02:00
Harald Hoyer
4a2ecdf123 fix: pass IPv6 addresses as host name in TLS connections
rustls does not like the brackets `[]` in `rustls::ServerName::try_from()`.

Signed-off-by: Harald Hoyer <harald@matterlabs.dev>
2023-06-27 00:26:21 +02:00
Harsh Shandilya
406b41a264 fix(json): bump serde_json dependency and fix failing test 2023-06-17 00:07:12 +02:00
Jacob Hoffman-Andrews
a8c038529f Allow http/1.0 responses to have content-length (#625)
Previously, we treated HTTP/1.0 responses as always being
close-delimited. However, that's not quite right. HTTP/1.0 responses
_default_ to Connection: close, but the server may send Connection:
keep-alive, along with a Content-Length header. Update body_type to
understand this.

Also, slightly reorganize body_type. has_no_body was being checked
redundantly when we could just early-return when has_no_body is true. And
regardless of whether we see Connection: close (on any HTTP version),
we must honor Transfer-Encoding or Content-Length if they are present.

Change the handling of `Connection: close` to more directly affect
whether a connection is pooled, regardless of what method was used
to delimit the body.

Fixes #600
2023-06-14 16:20:00 -07:00
Jacob Hoffman-Andrews
905bf8f0b2 temporarily add no_run to middleware doctests (#626)
These test were failing because they made live requests to httpbin.org,
which is serving intermittent 500s.

In general we strive to make our test and doctests interact with a local
test server rather than a live website. For doctests we do this with
some sleight of hand in a hidden `ureq::is_test(true)`, which swaps out
the default agent returned by ureq::agent. However, since the middleware
doctests rely on constructing a custom agent with the middleware, they
can't rely on this.

I suspect we can get around this problem but it may take some thinking.

Similarly disable the AgentBuilder::user_agent and redirects doctests
and the agent_set_header unittest.
2023-06-13 23:00:26 -07:00
Alec Moskvin
fbae1391ac Fix cookie leak on redirect (#608)
This removes the cookie header on redirect, otherwise if there are
multiple redirects, a new cookie header gets appended each time, while
the existing one remains. This could result in the cookies being leaked
to a third party.
2023-06-13 21:17:50 -07:00
Devrim Şahin
d2a1d30b20 fix clippy finding 2023-05-12 20:13:14 +02:00
Devrim Şahin
cd70959360 remove the Option from local_addr, replace unwrap() 2023-05-12 20:13:14 +02:00
Devrim Şahin
c305b915f8 fix flaky test(s) 2023-05-12 20:13:14 +02:00
Devrim Şahin
11a8eb470c make local_addr syscall unconditional 2023-05-12 20:13:14 +02:00
Martin Algesten
7e32dbaaaf Read local_addr from socket 2023-05-12 20:13:14 +02:00
Devrim Şahin
bfb0ef16e1 expose local_addr() from Response 2023-05-12 20:13:14 +02:00
stelofan
ec663fad45 fix cannot use http_proxy connect non-standard http ports 2023-04-16 09:19:27 +02:00
Jacob Hoffman-Andrews
ad1ff0c37f http_interop: fix tests (#606) 2023-03-30 21:02:53 -07:00
Lukas Wagner
20a9ae7977 Proxy: Only use HTTP CONNECT for HTTPS requests
Previously, `ureq` used `HTTP CONNECT` for *all* requests, including
plain-text HTTP requests. However, some proxy servers like Squid
only allow tunneling via the `HTTP CONNECT` method on port 443 - since
it is usually only used to proxy HTTPS requests. As a result,
it was not possible to use `ureq` with a Squid server in its default configuration.

With the changes from this commit, ureq will interact with HTTP proxies
in a more standard-conforming way, where `CONNECT` is only used for
HTTPS requests. HTTP request paths are transformed in such a way that they
comply with RFC 7230 [1].

Tested against Squid 4.13 in standard configuration, with and without basic authentication,
for HTTP and HTTPS requests.

[1] https://www.rfc-editor.org/rfc/rfc7230#section-5.3.2
2023-03-16 11:59:23 +01:00
Kade Robertson
bdcee72c53 docs: update README with http-interop feature 2023-03-15 03:54:13 +01:00
Kade Robertson
f4314e53ac docs: cover usage + doctests 2023-03-15 03:54:13 +01:00
Kade Robertson
6385b72d31 test: additional basic coverage for conversions 2023-03-15 03:54:13 +01:00
Kade Robertson
06db500ec4 refactor: keep http-related code together 2023-03-15 03:54:13 +01:00
Kade Robertson
7dcd60cbaf refactor: rename feature to http-interop 2023-03-15 03:54:13 +01:00
Kade Robertson
dff55fda4e feat: bidirectional http request conversion 2023-03-15 03:54:13 +01:00
Kade Robertson
f395a726e3 feat: bidrectional http response conversion 2023-03-15 03:54:13 +01:00
SwayStar123
efdd55421f Update request.rs 2023-03-13 16:35:36 +01:00
Fabian Grünbichler
2b86691a81 proxy: set proper user agent
instead of hard-coding "something/1.0.0".

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2023-03-13 16:28:57 +01:00
Martin Algesten
b66e558027 Fix clippy 2023-03-13 16:27:38 +01:00
Martin Algesten
05b9a82a38 Clippy fix 2023-01-31 08:52:47 +01:00
Martin Algesten
abda74c4d8 Upgrade deps 2023-01-31 08:52:47 +01:00
Jacob Hoffman-Andrews
34b239b388 Remove note about 2.0.0 being recent (#584) 2023-01-17 16:17:11 -08:00
Jacob Hoffman-Andrews
498e19943f Allow non-empty connection pools to be dropped (#583)
This breaks a reference cycle between PoolReturner and Agent that was
causing Agents (and their contained ConnectionPool) to never be dropped
so long as there was any stream in the ConnectionPool. This cause
sockets to leak over time, particularly when the convenience functions
ureq::get(), ureq::post(), etc were used, since those functions create
a new Agent each time.
2023-01-16 08:33:56 -08:00
Nathan Henrie
33fb553a28 Remove references to serde_derive (#581) 2023-01-09 14:46:00 -08:00
Jacob Hoffman-Andrews
032bfb4b27 gzip: examine Content-Length header before removing (#578)
Fixes #575.
2023-01-02 20:02:37 -08:00
Jacob Hoffman-Andrews
a8ca1ec085 Fix clippy 2022-12-09 17:03:35 +01:00
Jacob Hoffman-Andrews
6bef9daa8e Switch ureq to used forked chunked_transfer. 2022-12-09 17:03:35 +01:00
Jacob Hoffman-Andrews
43a12cdf51 Modify chunked crate for ureq use. 2022-12-09 17:03:35 +01:00
Jacob Hoffman-Andrews
fe3f1d550b Fork chunked_transfer crate 2022-12-09 17:03:35 +01:00
Jacob Hoffman-Andrews
9083d692f8 Redesign pooling mechanic (#565)
Introduce PoolReturner, a handle on an agent and a PoolKey that is
capable of returning a Stream to a Pool. Make Streams keep track of
their own PoolReturner, instead of having PoolReturnRead keep track of
that information.

For the LimitedRead code path, get rid of PoolReturnRead. Instead,
LimitedRead is responsible for returning its Stream to the Pool after
its second-to-last read. In other words, LimitedRead will return the
stream if the next read is guaranteed to return Ok(0).

Constructing a LimitedRead of size 0 is always wrong, because we could
always just return the stream immediately. Change the size argument to
NonZeroUsize to enforce that.

Remove the Done trait, which was only used for LimitedRead. It was used
to try and make sure we returned the stream to the pool on exact reads,
but was not reliable.

This does not yet move the ChunkDecoder code path away from
PoolReturnRead. That requires a little more work.

Part 1 of #559.  Fixes #555.
2022-12-03 23:42:58 -08:00
Jacob Hoffman-Andrews
d8225b22ed Split response body type into own function (#566)
This allows removing the hack where we create a Response with an empty `reader`,
then immediately mutate it to set the real reader. It also happens to allow us
to get rid of 3 fields of Response that were only used to pass information to
`stream_to_reader`.

I've tried to keep the structure and logic of the body calculation as close to
the same as possible, for ease of review and to avoid introducing bugs. I think
there are some followup fixes we can make to the logic, which will be made
easier by having it in a self contained function.
2022-12-03 10:22:53 -08:00
Jacob Hoffman-Andrews
cf687381bd Don't panic when rustls-native-certs errors (#564)
Fixes #563
2022-11-30 22:12:48 -08:00
zu1k
614d1dd7bc Make query_pairs more generic
Signed-off-by: zu1k <i@zu1k.com>
2022-11-26 11:09:33 +01:00
zu1k
78998dd032 feat: Set multi query parameters
Signed-off-by: zu1k <i@zu1k.com>
2022-11-26 11:09:33 +01:00
Jacob Hoffman-Andrews
dc7a8c3ebe Config-gate gzip test 2022-11-26 01:44:08 -08:00
Jacob Hoffman-Andrews
3745b028c6 Switch to MultiGzDecoder
This is more correct, since all gzip streams can consist of multiple members. It
has the happy side effect that it causes gzipped responses to reliably return
their streams to the pool.
2022-11-26 01:44:08 -08:00
Martin Algesten
5d9e89917c Test case showing gzip chunk not pooling 2022-11-26 01:44:08 -08:00
Jacob Hoffman-Andrews
a2836c49a7 Fix new clippy lints (#561) 2022-11-26 10:28:36 +01:00
Wolf Thomsen
28d667ade9 add badges to crates.io and docs.rs to README.md (#554) 2022-11-12 21:31:58 +01:00
Max von Forell
855f20e662 Add Response::remote_addr() (#489)
Fixes #488.
2022-10-03 13:29:21 -07:00
Martin Algesten
b0796c18f3 Make build work (#546)
The mbedtls example has caused problem in the main build a number of
times. By making it a standalone `cargo new --bin`, we can keep it in
the source tree as a good example but avoid having it break the main
build.

Also, fix some clippy lints.
2022-09-29 08:29:32 -07:00
Michael Schubart
a367a82317 Fix mistake in API docs 2022-08-28 12:09:17 +02:00
Martin Algesten
134d82ecf4 debug! log method of body response 2022-07-10 11:55:57 +02:00