Set Date and Server headers at beginning
This commit is contained in:
		@@ -181,11 +181,20 @@ impl Request {
 | 
			
		||||
 | 
			
		||||
impl Response {
 | 
			
		||||
    pub fn new() -> Response {
 | 
			
		||||
        Response {
 | 
			
		||||
        let mut res = Response {
 | 
			
		||||
            version: "1.1".to_string(),
 | 
			
		||||
            status: Status::from_code(200).unwrap(),
 | 
			
		||||
            header_fields: Vec::new(),
 | 
			
		||||
        }
 | 
			
		||||
        };
 | 
			
		||||
        res.add_header("Server", "Locutus");
 | 
			
		||||
        res.add_header(
 | 
			
		||||
            "Date",
 | 
			
		||||
            chrono::Utc::now()
 | 
			
		||||
                .format("%a, %d %b %Y %H:%M:%S GMT")
 | 
			
		||||
                .to_string()
 | 
			
		||||
                .as_str(),
 | 
			
		||||
        );
 | 
			
		||||
        res
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn status(&mut self, status_code: u16) {
 | 
			
		||||
@@ -217,15 +226,6 @@ impl Response {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    pub fn send(&mut self, stream: &mut Stream) -> Result<(), std::io::Error> {
 | 
			
		||||
        self.add_header("Server", "Locutus");
 | 
			
		||||
        self.add_header(
 | 
			
		||||
            "Date",
 | 
			
		||||
            chrono::Utc::now()
 | 
			
		||||
                .format("%a, %d %b %Y %H:%M:%S GMT")
 | 
			
		||||
                .to_string()
 | 
			
		||||
                .as_str(),
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        let mut buf = None;
 | 
			
		||||
        if let None = self.find_header("Content-Length") {
 | 
			
		||||
            let new_buf = self.format_default_response();
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user