aws_smithy_compression/
http.rs

1/*
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
6//! Checksum support for HTTP requests and responses.
7
8/// Support for the `http-body-0-4` and `http-0-2` crates.
9#[cfg(feature = "http-body-0-4-x")]
10pub mod http_body_0_4_x {
11    use crate::Compress;
12    use http_0_2::header::{HeaderName, HeaderValue};
13
14    /// Implementors of this trait can be used to compress HTTP requests.
15    pub trait CompressRequest: Compress + CloneCompressRequest {
16        /// Return the header name for the content-encoding header.
17        fn header_name(&self) -> HeaderName {
18            HeaderName::from_static("content-encoding")
19        }
20
21        /// Return the header value for the content-encoding header.
22        fn header_value(&self) -> HeaderValue;
23    }
24
25    /// Enables CompressRequest implementors to be cloned.
26    pub trait CloneCompressRequest {
27        /// Clone this request compressor.
28        fn clone_request_compressor(&self) -> Box<dyn CompressRequest>;
29    }
30
31    impl<T> CloneCompressRequest for T
32    where
33        T: CompressRequest + Clone + 'static,
34    {
35        fn clone_request_compressor(&self) -> Box<dyn CompressRequest> {
36            Box::new(self.clone())
37        }
38    }
39
40    impl Clone for Box<dyn CompressRequest> {
41        fn clone(&self) -> Self {
42            self.clone_request_compressor()
43        }
44    }
45}
46
47/// Support for the `http-body-1-0` and `http-1-0` crates.
48#[cfg(feature = "http-body-1-x")]
49pub mod http_body_1_x {
50    use crate::Compress;
51    use http_1_0::header::{HeaderName, HeaderValue};
52
53    /// Implementors of this trait can be used to compress HTTP requests.
54    pub trait CompressRequest: Compress + CloneCompressRequest {
55        /// Return the header name for the content-encoding header.
56        fn header_name(&self) -> HeaderName {
57            HeaderName::from_static("content-encoding")
58        }
59
60        /// Return the header value for the content-encoding header.
61        fn header_value(&self) -> HeaderValue;
62    }
63
64    /// Enables CompressRequest implementors to be cloned.
65    pub trait CloneCompressRequest {
66        /// Clone this request compressor.
67        fn clone_request_compressor(&self) -> Box<dyn CompressRequest>;
68    }
69
70    impl<T> CloneCompressRequest for T
71    where
72        T: CompressRequest + Clone + 'static,
73    {
74        fn clone_request_compressor(&self) -> Box<dyn CompressRequest> {
75            Box::new(self.clone())
76        }
77    }
78
79    impl Clone for Box<dyn CompressRequest> {
80        fn clone(&self) -> Self {
81            self.clone_request_compressor()
82        }
83    }
84}