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