v0.34.0_10
This commit is contained in:
1 parent
8c4cbc583f
commit
dd2502dd11
13 files changed
+389
-113
No files matched your search
@@ -0,0 +1,43 @@
|
||||
// Observation has already validated routing identity. Transfer it to the
|
||||
// forward handler instead of repeating hostname parsing and percent decoding.
|
||||
#[derive(Clone)]
|
||||
struct ValidatedRoutingIdentity {
|
||||
original_host: HeaderValue,
|
||||
host: String,
|
||||
decoded_path: Option<String>,
|
||||
}
|
||||
#[derive(Clone)]
|
||||
struct SelectedRouteContext {
|
||||
frontend: Option<Arc<crate::config::CompiledFrontend>>,
|
||||
route: Option<Arc<crate::config::CompiledRoute>>,
|
||||
validated: Option<ValidatedRoutingIdentity>,
|
||||
}
|
||||
/// Transfer middleware-validated identity without cloning strings. Internal
|
||||
/// fallback dispatches still use the complete authority validation path.
|
||||
fn take_routing_identity(
|
||||
request: &mut Request,
|
||||
tls: bool,
|
||||
) -> Result<(Option<SelectedRouteContext>, HeaderValue, String, Option<String>, bool), Response> {
|
||||
let mut selected_context = request.extensions_mut().remove::<SelectedRouteContext>();
|
||||
let validated = selected_context.as_mut().and_then(|context| context.validated.take());
|
||||
let host_already_validated = validated.is_some();
|
||||
let (original_host, host, decoded_path) = match validated {
|
||||
Some(validated) => (
|
||||
validated.original_host,
|
||||
validated.host,
|
||||
validated.decoded_path,
|
||||
),
|
||||
None => {
|
||||
let original_host = effective_host(request, tls).map_err(|_| error(
|
||||
StatusCode::BAD_REQUEST,
|
||||
"RustProxy: invalid or conflicting request authority\n",
|
||||
))?;
|
||||
let host = original_host.to_str().ok()
|
||||
.and_then(|v| request_host(v).ok())
|
||||
.ok_or_else(|| error(StatusCode::BAD_REQUEST,
|
||||
"RustProxy: invalid hostname\n"))?;
|
||||
(original_host, host, None)
|
||||
}
|
||||
};
|
||||
Ok((selected_context, original_host, host, decoded_path, host_already_validated))
|
||||
}
|
||||
Reference in new issue
Block a user