253 Commits

Author SHA1 Message Date
Mohamed Daahir
9afa25ca19 bump version to v0.24.1 2025-05-02 15:20:05 +01:00
zuisong
31c515e403
use sanitize-filename crate to make filenames safe
Sanitizes filenames by removing or replacing potentially problematic characters
Makes filenames safe for cross-platform use
Prevents directory traversal attacks (e.g., "../../../")
2025-04-10 14:47:07 +08:00
zuisong
a60a52453a
download file parse filename add RFC 5987 support
support percent-encoded filename

Signed-off-by: zuisong <com.me@foxmail.com>
2025-04-10 13:22:11 +08:00
Jan Verbeek
300203338f Improve rustls error messages for invalid certificates
After a recent release rustls provides better error messages for
invalid certificates. For example:

```
invalid peer certificate: certificate not valid for name "wrong.host.badssl.com"; certificate is only valid for DnsName("*.badssl.com") or DnsName("badssl.com")
```

The message for expired certificates still isn't too readable but the
error now contains timestamps so we enhance it ourselves:

```
xh: error: error sending request for url (https://expired.badssl.com/)

Caused by:
    0: client error (Connect)
    1: invalid peer certificate: certificate expired: verification time 1742381579 (UNIX), but certificate is not valid after 1428883199 (313498380 seconds ago)

Certificate not valid after 2015-04-12 23:59:59.0 +00:00:00 (9years 11months 6days 8h 43m 24s ago).
```
2025-03-19 12:29:17 +01:00
Mohamed Daahir
21e998e5b2 bump version to v0.24.0 2025-02-18 08:15:49 +00:00
Stefan Zwanenburg
de82cb8f6d Remove vendored reqwest_cookie_store.
Fixes #399
2025-01-19 13:23:55 +01:00
kranurag7
355dd04295 address review comments
Co-authored-by: Jan Verbeek <jan.verbeek@posteo.nl>
2025-01-11 23:13:41 +05:30
Fotis Gimian
196ca1f162
Switch to generating completions at runtime (#393)
* Allow for completion and man page generation at runtime and support for Elvish and Nshull

* Refine runtime generation based on feedback provided
2025-01-06 14:24:36 +02:00
Mohamed Daahir
65898226ee bump version to v0.23.1 2025-01-02 13:37:48 +02:00
Jan Verbeek
2b98447fac Enable logging in rustls and tracing-using dependencies
Enable `rustls`'s `logging` feature to start emitting logs.

Enable the `tracing` crate's `log` feature to hook up the dependencies
that log via that crate.

`hyper` can use `tracing` but it's currently unstable and locked
behind `RUSTFLAGS='--cfg hyper_unstable_tracing'` so we shouldn't use
it yet.

This partially addresses #389.

```console
$ RUST_LOG=trace/ALPN xh https://example.org
[0.495665s DEBUG rustls::client::hs] ALPN protocol is Some(b"h2")
[0.499526s TRACE hyper_util::client::legacy::client] ALPN negotiated h2, updating pool
HTTP/2.0 200 OK
[...]
$ RUST_LOG=rustls xh https://example.org
[0.288085s DEBUG rustls::client::hs] No cached session for DnsName("example.org")
[0.288657s DEBUG rustls::client::hs] Not resuming any session
[0.288767s TRACE rustls::client::hs] Sending ClientHello Message {
    version: TLSv1_0,
    payload: Handshake {
[...]
[0.698465s DEBUG rustls::client::hs] Using ciphersuite TLS13_AES_256_GCM_SHA384
[0.698508s DEBUG rustls::client::tls13] Not resuming
[0.698530s TRACE rustls::client::client_conn] EarlyData rejected
[0.699267s DEBUG rustls::client::tls13] TLS1.3 encrypted extensions: [Protocols([ProtocolName(6832)])]
[0.699342s DEBUG rustls::client::hs] ALPN protocol is Some(b"h2")
[0.699578s TRACE rustls::client::tls13] Server cert is
CertificateChain([CertificateDer(0x3082076e3082[...]
```

`native-tls` barely has any logging so we don't get much useful info
from there yet.
2024-11-30 17:51:01 +01:00
Mohamed Daahir
0fb0a13ecb bump version to v0.23.0 2024-10-12 22:22:45 +01:00
Jan Verbeek
65ca2f0848 Merge remote-tracking branch 'origin/master' into smart-header-decode 2024-09-30 21:46:49 +02:00
Mohamed Daahir
89e5428618 Merge branch 'hotfix/v0.22.0-re-fix-download-path-escape' 2024-07-08 23:30:41 +01:00
Mohamed Daahir
c0f46a4999 bump version to v0.22.2 2024-07-08 23:16:09 +01:00
Mohamed Daahir
dd27ddb4ac bump version to v0.22.1 2024-07-08 22:57:29 +01:00
Jan Verbeek
00bc6f2238 Decode headers as latin1/UTF-8, show real reason phrase
External changes:

- We now print the actual reason phrase sent by the server instead
  of guessing it from the status code. That is, if servers reply with
  "200 Wonderful" instead of "200 OK" then we show that. This is
  especially useful for status codes that xh doesn't recognize.

- Header values are now decoded as latin1, with the UTF-8 decoding
  also shown if applicable.

- A new FAQ file with an entry that explains header value encoding.
  Header output now hyperlinks to this entry when relevant and if
  supported by the terminal.

Under the hood we now color headers manually. It's still hooked up to
the `.tmTheme` files but not to the `.sublime-syntax` file. This lets
us highlight the latin1 header values differently. In the future we
could use the same approach to optimize JSON highlighting.

I'm unsure about the position of the hyperlink. Currently it's the
text "UTF-8" in `<latin1 value> (UTF-8: <utf-8 value>)`. But that
means it's only shown if the value can be decoded as UTF-8. An
alternative is to turn the latin1 value itself into a hyperlink, but
that's confusing if the value itself is already a URL (which is a
common case for the `Location` header).

