iron / router

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

Always returning a 404 after redirection #140

Open Nickforall opened 6 years ago

Nickforall commented 6 years ago

Whenever I do a redirect, I get a 404 on the page redirected to, even though the url exists when I reload the exact same url. I have checked the http responses of /auth/login and the page redirected to, and they are both valid.

This is what my handler looks like at the moment.

impl AuthenticationController {
    // Route: POST /auth/login
    pub fn login(req: &mut Request) -> IronResult<Response> {
        let url: Url;

        if try!(req.session().get::<middleware::sessions::Login>()).is_some() {
            url = url_for!(req, "index", "status" => "already_loggedin");
        } else {
            if User::authenticate("hello@nickforall.nl", "password") {
                url = url_for!(req, "index", "status" => "success");
            } else {
                url = url_for!(req, "index", "status" => "failure");
            }
        }

        Ok(Response::with((status::Found, Redirect(url.clone()))))
    }
}
Nickforall commented 6 years ago

I should also mention that the router is mounted using mount:

    let mut router_mount = Mount::new();
    // Mount the static folder on the static route
    router_mount
        .mount("/", routes::all())
        .mount("/static/", Static::new(Path::new("src/static")));

The behaviour doesn't change when I don't use mount, but chain the routes directly.

Nickforall commented 6 years ago

Small update:

Had some time to debug, whenever a POST redirects, the method property of the request is the following:

Extension("content=Hallo+dit+is+een+test!GET")

Where the part content=Hallo+dit+is+een+test! is the content from the post request that redirected.

When a GET request redirects, this behaviour doesn't appear and the method is as expected. I am not that familiar with Iron, so it would be great if someone can help me find the code that causes this so I can fix it.