This commit is contained in:
Mateusz Gruszczyński committed 2026-10-31 23:42:58 +01:00
1 parent 2c03fcf248
commit d3b492874b
95 files changed
+1628 -743

No files matched your search

-1
View File
@@ -300,7 +300,6 @@ pub(super) fn parse_cgi_headers(value: &[u8]) -> Result<(StatusCode, HeaderMap)>
.context("PHP-FPM returned a malformed CGI header")?;
if name.eq_ignore_ascii_case("status") {
let code = value
.trim()
.split_whitespace()
.next()
.context("PHP-FPM returned an empty Status header")?
+6 -6
View File
@@ -217,24 +217,24 @@ fn matching_scopes<'a>(compiled: &'a Compiled, path: &str) -> Vec<&'a Scope> {
pub fn denied(compiled: Option<&Compiled>, path: &str) -> bool {
let Some(compiled) = compiled else { return false; };
matching_scopes(compiled, path).into_iter().filter_map(|scope| scope.deny_all).last().unwrap_or(false)
matching_scopes(compiled, path).into_iter().filter_map(|scope| scope.deny_all).next_back().unwrap_or(false)
}
pub fn index_files<'a>(compiled: Option<&'a Compiled>, directory_components: &[String], fallback: &'a [String]) -> &'a [String] {
let Some(compiled) = compiled else { return fallback; };
compiled.scopes.iter().filter(|scope| scope_matches(scope, directory_components)).filter_map(|scope| scope.directory_index.as_deref()).last().unwrap_or(fallback)
compiled.scopes.iter().filter(|scope| scope_matches(scope, directory_components)).filter_map(|scope| scope.directory_index.as_deref()).next_back().unwrap_or(fallback)
}
pub fn directory_listing(compiled: Option<&Compiled>, directory_components: &[String], fallback: bool) -> bool {
let Some(compiled) = compiled else { return fallback; };
compiled.scopes.iter().filter(|scope| scope_matches(scope, directory_components)).filter_map(|scope| scope.directory_listing).last().unwrap_or(fallback)
compiled.scopes.iter().filter(|scope| scope_matches(scope, directory_components)).filter_map(|scope| scope.directory_listing).next_back().unwrap_or(fallback)
}
pub fn mime_type(compiled: Option<&Compiled>, path: &Path) -> Option<HeaderValue> {
let compiled = compiled?;
let extension = path.extension()?.to_str()?.to_ascii_lowercase();
let path_text = path.to_string_lossy();
matching_scopes(compiled, &path_text).into_iter().filter_map(|scope| scope.mime_types.get(&extension).cloned()).last()
matching_scopes(compiled, &path_text).into_iter().filter_map(|scope| scope.mime_types.get(&extension).cloned()).next_back()
}
pub fn php_extension(compiled: Option<&Compiled>, path: &Path) -> bool {
@@ -345,8 +345,8 @@ async fn condition_matches(condition: &RewriteCondition, service: &CompiledServi
ConditionMatcher::Regex { regex, negate } => {
if let Some(captures) = regex.captures(&value) {
let values = captures.iter().map(|value| value.map(|v| v.as_str().to_owned()).unwrap_or_default()).collect::<Vec<_>>();
(if *negate { false } else { true }, if *negate { Vec::new() } else { values })
} else { (if *negate { true } else { false }, Vec::new()) }
(!*negate, if *negate { Vec::new() } else { values })
} else { (*negate, Vec::new()) }
}
}
}
+2 -2
View File
@@ -10,8 +10,8 @@ mod security;
mod serve;
pub use config::{
CacheRule, CompiledService, Hardening, Php, PhpFpmProfile, Precompressed, RewriteRule, Service,
SymlinkPolicy, SendfileMode,
CacheRule, CompiledService, Hardening, Php, PhpFpmProfile, Precompressed, RewriteRule,
SendfileMode, Service, SymlinkPolicy,
};
pub use htaccess::Config as HtaccessConfig;
pub use request::RequestContext;
+5 -7
View File
@@ -217,13 +217,11 @@ async fn file_response_inner(
));
return response;
}
if start != 0 {
if file.seek(std::io::SeekFrom::Start(start)).await.is_err() {
return status_response(
StatusCode::INTERNAL_SERVER_ERROR,
"RustProxy: Web Server seek failed\n",
);
}
if start != 0 && file.seek(std::io::SeekFrom::Start(start)).await.is_err() {
return status_response(
StatusCode::INTERNAL_SERVER_ERROR,
"RustProxy: Web Server seek failed\n",
);
}
let stream = ReaderStream::with_capacity(file.take(body_length), stream_capacity);
*response.body_mut() = Body::new(file_body::FileBody::new(stream, body_length));
+1 -4
View File
@@ -412,10 +412,7 @@ async fn too_many_byte_ranges_are_rejected() {
let tmp = TempDir::new().unwrap();
std::fs::write(tmp.path().join("file.txt"), b"0123456789").unwrap();
let service = service(tmp.path(), false);
let ranges = std::iter::repeat("0-0")
.take(17)
.collect::<Vec<_>>()
.join(",");
let ranges = std::iter::repeat_n("0-0", 17).collect::<Vec<_>>().join(",");
let mut ranged = request(Method::GET, "/file.txt");
ranged
.headers_mut()