I also don't feel that our text is quite distinct enough from the
header value in the default `ansi` theme. Though the hyperlink does
help to set it apart.
2024-07-04 21:34:52 +02:00
zuisong
4248428745
update ruzstd to 0.7.0 2024-06-28 14:46:40 +08:00
Jan Verbeek
41ab47f32f Add --debug option for logging and backtraces
Add `env_logger` to be able to print the logs that our libraries
already generate.

Add some logging to the application code. We'll probably want more log
messages, and we might want to upgrade some of them from trace to
debug.

Add a `--debug` flag that automatically enables `env_logger` as well
as backtraces for `anyhow` and panics.

```console
$ xh --debug :
[2024-06-05T13:54:40Z DEBUG xh] xh 0.22.0 -native-tls +rustls
[2024-06-05T13:54:40Z DEBUG xh] Cli {
        httpie_compat_mode: false,
        [...]
    }
[2024-06-05T13:54:40Z DEBUG xh] Complete URL: http://localhost/
[2024-06-05T13:54:40Z DEBUG xh] HTTP method: GET
[2024-06-05T13:54:40Z DEBUG reqwest::connect] starting new connection: http://localhost/
[2024-06-05T13:54:40Z DEBUG hyper_util::client::legacy::connect::dns] resolving host="localhost"
[...]
xh: error: error sending request for url (http://localhost/)

Caused by:
    0: client error (Connect)
    1: tcp connect error: Connection refused (os error 111)
    2: Connection refused (os error 111)

Stack backtrace:
   0: anyhow::error::<impl core::convert::From<E> for anyhow::Error>::from
             at ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/anyhow-1.0.82/src/error.rs:565:25
[...]
```

