iron / router

Router middleware for the Iron web framework.
165 stars 74 forks source link

Implement 301 redirects for urls with a trailing slash #53

Closed reem closed 9 years ago

reem commented 9 years ago

@michaelsproul what's the best way to get a Url without the trailing slash from a Url with a trailing slash?

michaelsproul commented 9 years ago

We encode trailing slashes with a "" in the path, so you could do:

if url.path.last().unwrap() == "" {
   url.path.pop();
}
reem commented 9 years ago

@michaelsproul What are / and nothing encoded as?

reem commented 9 years ago

(I'm getting an infinite redirect on localhost:3000/ and localhost:3000 when detecting trailing urls with .last() == Some("".to_owned()) and then poping to get a trailing-slash-less url)

michaelsproul commented 9 years ago

Hmm, I think we actually encode localhost:3000 as localhost:3000/, i.e. with a path of [""]... The docs say the path is always non-empty, and I vaguely remember this being passed along from the rust-url library.

reem commented 9 years ago

I'll just add a check for path.len() != 1 to handle the final case.