Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Posting a html form doesn't work with trailing slash redirect. #7

Closed
kabukky opened this issue Apr 15, 2015 · 4 comments
Closed

Posting a html form doesn't work with trailing slash redirect. #7

kabukky opened this issue Apr 15, 2015 · 4 comments

Comments

@kabukky
Copy link

kabukky commented Apr 15, 2015

Hi,
thanks for making this router. I'm trying it out right now.
However, I encountered this weird behavior:

I have a html form that does a POST to /admin/register/ (notice the trailing slash).

When I use httptreemux like this:

router.GET("/admin/register", getRegistrationHandler)
router.POST("/admin/register", postRegistrationHandler)

the postRegistrationHandler isn't called.

But when I use httptreemux like this:

router.GET("/admin/register", getRegistrationHandler)
router.POST("/admin/register/", postRegistrationHandler)

it works just fine.

This seems to be a problem with redirection, right? Maybe because I defined the GET method without a trailing slash?

Thanks

@dimfeld
Copy link
Owner

dimfeld commented Apr 15, 2015

The router returns a 301 redirect to make the browser point to the version with/without the trailing slash. I did a bit of research and it appears that in this case the browser will just do a GET request to the redirected location instead of a POST with the original data. Is this the case that you're seeing?

If so, I think the best solution here is to add an option to the router to not do a redirect, but instead to just call the handler. I might have time to add such a feature this week, but not sure yet. If you'd like to take it on and submit a pull request I'll be glad to look it over.

@kabukky
Copy link
Author

kabukky commented Apr 15, 2015

Hi dimfeld,
that is exactly what my browser is doing.
That option would be a nice feature to have. You can take your time with it though, I'll just make sure to always use correctly formatted urls for now :)

Thanks!

@dimfeld
Copy link
Owner

dimfeld commented Apr 18, 2015

Quick update, I have some code written to make the redirect behavior more flexible, including an option to just call the handler like you want. Still need to write tests and update the docs for it which I hopefully will get to do some time next week.

@kabukky
Copy link
Author

kabukky commented Apr 19, 2015

That sounds good.
I'm using httptreemux as the default mux for Journey now - works great! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants