Normalizing paths now works as intended
parent
1e0fd05969
commit
bda49d53c4
18
src/proxy.rs
18
src/proxy.rs
|
@ -6,7 +6,9 @@ use reqwest::{
|
||||||
Method as ReqMethod,
|
Method as ReqMethod,
|
||||||
};
|
};
|
||||||
use rocket::{
|
use rocket::{
|
||||||
|
response::Redirect,
|
||||||
http::uri::Segments,
|
http::uri::Segments,
|
||||||
|
http::ext::IntoOwned,
|
||||||
fs::Options,
|
fs::Options,
|
||||||
data::ToByteUnit,
|
data::ToByteUnit,
|
||||||
http::{Method, Status},
|
http::{Method, Status},
|
||||||
|
@ -95,13 +97,23 @@ impl Handler for ProxyServer
|
||||||
return Outcome::Failure(Status::BadRequest);
|
return Outcome::Failure(Status::BadRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
let path_val = path.unwrap();
|
let path = path.unwrap();
|
||||||
let path_str = path_val.to_str(); // Unwrap is safe because we check for is_none() beforehand
|
let path_str = path.to_str(); // Unwrap is safe because we check for is_none() beforehand
|
||||||
|
|
||||||
if path_str.is_none() {
|
if path_str.is_none() {
|
||||||
return Outcome::Failure(Status::BadRequest);
|
return Outcome::Failure(Status::BadRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if self.options.contains(Options::NormalizeDirs) && !req.uri().path().ends_with('/') {
|
||||||
|
let normal = req.uri().map_path(|p| format!("{}/", p))
|
||||||
|
.expect("adding a trailing slash to a known good path => valid path")
|
||||||
|
.into_owned();
|
||||||
|
|
||||||
|
return Outcome::from_or_forward(req, data, Redirect::permanent(normal));
|
||||||
|
}
|
||||||
|
|
||||||
|
let path_str = path_str.unwrap();
|
||||||
|
|
||||||
let query_part = req
|
let query_part = req
|
||||||
.uri()
|
.uri()
|
||||||
.query()
|
.query()
|
||||||
|
@ -110,7 +122,7 @@ impl Handler for ProxyServer
|
||||||
let url = format!(
|
let url = format!(
|
||||||
"{}{}{}",
|
"{}{}{}",
|
||||||
self.root,
|
self.root,
|
||||||
path_str.unwrap(), // Unwrap is safe because we check for is_none() beforehand
|
path_str,
|
||||||
query_part
|
query_part
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Reference in New Issue