diff options
author | Ian Lewis <ianlewis@google.com> | 2020-01-17 01:47:38 -0500 |
---|---|---|
committer | Ian Lewis <ianlewis@google.com> | 2020-01-17 01:47:38 -0500 |
commit | 6d055f33a19203b8589142b74737dbe5f67d18e3 (patch) | |
tree | a19d52458e1453b48d4c568f70bbb114ad30aed2 /cmd/gvisor-website/main.go | |
parent | c73410c0bda98fa617d82cf423ce96ee5e6af6a4 (diff) | |
parent | dcd8504d9866a9b0d95fadbff79e599f5d6893db (diff) |
Merge branch 'master' into lint-md
Diffstat (limited to 'cmd/gvisor-website/main.go')
-rw-r--r-- | cmd/gvisor-website/main.go | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/cmd/gvisor-website/main.go b/cmd/gvisor-website/main.go index f4354f943..01ad9153a 100644 --- a/cmd/gvisor-website/main.go +++ b/cmd/gvisor-website/main.go @@ -71,6 +71,20 @@ var ( goGetHTML5 = `<!doctype html><html><head><meta charset=utf-8>` + goGetHeader + `<title>Go-get</title></head><body></html>` ) +// cronHandler wraps an http.Handler to check that the request is from the App +// Engine Cron service. +// See: https://cloud.google.com/appengine/docs/standard/go112/scheduling-jobs-with-cron-yaml#validating_cron_requests +func cronHandler(h http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.Header.Get("X-Appengine-Cron") != "true" { + http.NotFound(w, r) + return + } + // Fallthrough. + h.ServeHTTP(w, r) + }) +} + // wrappedHandler wraps an http.Handler. // // If the query parameters include go-get=1, then we redirect to a single @@ -174,7 +188,7 @@ func registerRebuild(mux *http.ServeMux) { mux = http.DefaultServeMux } - mux.Handle("/rebuild", wrappedHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + mux.Handle("/rebuild", cronHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { ctx := context.Background() credentials, err := google.FindDefaultCredentials(ctx, cloudbuild.CloudPlatformScope) if err != nil { |