pub mod headers {
pub const CONTENT_TYPE: &str = "Content-Type";
pub const AUTHORIZATION: &str = "Authorization";
pub const USER_AGENT: &str = "User-Agent";
pub const ACCEPT: &str = "Accept";
pub const CONTENT_LENGTH: &str = "Content-Length";
pub const CACHE_CONTROL: &str = "Cache-Control";
pub const HOST: &str = "Host";
pub const CONNECTION: &str = "Connection";
pub const X_API_KEY: &str = "X-API-Key";
pub const ACCEPT_ENCODING: &str = "Accept-Encoding";
}
pub mod mime_types {
pub const JSON: &str = "application/json";
pub const XML: &str = "application/xml";
pub const TEXT: &str = "text/plain";
pub const HTML: &str = "text/html";
pub const FORM: &str = "application/x-www-form-urlencoded";
pub const BINARY: &str = "application/octet-stream";
}
#[derive(Clone, Debug)]
pub struct HttpHeader<'a> {
pub name: &'a str,
pub value: &'a str,
}
impl<'a> HttpHeader<'a> {
#[must_use]
pub const fn new(name: &'a str, value: &'a str) -> Self {
Self { name, value }
}
#[must_use]
pub const fn content_type(value: &'a str) -> Self {
Self::new(headers::CONTENT_TYPE, value)
}
#[must_use]
pub const fn authorization(value: &'a str) -> Self {
Self::new(headers::AUTHORIZATION, value)
}
#[must_use]
pub const fn user_agent(value: &'a str) -> Self {
Self::new(headers::USER_AGENT, value)
}
#[must_use]
pub const fn accept(value: &'a str) -> Self {
Self::new(headers::ACCEPT, value)
}
#[must_use]
pub const fn api_key(value: &'a str) -> Self {
Self::new(headers::X_API_KEY, value)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_http_header_creation() {
let header = HttpHeader {
name: "Content-Type",
value: "application/json",
};
assert_eq!(header.name, "Content-Type");
assert_eq!(header.value, "application/json");
}
}