ilmen_http/http/configuration/
configuration.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use crate::http::security::service::SecurityProtocol;


#[derive(Clone)]
pub struct Config {
    port: Port,
    ip: Ip,
    security: SecurityProtocol,
    request_size: usize
}


type Port = i32;
type Ip = String;

impl Default for Config {
    fn default() -> Self {
        Self { 
            port: 7878, 
            ip: "0.0.0.0".to_string(),
            security: SecurityProtocol::None,
            request_size: 10485760
        }
    }
}

impl Config {
    pub fn adresse(&self) -> String {
        format!("{}:{}", self.ip, self.port)
    }

    pub fn security(&self) -> SecurityProtocol {
        self.security.clone()
    }

    pub fn request_size(&self) -> usize {
        self.request_size
    }

    pub fn initialize() -> Config {
        Config::default()
    }

    pub fn with_request_size(&mut self, size: &usize) -> &mut Self {
        self.request_size = *size;
        self
    }

    pub fn with_security(&mut self, security: &SecurityProtocol) -> &mut Self {
        self.security = security.clone();
        self
    }

    pub fn with_adresse(&mut self, ip: &str, port: &Port) ->  &mut Self {
        self.ip = ip.to_string();
        self.port = *port;
        self
    }
}