Skip to content

Commit 7099521

Browse files
committed
internal/frontend: allow HEAD requests
Fixes golang/go#43739 Change-Id: I887fd3c1949a9f26aff75122f455246dc802d6de Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/284912 Trust: Jonathan Amsterdam <[email protected]> Run-TryBot: Jonathan Amsterdam <[email protected]> Reviewed-by: Julie Qiu <[email protected]>
1 parent 70d94ea commit 7099521

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

cmd/frontend/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ func main() {
189189
}
190190
mw := middleware.Chain(
191191
middleware.RequestLog(cmdconfig.Logger(ctx, cfg, "frontend-log")),
192-
middleware.AcceptRequests(http.MethodGet, http.MethodPost), // accept only GETs and POSTs
192+
middleware.AcceptRequests(http.MethodGet, http.MethodPost, http.MethodHead), // accept only GETs, POSTs and HEADs
193193
middleware.Quota(cfg.Quota, cacheClient),
194194
middleware.GodocURL(), // potentially redirects so should be early in chain
195195
middleware.RedirectedFrom(),

internal/frontend/details.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
func (s *Server) serveDetails(w http.ResponseWriter, r *http.Request, ds internal.DataSource) (err error) {
2626
defer middleware.ElapsedStat(r.Context(), "serveDetails")()
2727

28-
if r.Method != http.MethodGet {
28+
if r.Method != http.MethodGet && r.Method != http.MethodHead {
2929
return &serverError{status: http.StatusMethodNotAllowed}
3030
}
3131
if r.URL.Path == "/" {

internal/frontend/search.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ const (
122122
// /search?q=<query>. If <query> is an exact match for a package path, the user
123123
// will be redirected to the details page.
124124
func (s *Server) serveSearch(w http.ResponseWriter, r *http.Request, ds internal.DataSource) error {
125-
if r.Method != http.MethodGet {
125+
if r.Method != http.MethodGet && r.Method != http.MethodHead {
126126
return &serverError{status: http.StatusMethodNotAllowed}
127127
}
128128
db, ok := ds.(*postgres.DB)

0 commit comments

Comments
 (0)