sentinel_modsec/variables/
response.rs1use super::collection::HashMapCollection;
4
5#[derive(Debug, Clone, Default)]
7pub struct ResponseData {
8 pub status: u16,
10 pub protocol: String,
12 pub headers: HashMapCollection,
14 pub body: Vec<u8>,
16 pub content_type: String,
18}
19
20impl ResponseData {
21 pub fn new() -> Self {
23 Self::default()
24 }
25
26 pub fn set_status(&mut self, status: u16) {
28 self.status = status;
29 }
30
31 pub fn set_protocol(&mut self, protocol: &str) {
33 self.protocol = protocol.to_string();
34 }
35
36 pub fn add_header(&mut self, name: &str, value: &str) {
38 self.headers.add(name.to_lowercase(), value.to_string());
39
40 if name.eq_ignore_ascii_case("content-type") {
42 self.content_type = value.to_string();
43 }
44 }
45
46 pub fn append_body(&mut self, data: &[u8]) {
48 self.body.extend_from_slice(data);
49 }
50
51 pub fn body_str(&self) -> String {
53 String::from_utf8_lossy(&self.body).to_string()
54 }
55
56 pub fn body_length(&self) -> usize {
58 self.body.len()
59 }
60}