Percent-decode URL parameters before parsing them (closes #103)
check / check (push) Canceled after 0s
check / check (push) Canceled after 0s
chi matches routes against the escaped path when a request has one and hands the handlers their URL parameters still percent-encoded. The home page's lookup form encodes the address it asks for, so every IPv6 lookup answered 400, as did a comma-separated address list or a prefix that a client percent-encoded. The router now matches against the decoded path, so every handler reads its parameters decoded. Model: opus-5-5
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
@@ -12,6 +13,18 @@ func (s *Server) setupRoutes() {
|
||||
r := chi.NewRouter()
|
||||
|
||||
// Middleware
|
||||
|
||||
// Match routes against the decoded path, so that the handlers read their
|
||||
// URL parameters decoded. chi otherwise matches against the escaped path
|
||||
// when the request has one and leaves the parameters escaped:
|
||||
// /ip/2001%3Adb8%3A%3A1 would look up "2001%3Adb8%3A%3A1".
|
||||
r.Use(func(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||
chi.RouteContext(req.Context()).RoutePath = req.URL.Path
|
||||
|
||||
next.ServeHTTP(w, req)
|
||||
})
|
||||
})
|
||||
r.Use(middleware.RequestID)
|
||||
r.Use(middleware.RealIP)
|
||||
r.Use(RequestLoggerMiddleware(s.logger.Logger)) // Structured request logging
|
||||
|
||||
Reference in New Issue
Block a user