Merge pull request #122 from rustfs/fix/content-length

Fix/content length
This commit is contained in:
weisd
2024-11-09 21:25:22 +08:00
committed by GitHub
6 changed files with 63 additions and 27 deletions
Generated
+1
View File
@@ -2135,6 +2135,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"admin", "admin",
"async-trait", "async-trait",
"atoi",
"axum", "axum",
"bytes", "bytes",
"clap", "clap",
+11 -2
View File
@@ -67,7 +67,9 @@ impl Erasure {
); );
let mut total: usize = 0; let mut total: usize = 0;
loop { loop {
if total_size > 0 {
let new_len = { let new_len = {
let remain = total_size - total; let remain = total_size - total;
if remain > self.block_size { if remain > self.block_size {
@@ -77,7 +79,7 @@ impl Erasure {
} }
}; };
if new_len == 0 { if new_len == 0 && total > 0 {
break; break;
} }
@@ -93,8 +95,8 @@ impl Erasure {
} }
} }
}; };
total += self.buf.len(); total += self.buf.len();
}
let blocks = self.encode_data(&self.buf)?; let blocks = self.encode_data(&self.buf)?;
let mut errs = Vec::new(); let mut errs = Vec::new();
@@ -112,6 +114,9 @@ impl Erasure {
let none_count = errs.iter().filter(|&x| x.is_none()).count(); let none_count = errs.iter().filter(|&x| x.is_none()).count();
if none_count >= write_quorum { if none_count >= write_quorum {
if total_size == 0 {
break;
}
continue; continue;
} }
@@ -119,6 +124,10 @@ impl Erasure {
warn!("Erasure encode errs {:?}", &errs); warn!("Erasure encode errs {:?}", &errs);
return Err(err); return Err(err);
} }
if total_size == 0 {
break;
}
} }
Ok(total) Ok(total)
+1 -1
View File
@@ -1,4 +1,4 @@
use std::path::{Path, PathBuf}; use std::path::PathBuf;
const GLOBAL_DIR_SUFFIX: &str = "__XLDIR__"; const GLOBAL_DIR_SUFFIX: &str = "__XLDIR__";
+1
View File
@@ -1,2 +1,3 @@
pub const AMZ_OBJECT_TAGGING: &str = "X-Amz-Tagging"; pub const AMZ_OBJECT_TAGGING: &str = "X-Amz-Tagging";
pub const AMZ_STORAGE_CLASS: &str = "x-amz-storage-class"; pub const AMZ_STORAGE_CLASS: &str = "x-amz-storage-class";
pub const AMZ_DECODED_CONTENT_LENGTH: &str = "X-Amz-Decoded-Content-Length";
+1
View File
@@ -57,6 +57,7 @@ router = { version = "0.0.1", path = "../router" }
matchit = "0.8.4" matchit = "0.8.4"
shadow-rs = "0.35.2" shadow-rs = "0.35.2"
const-str = { version = "0.5.7", features = ["std", "proc"] } const-str = { version = "0.5.7", features = ["std", "proc"] }
atoi = "2.0.0"
[build-dependencies] [build-dependencies]
prost-build.workspace = true prost-build.workspace = true
+26 -2
View File
@@ -588,7 +588,19 @@ impl S3 for FS {
let Some(body) = body else { return Err(s3_error!(IncompleteBody)) }; let Some(body) = body else { return Err(s3_error!(IncompleteBody)) };
let Some(content_length) = content_length else { return Err(s3_error!(IncompleteBody)) }; let content_length = match content_length {
Some(c) => c,
None => {
if let Some(val) = req.headers.get(xhttp::AMZ_DECODED_CONTENT_LENGTH) {
match atoi::atoi::<i64>(val.as_bytes()) {
Some(x) => x,
None => return Err(s3_error!(UnexpectedContent)),
}
} else {
return Err(s3_error!(UnexpectedContent));
}
}
};
let mut reader = PutObjReader::new(body, content_length as usize); let mut reader = PutObjReader::new(body, content_length as usize);
@@ -677,7 +689,19 @@ impl S3 for FS {
// let upload_id = // let upload_id =
let body = body.ok_or_else(|| s3_error!(IncompleteBody))?; let body = body.ok_or_else(|| s3_error!(IncompleteBody))?;
let content_length = content_length.ok_or_else(|| s3_error!(IncompleteBody))?; let content_length = match content_length {
Some(c) => c,
None => {
if let Some(val) = req.headers.get(xhttp::AMZ_DECODED_CONTENT_LENGTH) {
match atoi::atoi::<i64>(val.as_bytes()) {
Some(x) => x,
None => return Err(s3_error!(UnexpectedContent)),
}
} else {
return Err(s3_error!(UnexpectedContent));
}
}
};
// mc cp step 4 // mc cp step 4
let mut data = PutObjReader::new(body, content_length as usize); let mut data = PutObjReader::new(body, content_length as usize);