Commit Graph

104 Commits

Author SHA1 Message Date
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
06db500ec4 refactor: keep http-related code together 2023-03-15 03:54:13 +01:00
Martin Algesten
05b9a82a38 Clippy fix 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
6bef9daa8e Switch ureq to used forked chunked_transfer. 2022-12-09 17:03:35 +01: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
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
Martin Algesten
653cf03dee Fix and and
Close #503
2022-04-24 19:40:20 +02:00
Ed Morley
a8ed085a93 Fix broken TLS anchor link in docs overview
Now correctly links to:
https://docs.rs/ureq/latest/ureq/#https--tls--ssl

Introduced in 56276c3742.

Also fixes a rustdoc typo spotted by my IDE's spell checker whilst the
project was open.
2022-04-22 19:25:44 +02:00
Martin Algesten
6e5041044b Rename trait HttpsStream -> ReadWrite and make it public
Also provide an example of how to use it.
2022-01-22 10:41:22 +01:00
Martin Algesten
09ecb6ffd6 Implement middleware function 2021-12-22 07:58:45 +01:00
Jacob Hoffman-Andrews
352bf19f40 Fix doctests 2021-12-20 09:19:25 +01:00
Jacob Hoffman-Andrews
2df70168c4 Use ? instead of unwrap in examples (#458)
This is recommended by the Rust API Guidelines:

https://rust-lang.github.io/api-guidelines/documentation.html#examples-use--not-try-not-unwrap-c-question-mark

One exception: When we need to unwrap an Option, the examples still use
.unwrap(). The alternative would be something like
`.ok_or(SomeErrorHere)?`, which feels like an awkward way to deal with
an Option. This might get better with NoneError:

https://docs.rs/rustc-std-workspace-std/1.0.1/std/option/struct.NoneError.html

I also rearranged some examples that used turbofish to use type
annotations. I think type annotations are more familiar to early Rust
users (and they use fewer characters and less punctuation, which is
always nice).
2021-12-19 20:04:30 -08:00
Martin Algesten
738cb84aec Enable 'gzip' by default 2021-12-20 02:38:18 +01:00
Malloc Voidstar
9a070fb1ad And to lib.rs, woops 2021-12-19 14:01:56 +01:00
Martin Algesten
2a5ab43c8c Expose RedirectAuthHeaders enum at crate root 2021-12-19 11:00:39 +01:00
soruh
61e2402045 deprecate using SerdeValue, SerdeMap and serde_to_value
as they are just wrapper around serde_json::{Value, Map, to_value}.
Instead expose the serde_json and serde crates used.
2021-12-17 20:12:07 +01:00
Jacob Hoffman-Andrews
56276c3742 Add support for alternate TLs implementations. 2021-12-17 17:47:30 +01:00
Jochen Kupperschmidt
69ad3aabb0 Add shortcuts for PATCH (again)` 2021-11-26 13:50:29 +01:00
Keijia
f6f021cdbb highlight that socks:// prefix is equal to socks5:// 2021-08-23 20:46:44 +02:00
Keijia
37e19b34ec add socks4 to readme 2021-08-23 20:46:44 +02:00
Tshepang Lekhonkhobe
eb04d96af8 Fix a typo (#397) 2021-07-09 09:10:22 -07:00
Martin Algesten
4ade506047 Allow upper_case_acronyms 2021-04-17 12:30:39 +02:00
Martin Algesten
40e156e2a3 Url access functions for Request (simpler) 2021-03-24 20:58:47 +01:00
Martin Algesten
b42e9afd71 Fix clippy warnings 2021-03-24 20:29:43 +01:00
Martin Algesten
d627ef9704 OrAnyStatus::or_any_status ergonomic helper
Some users might prefer to handle all HTTP responses as Response
regardless of status code.
2021-01-30 09:40:45 +01:00
Martin Algesten
948f736125 Document proxy support (#298)
ureq supports proxying using HTTP CONNECT and SOCKS5, the features are however
missing documentation. This brings it to the lib.rs doc.
2021-01-09 09:58:07 -08:00
Joshua Nelson
f0245aad23 Fix some clippy lints (#292)
This commit can be replicated with `cargo +nightly clippy --fix -Z unstable-options`,
plus an edit to fix another `return` missed by clippy.
2021-01-03 20:10:43 -08:00
Martin Algesten
8f9f3e5827 Fix main lib.rs and README.md example (#284)
Small fixes to just ensure lib.rs and README.md are run via cargo readme.
2021-01-03 10:38:10 -08:00
Martin Algesten
1f0d84279a Document simplest error example 2020-12-27 23:47:43 +01:00
Jacob Hoffman-Andrews
243b987110 Remove error_on_non_2xx. (#272)
After the recent changes in #257, it's probably not necessary. It's now
quite easy to use a match statement to extract responses for certain
status codes, or all status codes.

Add documentation on how to turn a status code error back into a
Response.
2020-12-18 22:10:55 -08:00
Jacob Hoffman-Andrews
e25a6876f9 Document error handling. 2020-12-18 22:04:00 -08:00
Jacob Hoffman-Andrews
10baf7c051 Clarify example from README. (#277)
We should include the `fn main() -> Result` part, because people may not
know they need the `-> Result` in order for `?` to work.

Also, I replaced `Accept: text/html` with `Example-Header: header
value`. My thinking is that if someone doesn't know they need to remove
that Accept for non-HTML URLs, they might get unexpected results.
2020-12-12 10:33:30 -08:00
Jacob Hoffman-Andrews
6c9378ce37 De-redundantize Error kinds. (#259)
Change "Bad" to "Invalid" in error names, mimicking io::Error::ErrorKind.

Change InvalidProxyCreds to ProxyUnauthorized.

Change DnsFailed to just Dns (the fact that there was a failure is implicit
in the fact that this was an error).
2020-12-05 12:05:29 -08:00
Martin Algesten
b91d196fbc error::Transport part of public API 2020-12-05 20:00:47 +01:00
Jacob Hoffman-Andrews
cc7ce757bd Update CHANGELOG, Cargo.toml, and docs for 2.0. 2020-11-22 11:09:32 -08:00
Jacob Hoffman-Andrews
e92bf0b4bb Add ureq::request_url and Agent::request_url. (#226)
These let a user pass an already-parsed Url.
2020-11-21 22:11:15 -08:00
Jacob Hoffman-Andrews
0321ea043d Add some short docstrings for types. (#225)
These types were missing a short docstring, leaving the comment space to
their right blank on the crate page.

Also, this takes advantage of intra-rustdoc links to link terms:
https://github.com/rust-lang/rfcs/blob/master/text/1946-intra-rustdoc-links.md
2020-11-21 22:10:37 -08:00
Jacob Hoffman-Andrews
fade03b54e Rewrite the Error type. (#234)
This adds a source field to keep track of upstream errors and allow
backtraces, plus a URL field to indicate what URL an error was
associated with.

The enum variants we used to use for Error are now part of a new
ErrorKind type. For convenience within ureq, ErrorKinds can be turned
into an Error with `.new()` or `.msg("some additional information")`.

Error acts as a builder, so additional information can be added after
initial construction. For instance, we return a DnsFailed error when
name resolution fails. When that error bubbles up to Request's
`do_call`, Request adds the URL.

Fixes #232.
2020-11-21 16:14:44 -08:00
Jacob Hoffman-Andrews
c891aa31e5 Tweak sentence. 2020-11-19 21:36:23 -08:00
Jacob Hoffman-Andrews
cc72fdfca8 Add section on async 2020-11-19 21:31:23 -08:00
Jacob Hoffman-Andrews
a300ccdaad Update README and docs.
This makes src/lib.rs the primary source for crate-level documentation.
I've generated README.md with `cargo readme > README.md`. Since links to
specific documentation items should be relative when possible, but must
be absolute in README.md, I've used the new syntax for intra-rustdoc
links
(https://github.com/rust-lang/rfcs/blob/master/text/1946-intra-rustdoc-links.md),
along with a README.tpl that sets up those links to point at the
absolute versions. `cargo readme` uses the README.tpl by default.

I've also rewritten the crate level docs, removing some TODO information
at the bottom, and moving the license information to CONTRIBUTING.md.
2020-11-15 22:58:02 -08:00
Jacob Hoffman-Andrews
26145810bf Add some more updates. 2020-11-15 09:14:19 +01:00
Jacob Hoffman-Andrews
acc36ac370 Add support for using testserver in doctests. (#218)
Doctests run against a normally-built copy of the crate, i.e. one
without #[cfg(test)] set, so we can't use the conditional compilation
feature.

Instead, define a static var that indicates whether the library is
running in test mode or not. For each doctest, insert a hidden call that
sets this var to true. Then, when ureq::agent() is called, it returns a
test_agent instead.

This required moving testserver out of the test mod and into src/, so
that it can be included unconditionally (i.e. when cfg(test) is false).

This PR converts one doctest as an example. If we land this PR, I'll
send a followup to convert the rest.
2020-11-13 10:40:16 -08:00
Martin Algesten
b66e618198 Gate entire mod cookies on "cookies" feature 2020-11-08 11:31:49 +01:00
Jacob Hoffman-Andrews
d83de53bcd Restore HEAD and DELETE
Also, remove OPTIONS, TRACE, and PATCH from lib.rs.
2020-10-30 05:49:01 +01:00