We could ask users to post `--debug` output when reporting bugs.
2024-06-05 17:47:36 +02:00
zuisong
94f0d6214f
use ruzstd crate 2024-05-06 10:38:39 +08:00
zuisong
c94fea2013
decode responses in zstd format 2024-05-06 10:38:39 +08:00
Mohamed Daahir
0c335ac26a bump version to v0.22.0 2024-04-13 01:34:00 +03:00
Mohamed Daahir
57779c04aa raise msrv to 1.74 2024-04-13 01:21:28 +03:00
Mohamed Daahir
40a0448918
Merge pull request #359 from ducaale/interface-name-bind
Directly bind to interface name on supported platforms
2024-04-13 00:19:04 +03:00
Mohamed Daahir
e9f62da7bc re-add comment about auto-disabling network-interface 2024-04-12 23:22:14 +03:00
Jan Verbeek
034591e2b7 Use serde-transcode to optimize JSON formatting
Instead of parsing the JSON input into a complicated heap value before
writing it out we can write it out as we parse it. On a ridiculously
large input this gives me a 5× speedup.
2024-04-12 21:18:10 +02:00
Mohamed Daahir
e25815bc1e Merge branch 'master' into interface-name-bind 2024-04-06 16:28:52 +01:00
zuisong
3f658ed4ed
hyper v1 upgrade 2024-04-06 00:40:21 +08:00
Mohamed Daahir
30b88308cb include network-interface in default features 2024-04-02 03:59:44 +01:00
Mohamed Daahir
3fa051a6db Merge branch 'master' into interface-name-bind 2024-04-01 23:05:40 +01:00
Mohamed Daahir
83da60e76e don't pull network-interface if platform supports SO_BINDTODEVICE 2024-04-01 23:03:46 +01:00
Mohamed Daahir
6f8f9b0c1f directly bind to interface name on supported platforms 2024-04-01 17:38:21 +01:00
zuisong
f9f0edc553
hyper v1 upgrade 2024-03-27 21:12:47 +08:00
zuisong
231ad3a41f
modify rand as a dev-dependency 2024-03-25 15:25:32 +08:00
Mohamed Daahir
9580a9050e bump version to v0.21.0 2024-01-28 21:08:51 +00:00
Mohamed Daahir
3d1afbad03
Merge pull request #339 from ducaale/update-lock-file
Update Cargo.lock
2023-11-30 19:57:02 +00:00
Mohamed Daahir
5964fb167f update cargo.toml to match clap's version in cargo.lock 2023-11-27 22:39:39 +00:00
Mohamed Daahir
c9162b6a74 replace regex with regex-lite 2023-11-27 22:36:07 +00:00
Mohamed Daahir
b694c7776b bump version to v0.20.1 2023-11-19 17:08:38 +00:00
Mohamed Daahir
6ed5362db8 bump version to v0.20.0 2023-11-19 16:50:09 +00:00
Mohamed Daahir
7a41828697 replace atty with IsTerminal trait 2023-11-19 16:22:46 +00:00
Mohamed Daahir
f4bc2533d3 raise MSRV to 1.70 2023-11-19 16:10:19 +00:00
Mohamed Daahir
0941f85d55 pin clap to 4.3 2023-11-19 16:00:56 +00:00
Mohamed Daahir
b83855b806 raise MSRV to 1.65 2023-11-19 15:46:12 +00:00
Mohamed Daahir
d34e0537ee bump version to v0.19.4 2023-10-22 16:54:08 +01:00
John Vandenberg
cd08c47fdf Bump dependencies 2023-10-22 20:04:02 +08:00
John Vandenberg
1e69ff40d2 Use serde derive feature 2023-10-22 08:46:17 +08:00
Mohamed Daahir
9e3b1b46ea bump version to v0.19.3 2023-10-21 21:23:38 +01:00
Jan Verbeek
a1599960b9 Make network-interface an optional dependency 2023-10-21 21:37:03 +02:00
Mohamed Daahir
c45cc0bf97 bump version to v0.19.2 2023-10-21 15:00:13 +01:00
Mohamed Daahir
0e4a87baf1 bump version to v0.19.1 2023-10-09 21:20:10 +01:00