pdk_classy/hl/
early_response.rs1#[derive(Clone, PartialEq, PartialOrd, Eq, Ord, Debug, Hash, Default)]
7pub struct Response {
8 status_code: u32,
9 headers: Vec<(String, String)>,
10 body: Vec<u8>,
11}
12
13impl Response {
14 pub fn new(status_code: u32) -> Self {
16 Self {
17 status_code,
18 headers: Vec::new(),
19 body: Vec::new(),
20 }
21 }
22
23 pub fn with_headers(mut self, headers: impl Into<Vec<(String, String)>>) -> Self {
25 self.headers = headers.into();
26 self
27 }
28
29 pub fn with_body(mut self, body: impl Into<Vec<u8>>) -> Self {
31 self.body = body.into();
32 self
33 }
34
35 pub fn status_code(&self) -> u32 {
37 self.status_code
38 }
39
40 pub fn headers(&self) -> Vec<(&str, &str)> {
42 self.headers
43 .iter()
44 .map(|(k, v)| (k.as_str(), v.as_str()))
45 .collect()
46 }
47
48 pub fn body(&self) -> Option<&[u8]> {
50 (!self.body.as_slice().is_empty()).then_some(self.body.as_slice())
51 }
52}