From 287c8514ee2efe80a5fce3ddbd15d886b459116c Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 18 Jul 2020 19:07:22 +0200 Subject: FastCgiRequest::path: Get path from `REQUEST_URI` Use the `REQUEST_URI` param instead of `SCRIPT_NAME` to get the request path. Using `SCRIPT_NAME` caused issues with redirects. If my FastCGI program has the file name `script.fcgi`, and I set up a redirect from `/script` to `/script.fcgi`, then `path()` should return `/script` when using that path. In the above case, because we were using the `SCRIPT_NAME` param, `path()` would return `/script.fcgi` instead. This caused routes defined with a `RouteBuilder` to not match correctly. Now that we're using `REQUEST_URI`, we need to trim the query string and hash, which are included in the param value, since we only want the URI path. --- src/request.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/request.rs') diff --git a/src/request.rs b/src/request.rs index 02f416e..c62002c 100644 --- a/src/request.rs +++ b/src/request.rs @@ -189,10 +189,14 @@ impl<'a> FastCgiRequest<'a> { /// Returns `/path` when the URI is `http://localhost:8000/path?s=query`. /// When the path is empty, returns `/`. fn path(request: &fastcgi::Request) -> String { - match request.param("SCRIPT_NAME") { - Some(p) => p, - None => "/".to_owned(), - } + request.param("REQUEST_URI") + .as_ref() + + // Remove query string + .map(|uri| uri.split('?').next()) + .flatten() + .unwrap_or("/") + .to_owned() } /// Get the URI query string. -- cgit v1.2.3