rama_http_types/
lib.rs

1//! rama http types and minimal utilities
2//!
3//! # Rama
4//!
5//! Crate used by the end-user `rama` crate and `rama` crate authors alike.
6//!
7//! Learn more about `rama`:
8//!
9//! - Github: <https://github.com/plabayo/rama>
10//! - Book: <https://ramaproxy.org/book/>
11
12#![doc(
13    html_favicon_url = "https://raw.githubusercontent.com/plabayo/rama/main/docs/img/old_logo.png"
14)]
15#![doc(html_logo_url = "https://raw.githubusercontent.com/plabayo/rama/main/docs/img/old_logo.png")]
16#![cfg_attr(docsrs, feature(doc_auto_cfg, doc_cfg))]
17#![cfg_attr(test, allow(clippy::float_cmp))]
18#![cfg_attr(not(test), warn(clippy::print_stdout, clippy::dbg_macro))]
19
20pub(crate) mod body;
21pub use body::{Body, BodyDataStream};
22
23mod body_limit;
24pub use body_limit::BodyLimit;
25
26mod body_ext;
27pub use body_ext::BodyExtractExt;
28
29/// Type alias for [`http::Request`] whose body type
30/// defaults to [`Body`], the most common body type used with rama.
31pub type Request<T = Body> = http::Request<T>;
32
33/// Type alias for [`http::Response`] whose body type defaults to [`Body`], the most common body
34/// type used with rama.
35pub type Response<T = Body> = http::Response<T>;
36
37pub mod proto;
38
39pub mod conn;
40
41pub mod dep {
42    //! Dependencies for rama http modules.
43    //!
44    //! Exported for your convenience.
45
46    pub mod http {
47        //! Re-export of the [`http`] crate.
48        //!
49        //! A general purpose library of common HTTP types.
50        //!
51        //! [`http`]: https://docs.rs/http
52
53        #[doc(inline)]
54        pub use http::*;
55    }
56
57    pub mod http_body {
58        //! Re-export of the [`http-body`] crate.
59        //!
60        //! Asynchronous HTTP request or response body.
61        //!
62        //! [`http-body`]: https://docs.rs/http-body
63
64        #[doc(inline)]
65        pub use http_body::*;
66    }
67
68    pub mod http_body_util {
69        //! Re-export of the [`http-body-util`] crate.
70        //!
71        //! Utilities for working with [`http-body`] types.
72        //!
73        //! [`http-body`]: https://docs.rs/http-body
74        //! [`http-body-util`]: https://docs.rs/http-body-util
75
76        #[doc(inline)]
77        pub use http_body_util::*;
78    }
79
80    pub mod mime {
81        //! Re-export of the [`mime`] crate.
82        //!
83        //! Support MIME (Media Types) as strong types in Rust.
84        //!
85        //! [`mime`]: https://docs.rs/mime
86
87        #[doc(inline)]
88        pub use mime::*;
89    }
90
91    pub mod mime_guess {
92        //! Re-export of the [`mime_guess`] crate.
93        //!
94        //! Guessing of MIME types by file extension.
95        //!
96        //! [`mime_guess`]: https://docs.rs/mime_guess
97
98        #[doc(inline)]
99        pub use mime_guess::*;
100    }
101}
102
103pub mod header {
104    //! HTTP header types
105
106    #[doc(inline)]
107    pub use crate::dep::http::header::*;
108
109    macro_rules! static_header {
110        ($($name_bytes:literal),+ $(,)?) => {
111            $(
112                rama_macros::paste! {
113                    #[doc = concat!("header name constant for `", $name_bytes, "`.")]
114                    pub static [<$name_bytes:snake:upper>]: super::HeaderName = super::HeaderName::from_static($name_bytes);
115                }
116            )+
117        };
118    }
119
120    // non-std conventional
121    static_header!["x-forwarded-host", "x-forwarded-for", "x-forwarded-proto",];
122
123    // standard
124    static_header!["keep-alive", "proxy-connection"];
125
126    // non-std client ip forward headers
127    static_header![
128        "cf-connecting-ip",
129        "true-client-ip",
130        "client-ip",
131        "x-client-ip",
132        "x-real-ip",
133    ];
134
135    /// Static Header Value that is can be used as `User-Agent` or `Server` header.
136    pub static RAMA_ID_HEADER_VALUE: HeaderValue = HeaderValue::from_static(
137        const_format::formatcp!("{}/{}", rama_utils::info::NAME, rama_utils::info::VERSION),
138    );
139}
140
141#[doc(inline)]
142pub use self::dep::http::header::{HeaderMap, HeaderName, HeaderValue};
143#[doc(inline)]
144pub use self::dep::http::method::Method;
145#[doc(inline)]
146pub use self::dep::http::status::StatusCode;
147#[doc(inline)]
148pub use self::dep::http::uri::{Scheme, Uri};
149#[doc(inline)]
150pub use self::dep::http::version::Version;