1.0.0-rc.4 add readme and 403 connection close bug fix

This commit is contained in:
Tim-Paik 2021-08-25 20:41:59 +08:00
parent dda85e927a
commit 2cda2c0a45
3 changed files with 115 additions and 84 deletions

View File

@ -1 +1,35 @@
# Srv Dev Server
This is a simple HTTP Server for use in a development environment, inspired by [simple-http-server](https://github.com/TheWaWaR/simple-http-server) and [caddy2](https://github.com/caddyserver/caddy), and it is also a practice project for me to learn rust.
### Screenshot
![screenshot](screenshot.png)
### Built With
- ~~[rocket](https://github.com/SergioBenitez/Rocket)~~ Framework used in previous versions
- [clap](https://github.com/clap-rs/clap) Provide command line parameter analysis
- [tera](https://github.com/Keats/tera) Provide template support
- [actix-web](https://github.com/actix/actix-web) Main frame
- [actix-files](https://github.com/actix/actix-web/tree/master/actix-files) Provide static resources
- [actix-web-httpauth](https://github.com/actix/actix-extras/tree/master/actix-web-httpauth) Provide authentication
- [rustls](https://github.com/rustls/rustls) Provide TLS and HTTP/2 support
- [env_logger](https://github.com/env-logger-rs/env_logger) Provide log output
## Features
- Automatic generation of directory listings (default enabled)
- Relative path/absolute path/support
- Brotli/Gzip/Deflate streaming compression support (default disabled, disables Content-length and segmented downloads when enabled)
- Control whether dotfiles are displayed and can be accessed (default disabled)
- HTTP cache support, 304 support, Last-Modified/ETag support, of course you can also turn off cache
- Clearly colored organized log
- Disable access logging or disable all logging support
- Automatically open default browser (default disabled)
- Single-Page Application mode (always serve /index.html when the file is not found)
- Custom listening address (default 0.0.0.0) Custom listening port number (default 8000)
- HTTP Basic Authentication Support
- TLS/SSL support, HTTP/2 support
- One click to enable CORS, custom CORS header support
- cargo doc support

BIN
screenshot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 164 KiB

View File

@ -599,9 +599,7 @@ async fn main() -> std::io::Result<()> {
addr
};
env_logger::Builder::from_env(
env_logger::Env::default().default_filter_or("info"),
)
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info"))
.format(|buf, record| {
let data = record.args().to_string();
let mut style = buf.style();
@ -684,11 +682,6 @@ async fn main() -> std::io::Result<()> {
http::header::ContentEncoding::Identity
};
let app = App::new()
.wrap(middleware::Compress::new(compress))
.wrap(middleware::Condition::new(
var("ENABLE_AUTH").unwrap_or("false".to_string()) == "true",
actix_web_httpauth::middleware::HttpAuthentication::basic(validator),
))
.wrap_fn(|req, srv| {
let paths = PathBuf::from_str(req.path()).unwrap_or(PathBuf::default());
let mut isdotfile = false;
@ -699,7 +692,7 @@ async fn main() -> std::io::Result<()> {
}
let fut = srv.call(req);
async move {
Ok(fut.await?.map_body(|head, mut body| {
Ok(fut.await?.map_body(|head, body| {
if var("NOCACHE").unwrap_or("false".to_string()) == "true" {
head.headers_mut().insert(
http::header::CACHE_CONTROL,
@ -717,13 +710,17 @@ async fn main() -> std::io::Result<()> {
{
head.status = http::StatusCode::FORBIDDEN;
*head.headers_mut() = http::HeaderMap::new();
let _ = body.take_body();
head.set_connection_type(http::ConnectionType::Close);
return dev::ResponseBody::Other(actix_web::body::Body::None);
}
body
}))
}
})
.wrap(middleware::Compress::new(compress))
.wrap(middleware::Condition::new(
var("ENABLE_AUTH").unwrap_or("false".to_string()) == "true",
actix_web_httpauth::middleware::HttpAuthentication::basic(validator),
))
.wrap(middleware::Logger::new("%t^%a^%s^%D^%r"));
let files = fs::Files::new("/", var("ROOT").unwrap_or(".".to_string()))
.use_hidden_files()