Commit Graph

500 Commits

Author SHA1 Message Date
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
Jacob Hoffman-Andrews
f14fc45179 Buffer short responses (2) (#531)
* Response: build reader at construction time

* Remove unwrapping/rewrapping DeadlineStream

* Let into_reader() provide Sync + 'static

* Prebuffer Vec use known capacity

Co-authored-by: Martin Algesten <martin@algesten.se>
2022-07-10 11:12:50 +02:00
Jacob Hoffman-Andrews
9908c446d6 Simplify ReadWrite interface (#530)
Previously, ReadWrite had methods `is_poolable` and `written_bytes`, which
were solely for the use of unittests.

This replaces `written_bytes` and `TestStream` with a `struct Recorder`
that implements `ReadWrite` and allows unittests to access its recorded
bytes via an `Arc<Mutex<Vec<u8>>>`. It eliminates `is_poolable`; it's fine
to pool a Stream of any kind.

The new `Recorder` also has some convenience methods that abstract away
boilerplate code from many of our unittests.

I got rid of `Stream::from_vec` and `Stream::from_vec_poolable` because
they depended on `TestStream`. They've been replaced by `NoopStream` for
the pool.rs tests, and `ReadOnlyStream` for constructing `Response`s from
`&str` and some test cases.
2022-07-09 10:13:44 -07:00
Jacob Hoffman-Andrews
0cf1f8dbb9 Add Sync traits to ReadWrite trait (#528)
This allows us to get rid of a Mutex (and not take a dependency on
sync_wrapper).
2022-07-05 01:52:25 -07:00
Martin Algesten
9395046029 IoResult -> io::Result (#521) 2022-06-11 17:06:43 -07:00
guyo13
c94284482a Return Err on deadline checked_add overflow instead of panic (#517) 2022-05-22 19:51:58 +02:00
Jacob Hoffman-Andrews
8a32cae507 Remove sync_wrapper dep in favor of Mutex (#514)
We unwrap the stream exactly once per response, and we know that case
will be uncontended for the same reason `SyncWrapper` works:
`into_reader()` takes `self`, so it must have exclusive ownership.
Uncontended mutexes are extremely cheap. This saves us a dependency
at a trivial performance cost.
2022-05-09 10:32:23 -07:00
Jacob Hoffman-Andrews
4bb6d3a4db DeadlineStream: read from Stream's buffer first (#508)
This fixes an issue where requests with a deadline would do a syscall
on every read, rather than pulling from the buffer. Fixes a problem
reported in #506 where `resp.into_json()` was unnecessarily slow.
2022-05-09 10:31:59 -07:00
Martin Algesten
4675d748e9 Remove Sync bound from TlsConnector io arg 2022-05-07 14:39:59 +02:00
Martin Algesten
049b5a5acd Fixes after feedback 2022-05-07 14:39:59 +02:00
Martin Algesten
65371c966c Box<dyn ReadWrite> for TlsConnector::connect 2022-05-07 14:39:59 +02:00
Jacob Hoffman-Andrews
101467f13f Return stream to pool on exact read (#509)
If the user reads exactly the number of bytes in the response, then
drops the Read object, streams will never get returned to the pool since
the user never triggered a read past the end of the LimitedRead.

This fixes that by making PoolReturnRead aware of the level below it, so
it can ask if a stream is "done" without actually doing a read.

Also, a refactorign:

Previously, Response contained an Option<Box<Unit>> because the testing
method `from_str()` would construct a Response with no associated Unit.
However, this increased code complexity with no corresponding test
benefit. Instead, construct a fake Unit in from_str().

Also, instead of taking an `Option<Box<Unit>>`, PoolReturnRead now takes
a URL (to figure out host and port for the PoolKey) and an &Agent where
it will return the stream. This cuts interconnectedness somewhat:
PoolReturnRead doesn't need to know about Unit anymore.
2022-04-30 17:22:27 -07:00
Jacob Hoffman-Andrews
4d77d365a0 Improve unittest 2022-04-30 14:55:07 +02:00