1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0
 */

//! Checksum support for HTTP requests and responses.

/// Support for the `http-body-0-4` and `http-0-2` crates.
#[cfg(feature = "http-body-0-4-x")]
pub mod http_body_0_4_x {
    use crate::Compress;
    use http_0_2::header::{HeaderName, HeaderValue};

    /// Implementors of this trait can be used to compress HTTP requests.
    pub trait CompressRequest: Compress + CloneCompressRequest {
        /// Return the header name for the content-encoding header.
        fn header_name(&self) -> HeaderName {
            HeaderName::from_static("content-encoding")
        }

        /// Return the header value for the content-encoding header.
        fn header_value(&self) -> HeaderValue;
    }

    /// Enables CompressRequest implementors to be cloned.
    pub trait CloneCompressRequest {
        /// Clone this request compressor.
        fn clone_request_compressor(&self) -> Box<dyn CompressRequest>;
    }

    impl<T> CloneCompressRequest for T
    where
        T: CompressRequest + Clone + 'static,
    {
        fn clone_request_compressor(&self) -> Box<dyn CompressRequest> {
            Box::new(self.clone())
        }
    }

    impl Clone for Box<dyn CompressRequest> {
        fn clone(&self) -> Self {
            self.clone_request_compressor()
        }
    }
}

/// Support for the `http-body-1-0` and `http-1-0` crates.
#[cfg(feature = "http-body-1-x")]
pub mod http_body_1_x {
    use crate::Compress;
    use http_1_0::header::{HeaderName, HeaderValue};

    /// Implementors of this trait can be used to compress HTTP requests.
    pub trait CompressRequest: Compress + CloneCompressRequest {
        /// Return the header name for the content-encoding header.
        fn header_name(&self) -> HeaderName {
            HeaderName::from_static("content-encoding")
        }

        /// Return the header value for the content-encoding header.
        fn header_value(&self) -> HeaderValue;
    }

    /// Enables CompressRequest implementors to be cloned.
    pub trait CloneCompressRequest {
        /// Clone this request compressor.
        fn clone_request_compressor(&self) -> Box<dyn CompressRequest>;
    }

    impl<T> CloneCompressRequest for T
    where
        T: CompressRequest + Clone + 'static,
    {
        fn clone_request_compressor(&self) -> Box<dyn CompressRequest> {
            Box::new(self.clone())
        }
    }

    impl Clone for Box<dyn CompressRequest> {
        fn clone(&self) -> Self {
            self.clone_request_compressor()
        }
    }
}