use fire::fs::StaticFiles;
use fire::Body;
use fire_http as fire;
#[macro_use]
mod util;
#[tokio::test]
async fn read_file() {
const CSS: StaticFiles = StaticFiles::new("/css", "./examples/www/css");
let addr = spawn_server!(|builder| {
builder.add_route(CSS);
});
make_request!("GET", addr, "/css")
.await
.assert_status(404)
.assert_not_header("cache-control")
.assert_not_header("content-type")
.assert_header("content-length", "0");
let file_ctn = include_str!("./../examples/www/css/style.css");
let res = make_request!("GET", addr, "/css/style.css")
.await
.assert_status(200)
.assert_header("content-length", file_ctn.len().to_string())
.assert_header("content-type", "text/css; charset=utf-8")
.assert_header("cache-control", "max-age=86400, public");
let etag = res.header("etag").expect("etag not found");
make_request!("GET", addr, "/css/style.css", |req| {
req.header("if-none-match", etag)
.body(Body::new().into_http_body())
.expect("could not build request")
})
.await
.assert_status(304)
.assert_header("cache-control", "max-age=86400, public")
.assert_not_header("content-type");
}