Skip to content
Snippets Groups Projects
Unverified Commit 3483193e authored by LinFeng Qian's avatar LinFeng Qian Committed by GitHub
Browse files

Merge pull request #41 from michelk/add-upload-file-size-cmd-arg

add command-line option to specify upload file size limit
parents 67fc4854 21301a4b
No related branches found
No related tags found
No related merge requests found
...@@ -816,7 +816,7 @@ dependencies = [ ...@@ -816,7 +816,7 @@ dependencies = [
[[package]] [[package]]
name = "simple-http-server" name = "simple-http-server"
version = "0.5.0" version = "0.6.0"
dependencies = [ dependencies = [
"chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", "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)", "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
......
[package] [package]
name = "simple-http-server" name = "simple-http-server"
version = "0.5.0" version = "0.6.0"
authors = ["thewawar <thewawar@gmail.com>"] authors = ["thewawar <thewawar@gmail.com>"]
license = "MIT" license = "MIT"
description = "Simple HTTP server" description = "Simple HTTP server"
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
### Command Line Arguments ### Command Line Arguments
``` ```
Simple HTTP(s) Server 0.4.7 Simple HTTP(s) Server 0.6.0
USAGE: USAGE:
simple-http-server [FLAGS] [OPTIONS] [--] [root] simple-http-server [FLAGS] [OPTIONS] [--] [root]
...@@ -22,21 +22,23 @@ FLAGS: ...@@ -22,21 +22,23 @@ FLAGS:
-V, --version Prints version information -V, --version Prints version information
OPTIONS: OPTIONS:
-a, --auth <auth> HTTP Basic Auth (username:password) -a, --auth <auth> HTTP Basic Auth (username:password)
--cert <cert> TLS/SSL certificate (pkcs#12 format) --cert <cert> TLS/SSL certificate (pkcs#12 format)
--certpass <certpass> TLS/SSL certificate password --certpass <certpass> TLS/SSL certificate password
-c, --compress <compress>... Enable file compression: gzip/deflate -c, --compress <compress>...
Example: -c=js,d.ts Enable file compression: gzip/deflate
Note: disabled on partial request! Example: -c=js,d.ts
--ip <ip> IP address to bind [default: 0.0.0.0] Note: disabled on partial request!
-p, --port <port> Port number [default: 8000] --ip <ip> IP address to bind [default: 0.0.0.0]
--redirect <redirect> takes a URL to redirect to using HTTP 301 Moved Permanently -p, --port <port> Port number [default: 8000]
-t, --threads <threads> How many worker threads [default: 3] --redirect <redirect> takes a URL to redirect to using HTTP 301 Moved Permanently
--try-file <PATH> serve this file (server root relative) in place of missing files (useful for single -t, --threads <threads> How many worker threads [default: 3]
page apps) [aliases: try-file-404] --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 # Installation
......
...@@ -104,6 +104,18 @@ fn main() { ...@@ -104,6 +104,18 @@ fn main() {
long("certpass") long("certpass")
.takes_value(true) .takes_value(true)
.help("TLS/SSL certificate password")) .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") .arg(clap::Arg::with_name("ip")
.long("ip") .long("ip")
.takes_value(true) .takes_value(true)
...@@ -206,6 +218,11 @@ fn main() { ...@@ -206,6 +218,11 @@ fn main() {
let cors = matches.is_present("cors"); let cors = matches.is_present("cors");
let ip = matches.value_of("ip").unwrap(); let ip = matches.value_of("ip").unwrap();
let port = matches.value_of("port").unwrap().parse::<u16>().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 auth = matches.value_of("auth");
let compress = matches.values_of_lossy("compress"); let compress = matches.values_of_lossy("compress");
let threads = matches.value_of("threads").unwrap().parse::<u8>().unwrap(); let threads = matches.value_of("threads").unwrap().parse::<u8>().unwrap();
...@@ -272,6 +289,7 @@ fn main() { ...@@ -272,6 +289,7 @@ fn main() {
.clone() .clone()
.map(|exts| exts.iter().map(|s| format!(".{}", s)).collect()), .map(|exts| exts.iter().map(|s| format!(".{}", s)).collect()),
try_file_404: try_file_404.map(PathBuf::from), try_file_404: try_file_404.map(PathBuf::from),
upload_size_limit,
}); });
if cors { if cors {
chain.link_around(CorsMiddleware::with_allow_any()); chain.link_around(CorsMiddleware::with_allow_any());
...@@ -331,6 +349,7 @@ struct MainHandler { ...@@ -331,6 +349,7 @@ struct MainHandler {
sort: bool, sort: bool,
compress: Option<Vec<String>>, compress: Option<Vec<String>>,
try_file_404: Option<PathBuf>, try_file_404: Option<PathBuf>,
upload_size_limit: u64,
} }
impl Handler for MainHandler { impl Handler for MainHandler {
...@@ -409,7 +428,7 @@ impl MainHandler { ...@@ -409,7 +428,7 @@ impl MainHandler {
// Fetching all data and processing it. // Fetching all data and processing it.
// save().temp() reads the request fully, parsing all fields and saving all files // save().temp() reads the request fully, parsing all fields and saving all files
// in a new temporary directory under the OS temporary directory. // 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) => { SaveResult::Full(entries) => {
for (_, fields) in entries.fields { for (_, fields) in entries.fields {
for field in fields { for field in fields {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment