proxmox/proxmox-http/src
Maximiliano Sandoval 4d1c4ec829 http: teach the Client how to decode deflate content
The Backup Server can compress the content using deflate so we teach the
client how to decode it.

If a request is sent with the `Accept-Encoding` [2] header set to
`deflate`, and the response's `Content-Encoding` [1] header is equal to
`deflate` we wrap the Body stream with a stream that can decode `zlib`
on the run.

Note that from the `Accept-Encoding` docs [2], the `deflate` encoding is
actually `zlib`.

This can be also tested against
http://eu.httpbin.org/#/Response_formats/get_deflate by adding the
following test:

```rust
    #[tokio::test]
    async fn test_client() {
        let client = Client::new();
        let headers = HashMap::from([(
            hyper::header::ACCEPT_ENCODING.to_string(),
            "deflate".to_string(),
        )]);
        let response = client
            .get_string("https://eu.httpbin.org/deflate", Some(&headers))
            .await;
        assert!(response.is_ok());
    }
```

at `proxmox-http/src/client/simple.rs` and running

```
cargo test --features=client,client-trait
```

[1] https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding
[2] https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Encoding

Suggested-by: Lukas Wagner <l.wagner@proxmox.com>
Signed-off-by: Maximiliano Sandoval <m.sandoval@proxmox.com>
Reviewed-by: Max Carrara <m.carrara@proxmox.com>
Tested-by: Max Carrara <m.carrara@proxmox.com>
2024-07-10 11:37:36 +02:00
..
client http: teach the Client how to decode deflate content 2024-07-10 11:37:36 +02:00
websocket http: remove unnecessary cast 2024-06-28 10:22:58 +02:00
client_trait.rs http: client_trait: make request body generic 2022-09-07 09:25:47 +02:00
http_options.rs http: move SimpleHttpOptions to http-helpers feature 2022-09-07 09:17:45 +02:00
lib.rs tree-wide: enable doc_cfg and doc_auto_cfg for docs 2024-07-02 11:59:53 +02:00
proxy_config.rs http: rename SimpleHttp to Client 2022-09-07 09:17:45 +02:00
rate_limited_stream.rs http: rate limited stream: fix typo in rustdoc comment 2023-11-08 09:56:26 +01:00
rate_limiter.rs http: move rate-limiting out of client feature 2023-03-02 16:14:04 +01:00
uri.rs http: take over json_object_to_query 2022-06-29 10:32:44 +02:00