Removed / check that is performed in newPath. Return Not Acceptable if a path not starting with /.

This commit is contained in:
Alexander Andreev 2023-05-28 01:29:01 +04:00
parent a0b80ced85
commit 538f1bd676
Signed by: Arav
GPG Key ID: D22A817D95815393

View File

@ -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))
} }