-
Notifications
You must be signed in to change notification settings - Fork 102
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
404 Error instead of 405 Status Code #60
Comments
Same as #37 |
I could have sent a PR about this, but it involves major changes, that's why I want to discuss the same. |
Hi, i have no problems with changes if it's not broking the public api. |
Working on it! 👍 |
great :) |
I was thinking to change current Mux struct to type Mux struct {
Routes []*Route //changed
prefix string
notFound http.Handler
Serve func(rw http.ResponseWriter, req *http.Request)
CaseSensitive bool
} and Route will have information of allowed methods and their handlers, something like: type Route struct {
Path string
methods int //changed
Size int
Atts int
wildPos int
Token Token
Pattern map[int]string
Compile map[int]*regexp.Regexp
Tag map[int]string
MethodHandlers map[string]*http.Handler //added
} Route.methods will have ORed int values of Methods, as done for func (r *Route) setMethod(m string, h http.Handler) {
r.methods |= methodValues[m]
r.MethodHandlers[m] = &h
} will set the Method for the given route. func (r *Route) handler(m string) (*http.Handler) {
if methodValues[m]&r.methods != 0 {
return r.MethodHandlers[m]
}
return nil
} But in this case, I will need to iterate through all the value in So I would like to go with solution 1, proposed in the 1st comment of this thread. |
Iterating over all routes is really costly in term of performance... Maybe you could try to make a fail over, only when a route is not found, you try to found a matching one by url instead ? |
If I make requests to /test/ endpoint with POST method then I get 404 Not Found error instead of 405 Method Not Allowed.
Probable reason:
map[string][]*Route
the key in this map is method name (e.g., GET, POST, etc..) and the requested endpoint is searched in the slice of the requested method, and if the endpoint is not found then 404 is returned.Proposed Solution:
OR
The text was updated successfully, but these errors were encountered: