Skip to content

Commit e87f299

Browse files
committed
internal/frontend: require GET for most routes
Add a GET method to the patterns for most frontend routes. We omitted a few where we're not totally clear on what the client may be sending. Change-Id: I3f300b7d3753fd4009a60855c7a15b24c5e27dd6 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/616395 Reviewed-by: Robert Findley <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> kokoro-CI: kokoro <[email protected]>
1 parent 2d793c0 commit e87f299

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

internal/frontend/server.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -180,37 +180,37 @@ func (s *Server) Install(handle func(string, http.Handler), cacher Cacher, authV
180180
// https://cloud.google.com/appengine/docs/standard/go/how-instances-are-managed#startup
181181
// and for /_ah/warmup at
182182
// https://cloud.google.com/appengine/docs/standard/go/configuring-warmup-requests.
183-
handle("/_ah/", http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) {
183+
handle("GET /_ah/", http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) {
184184
log.Infof(r.Context(), "Request made to %q", r.URL.Path)
185185
}))
186-
handle("/static/", s.staticHandler())
187-
handle("/third_party/", http.StripPrefix("/third_party", http.FileServer(http.FS(s.thirdPartyFS))))
188-
handle("/favicon.ico", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
186+
handle("GET /static/", s.staticHandler())
187+
handle("GET /third_party/", http.StripPrefix("/third_party", http.FileServer(http.FS(s.thirdPartyFS))))
188+
handle("GET /favicon.ico", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
189189
serveFileFS(w, r, s.staticFS, "shared/icon/favicon.ico")
190190
}))
191191

192192
handle("/sitemap/", http.StripPrefix("/sitemap/", http.FileServer(http.Dir("private/sitemap"))))
193-
handle("/mod/", http.HandlerFunc(s.handleModuleDetailsRedirect))
194-
handle("/pkg/", http.HandlerFunc(s.handlePackageDetailsRedirect))
193+
handle("GET /mod/", http.HandlerFunc(s.handleModuleDetailsRedirect))
194+
handle("GET /pkg/", http.HandlerFunc(s.handlePackageDetailsRedirect))
195195
if fetchHandler != nil {
196196
handle("/fetch/", fetchHandler)
197197
}
198198
handle("/play/compile", http.HandlerFunc(s.proxyPlayground))
199-
handle("/play/fmt", http.HandlerFunc(s.handleFmt))
199+
handle("GET /play/fmt", http.HandlerFunc(s.handleFmt))
200200
handle("/play/share", http.HandlerFunc(s.proxyPlayground))
201-
handle("/search", searchHandler)
202-
handle("/search-help", s.staticPageHandler("search-help", "Search Help"))
203-
handle("/license-policy", s.licensePolicyHandler())
204-
handle("/about", s.staticPageHandler("about", "About"))
205-
handle("/badge/", http.HandlerFunc(s.badgeHandler))
206-
handle("/C", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
201+
handle("GET /search", searchHandler)
202+
handle("GET /search-help", s.staticPageHandler("search-help", "Search Help"))
203+
handle("GET /license-policy", s.licensePolicyHandler())
204+
handle("GET /about", s.staticPageHandler("about", "About"))
205+
handle("GET /badge/", http.HandlerFunc(s.badgeHandler))
206+
handle("GET /C", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
207207
// Package "C" is a special case: redirect to /cmd/cgo.
208208
// (This is what golang.org/C does.)
209209
http.Redirect(w, r, "/cmd/cgo", http.StatusMovedPermanently)
210210
}))
211-
handle("/golang.org/x", s.staticPageHandler("subrepo", "Sub-repositories"))
212-
handle("/files/", http.StripPrefix("/files", s.fileMux))
213-
handle("/vuln/", vulnHandler)
211+
handle("GET /golang.org/x", s.staticPageHandler("subrepo", "Sub-repositories"))
212+
handle("GET /files/", http.StripPrefix("/files", s.fileMux))
213+
handle("GET /vuln/", vulnHandler)
214214
handle("/opensearch.xml", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
215215
serveFileFS(w, r, s.staticFS, "shared/opensearch.xml")
216216
}))
@@ -234,8 +234,8 @@ Sitemap: https://pkg.go.dev/sitemap/index.xml
234234

235235
// installDebugHandlers installs handlers for debugging. Most of the handlers
236236
// are provided by the net/http/pprof package. Although that package installs
237-
// them on the default ServeMux in its init function, we must install them on
238-
// our own ServeMux.
237+
// them on the default ServeMux in its init function, we must install them
238+
// on our own ServeMux.
239239
func (s *Server) installDebugHandlers(handle func(string, http.Handler)) {
240240

241241
ifDebug := func(h func(http.ResponseWriter, *http.Request)) http.HandlerFunc {

0 commit comments

Comments
 (0)