Skip to content

Commit

Permalink
Merge branch 'release/0.7.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
s3rius committed Nov 1, 2023
2 parents 3206250 + 70c179c commit b0c8f5e
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rustus"
version = "0.7.4"
version = "0.7.5"
edition = "2021"
description = "TUS protocol implementation written in Rust."
keywords = ["tus", "server", "actix-web"]
Expand Down
2 changes: 2 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Also you can disable access log for `/health` endpoint, by using `--disable-heal
--cors "my.*.domain.com,your.*.domain.com" \
--disable-health-access-log \
--allow-empty
--max-file-size 10000000
```

=== "ENV"
Expand All @@ -58,6 +59,7 @@ Also you can disable access log for `/health` endpoint, by using `--disable-heal
export RUSTUS_CORS="my.*.domain.com,your.*.domain.com"
export RUSTUS_DISABLE_HEALTH_ACCESS_LOG="true"
export RUSTUS_ALLOW_EMPTY="true"
export RUSTUS_MAX_FILE_SIZE="10000000"

rustus
```
Expand Down
6 changes: 6 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,12 @@ pub struct RustusConf {
#[arg(long, env = "RUSTUS_REMOVE_PARTS")]
pub remove_parts: bool,

/// Maximum size of file that can be uploaded.
///
/// If not set, file size is unlimited.
#[arg(long, env = "RUSTUS_MAX_FILE_SIZE")]
pub max_file_size: Option<usize>,

#[command(flatten)]
pub storage_opts: StorageOptions,

Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ fn create_cors(origins: Vec<String>, additional_headers: Vec<String>) -> Cors {
"X-Request-ID",
"X-HTTP-Method-Override",
])
.allowed_headers(additional_headers.into_iter())
.allowed_headers(additional_headers)
.expose_headers(vec![
"Location",
"Tus-Version",
Expand Down
2 changes: 1 addition & 1 deletion src/notifiers/models/message_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl From<&FileInfo> for TusdFileInfo {
/// arrays.
fn headers_to_value_map(headers: &HeaderMap, use_arrays: bool) -> HashMap<String, Value> {
let mut headers_map = HashMap::new();
for (name, value) in headers.iter() {
for (name, value) in headers {
if let Ok(header_val) = value.to_str().map(String::from) {
if use_arrays {
headers_map.insert(
Expand Down
20 changes: 20 additions & 0 deletions src/protocol/creation/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ pub async fn create_file(
return Ok(HttpResponse::BadRequest().body("Upload-Length header is required"));
}

if state.config.max_file_size.is_some() && state.config.max_file_size < length {
return Ok(HttpResponse::BadRequest().body(format!(
"Upload-Length should be less than or equal to {}",
state.config.max_file_size.unwrap()
)));
}

let meta = get_metadata(&request);

let file_id = uuid::Uuid::new_v4().to_string();
Expand Down Expand Up @@ -561,4 +568,17 @@ mod tests {
let resp = call_service(&mut rustus, request).await;
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
}

#[actix_rt::test]
async fn max_file_size_exceeded() {
let mut state = State::test_new().await;
state.config.max_file_size = Some(1000);
let mut rustus = get_service(state.clone()).await;
let request = TestRequest::post()
.uri(state.config.test_url().as_str())
.insert_header(("Upload-Length", 1001))
.to_request();
let resp = call_service(&mut rustus, request).await;
assert_eq!(resp.status(), StatusCode::BAD_REQUEST);
}
}

0 comments on commit b0c8f5e

Please sign in to comment.