Skip to main content

musdk_common/
function.rs

1mod response;
2
3use std::{borrow::Cow, collections::HashMap};
4
5use borsh::{BorshDeserialize, BorshSerialize};
6
7pub use crate::common_http::{Header, HttpMethod, Status};
8pub use response::{Response, ResponseBuilder};
9
10#[derive(Debug, BorshSerialize, BorshDeserialize)]
11pub struct Request<'a> {
12    pub method: HttpMethod,
13    pub path_params: HashMap<Cow<'a, str>, Cow<'a, str>>,
14    pub query_params: HashMap<Cow<'a, str>, Cow<'a, str>>,
15    pub headers: Vec<Header<'a>>,
16    pub body: Cow<'a, [u8]>,
17}
18
19impl<'a> Request<'a> {
20    pub fn content_type(&self) -> Option<Cow<'a, str>> {
21        self.headers.iter().find_map(|header| {
22            if &header.name.to_lowercase() == "content-type" {
23                Some(header.value.clone())
24            } else {
25                None
26            }
27        })
28    }
29}