Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
db4f58d737 |
@@ -14,8 +14,8 @@ const (
|
||||
notFoundMessage = "Not found"
|
||||
methodNotAllowedMessage = "Method not allowed"
|
||||
|
||||
// jsonRoutesAllow is the Allow header of their 405 answer: they are all
|
||||
// GET routes, and GetHead serves HEAD on them as GET.
|
||||
// jsonRoutesAllow is the Allow header of their 405 answer: every one of
|
||||
// them takes GET and HEAD, and no other method.
|
||||
jsonRoutesAllow = "GET, HEAD"
|
||||
)
|
||||
|
||||
@@ -71,7 +71,10 @@ func (s *Server) setupRoutes() {
|
||||
r.Use(JSONValidationMiddleware)
|
||||
r.NotFound(jsonNotFound)
|
||||
r.MethodNotAllowed(jsonMethodNotAllowed)
|
||||
r.Get("/", s.handleIPInfo()) // Client IP
|
||||
r.Get("/", s.handleIPInfo()) // Client IP
|
||||
// GetHead does not reach this route: mounting the group registers
|
||||
// /ip and /ip/ for every method, so HEAD arrives here as HEAD.
|
||||
r.Head("/", s.handleIPInfo())
|
||||
r.Get("/{addr}", s.handleIPInfo()) // Specified IP
|
||||
})
|
||||
|
||||
|
||||
@@ -7,16 +7,17 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestRoutesAnswerHEAD sends HEAD for a page and a JSON route through the
|
||||
// server's router and checks that each answers as GET does. Before the fix
|
||||
// every route answered HEAD with 405
|
||||
// TestRoutesAnswerHEAD sends HEAD for a page and JSON routes through the
|
||||
// server's router and checks that each answers as GET does. /ip and /ip/, the
|
||||
// lookup of the caller's own address, are in the list because chi's GetHead
|
||||
// does not reach them. Before the fix every route answered HEAD with 405
|
||||
// (https://git.eeqj.de/sneak/routewatch/issues/111).
|
||||
func TestRoutesAnswerHEAD(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
s := newServerWithTestRoutes(t)
|
||||
|
||||
for _, path := range []string{"/", statsPath} {
|
||||
for _, path := range []string{"/", statsPath, "/ip", "/ip/"} {
|
||||
rec := httptest.NewRecorder()
|
||||
s.router.ServeHTTP(rec, httptest.NewRequestWithContext(
|
||||
t.Context(), http.MethodHead, path, nil))
|
||||
|
||||
Reference in New Issue
Block a user