diff options
author | Teddy Wing | 2020-07-18 19:07:22 +0200 |
---|---|---|
committer | Teddy Wing | 2020-07-18 19:07:22 +0200 |
commit | 287c8514ee2efe80a5fce3ddbd15d886b459116c (patch) | |
tree | b94f93738a34f63990f1a91c6bf54bcc5244f43c | |
parent | e3f4e806cad703def89c7a96c06bda8dfd94990a (diff) | |
download | fastcgi-conduit-287c8514ee2efe80a5fce3ddbd15d886b459116c.tar.bz2 |
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.
-rw-r--r-- | src/request.rs | 12 |
1 files changed, 8 insertions, 4 deletions
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. |