nanofish_client/
header.rs1pub mod headers {
3 pub const CONTENT_TYPE: &str = "Content-Type";
5 pub const AUTHORIZATION: &str = "Authorization";
7 pub const USER_AGENT: &str = "User-Agent";
9 pub const ACCEPT: &str = "Accept";
11 pub const CONTENT_LENGTH: &str = "Content-Length";
13 pub const CACHE_CONTROL: &str = "Cache-Control";
15 pub const HOST: &str = "Host";
17 pub const CONNECTION: &str = "Connection";
19 pub const X_API_KEY: &str = "X-API-Key";
21 pub const ACCEPT_ENCODING: &str = "Accept-Encoding";
23}
24
25pub mod mime_types {
27 pub const JSON: &str = "application/json";
29 pub const XML: &str = "application/xml";
31 pub const TEXT: &str = "text/plain";
33 pub const HTML: &str = "text/html";
35 pub const FORM: &str = "application/x-www-form-urlencoded";
37 pub const BINARY: &str = "application/octet-stream";
39}
40
41#[derive(Clone, Debug)]
47pub struct HttpHeader<'a> {
48 pub name: &'a str,
50 pub value: &'a str,
52}
53
54impl<'a> HttpHeader<'a> {
55 #[must_use]
57 pub const fn new(name: &'a str, value: &'a str) -> Self {
58 Self { name, value }
59 }
60
61 #[must_use]
63 pub const fn content_type(value: &'a str) -> Self {
64 Self::new(headers::CONTENT_TYPE, value)
65 }
66
67 #[must_use]
69 pub const fn authorization(value: &'a str) -> Self {
70 Self::new(headers::AUTHORIZATION, value)
71 }
72
73 #[must_use]
75 pub const fn user_agent(value: &'a str) -> Self {
76 Self::new(headers::USER_AGENT, value)
77 }
78
79 #[must_use]
81 pub const fn accept(value: &'a str) -> Self {
82 Self::new(headers::ACCEPT, value)
83 }
84
85 #[must_use]
87 pub const fn api_key(value: &'a str) -> Self {
88 Self::new(headers::X_API_KEY, value)
89 }
90}
91
92#[cfg(test)]
93mod tests {
94 use super::*;
95
96 #[test]
97 fn test_http_header_creation() {
98 let header = HttpHeader {
99 name: "Content-Type",
100 value: "application/json",
101 };
102 assert_eq!(header.name, "Content-Type");
103 assert_eq!(header.value, "application/json");
104 }
105}