1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-08-22 21:55:10 +02:00

escape router pattern re

This commit is contained in:
Nikolay Kim
2018-02-19 14:57:57 -08:00
parent ddc82395e8
commit 4d81186059
2 changed files with 16 additions and 8 deletions

View File

@@ -383,12 +383,14 @@ impl<S> Handler<S> for NormalizePath {
// try to remove trailing slash
if p.ends_with('/') {
let p = p.as_ref().trim_right_matches('/');
if router.has_route(&p) {
let p = p.to_owned();
let p = if !query.is_empty() { p + "?" + query } else { p };
return HttpResponse::build(self.redirect)
.header(header::LOCATION, p.as_str())
.body(Body::Empty);
if router.has_route(p) {
let mut req = HttpResponse::build(self.redirect);
return if !query.is_empty() {
req.header(header::LOCATION, (p.to_owned() + "?" + query).as_str())
} else {
req.header(header::LOCATION, p)
}
.body(Body::Empty);
}
}
}