diff --git a/Cargo.lock b/Cargo.lock index d5ef80715692996c48f8afb09a862c7b65643af1..991ae2b59638e7ec2ce962f227ba619e12f043af 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -816,7 +816,7 @@ dependencies = [ [[package]] name = "simple-http-server" -version = "0.5.0" +version = "0.6.0" dependencies = [ "chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/Cargo.toml b/Cargo.toml index 8aae609d0ebdd8f7243d80a6add7f3ceacd2dadf..6183e85c62b562d2b551584e5742cce196513a4b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "simple-http-server" -version = "0.5.0" +version = "0.6.0" authors = ["thewawar <thewawar@gmail.com>"] license = "MIT" description = "Simple HTTP server" diff --git a/README.md b/README.md index 74d680dc78800f28cc52a6eee386cddec8dfb58d..ca21867346dd1a4af7805a9da8134f83b88861b5 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ ### Command Line Arguments ``` -Simple HTTP(s) Server 0.4.7 +Simple HTTP(s) Server 0.6.0 USAGE: simple-http-server [FLAGS] [OPTIONS] [--] [root] @@ -22,21 +22,23 @@ FLAGS: -V, --version Prints version information OPTIONS: - -a, --auth <auth> HTTP Basic Auth (username:password) - --cert <cert> TLS/SSL certificate (pkcs#12 format) - --certpass <certpass> TLS/SSL certificate password - -c, --compress <compress>... Enable file compression: gzip/deflate - Example: -c=js,d.ts - Note: disabled on partial request! - --ip <ip> IP address to bind [default: 0.0.0.0] - -p, --port <port> Port number [default: 8000] - --redirect <redirect> takes a URL to redirect to using HTTP 301 Moved Permanently - -t, --threads <threads> How many worker threads [default: 3] - --try-file <PATH> serve this file (server root relative) in place of missing files (useful for single - page apps) [aliases: try-file-404] + -a, --auth <auth> HTTP Basic Auth (username:password) + --cert <cert> TLS/SSL certificate (pkcs#12 format) + --certpass <certpass> TLS/SSL certificate password + -c, --compress <compress>... + Enable file compression: gzip/deflate + Example: -c=js,d.ts + Note: disabled on partial request! + --ip <ip> IP address to bind [default: 0.0.0.0] + -p, --port <port> Port number [default: 8000] + --redirect <redirect> takes a URL to redirect to using HTTP 301 Moved Permanently + -t, --threads <threads> How many worker threads [default: 3] + --try-file <PATH> + serve this file (server root relative) in place of missing files (useful for single page apps) [aliases: + try-file-404] + -l, --upload-size-limit <upload_size_limit> Upload file size limit [bytes] [default: 8000000] + -ARGS: - <root> Root directory ``` # Installation diff --git a/src/main.rs b/src/main.rs index 184c9952077242cdb8513dea0e09b30fe91ff1f2..9d161b8be3191b5a9140c9208229337efcbe1c01 100644 --- a/src/main.rs +++ b/src/main.rs @@ -104,6 +104,18 @@ fn main() { long("certpass") .takes_value(true) .help("TLS/SSL certificate password")) + .arg(clap::Arg::with_name("upload_size_limit") + .short("l") + .long("upload-size-limit") + .takes_value(true) + .default_value("8000000") + .value_name("NUM") + .validator(|s| { + match s.parse::<u64>() { + Ok(_) => Ok(()), + Err(e) => Err(e.description().to_string()) + }}) + .help("Upload file size limit [bytes]")) .arg(clap::Arg::with_name("ip") .long("ip") .takes_value(true) @@ -206,6 +218,11 @@ fn main() { let cors = matches.is_present("cors"); let ip = matches.value_of("ip").unwrap(); let port = matches.value_of("port").unwrap().parse::<u16>().unwrap(); + let upload_size_limit = matches + .value_of("upload_size_limit") + .unwrap() + .parse::<u64>() + .unwrap(); let auth = matches.value_of("auth"); let compress = matches.values_of_lossy("compress"); let threads = matches.value_of("threads").unwrap().parse::<u8>().unwrap(); @@ -272,6 +289,7 @@ fn main() { .clone() .map(|exts| exts.iter().map(|s| format!(".{}", s)).collect()), try_file_404: try_file_404.map(PathBuf::from), + upload_size_limit, }); if cors { chain.link_around(CorsMiddleware::with_allow_any()); @@ -331,6 +349,7 @@ struct MainHandler { sort: bool, compress: Option<Vec<String>>, try_file_404: Option<PathBuf>, + upload_size_limit: u64, } impl Handler for MainHandler { @@ -409,7 +428,7 @@ impl MainHandler { // Fetching all data and processing it. // save().temp() reads the request fully, parsing all fields and saving all files // in a new temporary directory under the OS temporary directory. - match multipart.save().temp() { + match multipart.save().size_limit(self.upload_size_limit).temp() { SaveResult::Full(entries) => { for (_, fields) in entries.fields { for field in fields {