9 Commits

Author SHA1 Message Date
0217f3f1f6 Release 1.0.0 2022-06-07 11:06:42 +08:00
c575147891 update deps 2022-06-07 10:25:45 +08:00
9d81ee2291 Merge pull request #2 from Tim-Paik/dependabot/cargo/regex-1.5.5
Bump regex from 1.5.4 to 1.5.5
2022-06-07 10:10:03 +08:00
d6f7ec2380 Merge pull request #1 from Tim-Paik/dependabot/cargo/crossbeam-utils-0.8.8
Bump crossbeam-utils from 0.8.6 to 0.8.8
2022-06-07 10:08:52 +08:00
b4c980db32 Bump regex from 1.5.4 to 1.5.5
Bumps [regex](https://github.com/rust-lang/regex) from 1.5.4 to 1.5.5.
- [Release notes](https://github.com/rust-lang/regex/releases)
- [Changelog](https://github.com/rust-lang/regex/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/regex/compare/1.5.4...1.5.5)

---
updated-dependencies:
- dependency-name: regex
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-06-06 22:02:34 +00:00
3953820138 Bump crossbeam-utils from 0.8.6 to 0.8.8
Bumps [crossbeam-utils](https://github.com/crossbeam-rs/crossbeam) from 0.8.6 to 0.8.8.
- [Release notes](https://github.com/crossbeam-rs/crossbeam/releases)
- [Changelog](https://github.com/crossbeam-rs/crossbeam/blob/master/CHANGELOG.md)
- [Commits](https://github.com/crossbeam-rs/crossbeam/compare/crossbeam-utils-0.8.6...crossbeam-utils-0.8.8)

---
updated-dependencies:
- dependency-name: crossbeam-utils
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-06-06 21:10:58 +00:00
92a69aa058 bug fixs 2022-06-06 18:23:20 +08:00
fa3ca96fb7 bug fixs 2022-06-06 14:27:56 +08:00
edc7fad925 add aarch64 support 2022-06-06 13:19:34 +08:00
4 changed files with 46 additions and 47 deletions

View File

@ -22,6 +22,8 @@ jobs:
os: ubuntu-latest
- target: x86_64-unknown-linux-musl
os: ubuntu-latest
- target: aarch64-apple-darwin
os: macos-latest
- target: x86_64-apple-darwin
os: macos-latest
- target: x86_64-pc-windows-msvc
@ -32,6 +34,7 @@ jobs:
- uses: taiki-e/upload-rust-binary-action@v1
with:
bin: srv
archive: $bin-$tag-$target
target: ${{ matrix.target }}
tar: unix
zip: windows

10
Cargo.lock generated
View File

@ -521,9 +521,9 @@ dependencies = [
[[package]]
name = "crossbeam-utils"
version = "0.8.6"
version = "0.8.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cfcae03edb34f947e64acdb1c33ec169824e20657e9ecb61cef6c8c74dcb8120"
checksum = "0bf124c720b7686e3c2663cf54062ab0f68a88af2fb6a030e87e30bf721fcb38"
dependencies = [
"cfg-if",
"lazy_static",
@ -1282,9 +1282,9 @@ dependencies = [
[[package]]
name = "regex"
version = "1.5.4"
version = "1.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461"
checksum = "1a11647b6b25ff05a515cb92c365cec08801e83423a235b51e231e1808747286"
dependencies = [
"aho-corasick",
"memchr",
@ -1513,7 +1513,6 @@ name = "srv"
version = "1.0.0-rc"
dependencies = [
"actix-files",
"actix-http",
"actix-web",
"actix-web-httpauth",
"chrono",
@ -1522,7 +1521,6 @@ dependencies = [
"lazy_static",
"log",
"mime_guess",
"regex",
"rustls",
"rustls-pemfile",
"serde",

View File

@ -3,11 +3,10 @@ authors = ["Tim_Paik <timpaikc@outlook.com>"]
description = "simple http server written in rust"
edition = "2018"
name = "srv"
version = "1.0.0-rc"
version = "1.0.0"
[dependencies]
actix-files = "0.6"
actix-http = "3.0"
actix-web = {version = "4.0", features = ["rustls"]}
actix-web-httpauth = "0.6"
chrono = "0.4"
@ -16,7 +15,6 @@ env_logger = "0.9"
lazy_static = "1.4"
log = "0.4"
mime_guess = "2.0"
regex = "1.5"
rustls = "0.20"
rustls-pemfile = "1.0"
serde = {version = "1.0", features = ["derive"]}

View File

@ -412,7 +412,6 @@ async fn main() -> std::io::Result<()> {
set_var("SPA", matches.is_present("spa").to_string());
set_var("DOTFILES", matches.is_present("dotfiles").to_string());
set_var("NOCACHE", matches.is_present("nocache").to_string());
set_var("COMPRESS", matches.is_present("compress").to_string());
if matches.is_present("quiet") {
set_var("RUST_LOG", "info,actix_web::middleware::logger=off");
@ -448,11 +447,7 @@ async fn main() -> std::io::Result<()> {
.value_of("address")
.unwrap_or("127.0.0.1")
.to_string();
let addr = format!(
"{}:{}",
ip,
matches.value_of("port").unwrap_or("8000")
);
let addr = format!("{}:{}", ip, matches.value_of("port").unwrap_or("8000"));
let url = format!(
"{}{}:{}",
if enable_tls {
@ -540,11 +535,7 @@ async fn main() -> std::io::Result<()> {
.value_of("address")
.unwrap_or("127.0.0.1")
.to_string();
let addr = format!(
"{}:{}",
ip,
matches.value_of("port").unwrap_or("8000")
);
let addr = format!("{}:{}", ip, matches.value_of("port").unwrap_or("8000"));
let url = format!(
"http://{}:{}/{}/index.html",
if ip == "0.0.0.0" { "127.0.0.1" } else { &ip },
@ -568,8 +559,9 @@ async fn main() -> std::io::Result<()> {
addr
};
let addr_copy = addr.clone();
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info"))
.format(|buf, record| {
.format(move |buf, record| {
let data = record.args().to_string();
let mut style = buf.style();
let blue = style.set_color(Color::Cyan);
@ -580,7 +572,8 @@ async fn main() -> std::io::Result<()> {
if record.target() == "actix_web::middleware::logger" {
let data: Vec<&str> = data.splitn(5, '^').collect();
let time = blue.value(
chrono::NaiveDateTime::from_str(data[0])
data[0]
.parse::<chrono::DateTime<chrono::Utc>>()
.unwrap()
.format("%Y/%m/%d %H:%M:%S")
.to_string(),
@ -612,30 +605,27 @@ async fn main() -> std::io::Result<()> {
time, ipaddr, status_code, process_time, content
);
} else if record.target() == "actix_server::builder" {
if data.starts_with("SIGINT received, exiting") {
return writeln!(buf, "\r{}", green.value("[INFO] SIGINT received, exiting"));
// Add '\r' to remove the input ^C
} else {
let data = data.replace("actix-web-service-", "");
let re1 = regex::Regex::new("Starting (.*) workers").unwrap();
if re1.is_match(&data) {
return Ok(());
}
let re2 = regex::Regex::new("Starting \"(.*)\" service on (.*)").unwrap();
if re2.is_match(&data) {
let addr = re2
.captures(&data)
.unwrap()
.get(1)
.map_or("", |m| m.as_str());
let data = format!(
"[INFO] Serving {} on {}",
var("ROOT").unwrap_or_else(|_| ".".to_string()),
addr
);
return writeln!(buf, "\r{}", green.value(data));
}
if data.starts_with("Starting ") && data.ends_with(" workers") {
return Ok(());
}
} else if record.target() == "actix_server::server" {
if data == "Actix runtime found; starting in Actix runtime" {
let data = format!(
"[INFO] Serving {} on {}",
var("ROOT").unwrap_or_else(|_| ".".to_string()),
addr_copy
);
return writeln!(buf, "\r{}", green.value(data));
}
if data == "SIGINT received; starting forced shutdown" {
return writeln!(buf, "\r{}", green.value("[INFO] SIGINT received; starting forced shutdown"));
// Add '\r' to remove the input ^C
}
return Ok(());
} else if record.target() == "actix_server::worker"
|| record.target() == "actix_server::accept"
{
return Ok(());
}
if data.starts_with("[ERROR]")
|| data.starts_with("TLS alert")
@ -722,8 +712,18 @@ async fn main() -> std::io::Result<()> {
let key = &mut BufReader::new(
std::fs::File::open(Path::new(matches.value_of("key").unwrap())).unwrap(),
);
let cert = rustls_pemfile::certs(cert).unwrap().iter().map(|x| rustls::Certificate(x.to_vec())).collect::<Vec<_>>();
let key = rustls::PrivateKey(rustls_pemfile::pkcs8_private_keys(key).unwrap().first().expect("no private key found").to_owned());
let cert = rustls_pemfile::certs(cert)
.unwrap()
.iter()
.map(|x| rustls::Certificate(x.to_vec()))
.collect::<Vec<_>>();
let key = rustls::PrivateKey(
rustls_pemfile::pkcs8_private_keys(key)
.unwrap()
.first()
.expect("no private key found")
.to_owned(),
);
let config = rustls::ServerConfig::builder()
.with_safe_defaults()
.with_no_client_auth()