index : static-web-server.git

ascending towards madness

author Jose Quintana <joseluisquintana20@gmail.com> 2021-05-17 22:59:54.0 +00:00:00
committer Jose Quintana <joseluisquintana20@gmail.com> 2021-05-17 22:59:54.0 +00:00:00
commit
84e011a348408b274549fa4ed67c7a985d34071f [patch]
tree
765fd7c36a23f382c4ad1cfd89b1eb14d1e2eeca
parent
b535297cac52e616644d1f927c3a6208b66fe854
download
84e011a348408b274549fa4ed67c7a985d34071f.tar.gz

refactor: proper body replacement during index html response



Diff

 src/static_files.rs |  9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/static_files.rs b/src/static_files.rs
index 5f925e8..f7d5901 100644
--- a/src/static_files.rs
+++ b/src/static_files.rs
@@ -197,14 +197,17 @@ async fn read_directory_entries(
    );

    let mut resp = Response::new(Body::empty());
    let len = page_str.len() as u64;
    resp.headers_mut()
        .typed_insert(ContentLength(page_str.len() as u64));

    // We skip the body for HEAD requests
    if is_head {
        resp.headers_mut().typed_insert(ContentLength(len));
        return Ok(resp);
    }

    Ok(Response::new(Body::from(page_str)))
    *resp.body_mut() = Body::from(page_str);

    Ok(resp)
}

fn parse_last_modified(modified: SystemTime) -> Result<time::Tm, Box<dyn std::error::Error>> {