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

bug: should not redirect if target location not exists #311

Open
jxskiss opened this issue May 30, 2020 · 3 comments
Open

bug: should not redirect if target location not exists #311

jxskiss opened this issue May 30, 2020 · 3 comments
Labels
Milestone

Comments

@jxskiss
Copy link

jxskiss commented May 30, 2020

I was running a python service and a go service before it, the go service handles some endpoints and proxy requests which not found to the python service. And I ran into a situation which redirect to death.

The following code will reproduce the bug when accessing "http://127.0.0.1:8080/users/profile/".

package main

import (
	"github.com/julienschmidt/httprouter"
	"net/http"
)

func main() {
	r := httprouter.New()
	r.GET("/users/:user_id/somedata/", dummyHandler)
	r.NotFound = proxyHandler()

	http.ListenAndServe(":8080", r)
}

// mimics the backend python service
func proxyHandler() http.Handler {
	r := httprouter.New()
	r.GET("/users/profile/", dummyHandler)
	return r
}

func dummyHandler(_ http.ResponseWriter, _ *http.Request, _ httprouter.Params) {}
@jxskiss
Copy link
Author

jxskiss commented May 30, 2020

It redirects between "/users/profile/" and "/users/profile" cyclically, which is not expected.
Since neither "/users/profile/" and "/users/profile" is registered, I think it should not redirect "/users/profile/" to "/users/profile", but should go to NotFound instead.

@jxskiss
Copy link
Author

jxskiss commented Jun 2, 2020

@julienschmidt Hi, sorry to bother, would you please look into this?

@duskwuff
Copy link

Here's a reduced test case:

package main

import (
    "github.com/julienschmidt/httprouter"
    "net/http"
)

func main() {
    r := &httprouter.Router{}
    r.RedirectTrailingSlash = true
    r.GET("/a/:id/b/", dummyHandler)
    http.ListenAndServe("localhost:9000", r)
}

func dummyHandler(_ http.ResponseWriter, _ *http.Request, _ httprouter.Params) {}

So long as RedirectTrailingSlash is enabled, a request to GET /a/x/ will be redirected to /a/x, despite there being no handler registered for that path. (This is specific to requests under /a/; requests under other paths will not be redirected similarly.)

@julienschmidt julienschmidt added this to the v1.4 milestone Jul 26, 2020
similark pushed a commit to similarweb/httprouter that referenced this issue May 9, 2023
Bumps [github.com/onsi/gomega](https://github.com/onsi/gomega) from 1.16.0 to 1.17.0.
- [Release notes](https://github.com/onsi/gomega/releases)
- [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md)
- [Commits](onsi/gomega@v1.16.0...v1.17.0)

---
updated-dependencies:
- dependency-name: github.com/onsi/gomega
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants