Removed / check that is performed in newPath. Return Not Acceptable if a path not starting with /.
This commit is contained in:
parent
a0b80ced85
commit
538f1bd676
10
httpr.go
10
httpr.go
@ -133,13 +133,13 @@ func New() *Router {
|
|||||||
|
|
||||||
func (rr *Router) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (rr *Router) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
if tree, ok := rr.tree[r.Method]; ok {
|
if tree, ok := rr.tree[r.Method]; ok {
|
||||||
if r.URL.Path[0] != '/' {
|
path, err := newPath(r.URL.Path)
|
||||||
panic("first element of path should be a slash (/) symbol")
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), http.StatusNotAcceptable)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
path, _ := newPath(r.URL.Path)
|
if handler, params := tree.get(path); handler != nil {
|
||||||
|
|
||||||
if handler, params := tree.get(path, 0); handler != nil {
|
|
||||||
if params != nil {
|
if params != nil {
|
||||||
r = r.WithContext(context.WithValue(r.Context(), ParamsKey, params))
|
r = r.WithContext(context.WithValue(r.Context(), ParamsKey, params))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user