From 951512dfed6ce3af7c9c8aa37505a03c9b0c348d Mon Sep 17 00:00:00 2001 From: Andrew Bonventre Date: Thu, 4 Jan 2018 18:12:00 -0500 Subject: [PATCH] godoc: proxy /compile requests to play.golang.org Now that play.golang.org and sandbox[-flex].golang.org have been merged, proxy requests to the former. Change-Id: I7d18d0494fd54c2357dc53952fa458ceb1380aca Reviewed-on: https://go-review.googlesource.com/86253 Reviewed-by: Brad Fitzpatrick --- cmd/godoc/setup-godoc-app.bash | 2 +- godoc/appengine.go | 2 +- godoc/proxy/proxy.go | 46 ++++++++++------------------------ 3 files changed, 15 insertions(+), 35 deletions(-) diff --git a/cmd/godoc/setup-godoc-app.bash b/cmd/godoc/setup-godoc-app.bash index a462ebe0..f2277389 100755 --- a/cmd/godoc/setup-godoc-app.bash +++ b/cmd/godoc/setup-godoc-app.bash @@ -76,7 +76,7 @@ makeAppYaml() { application: godoc version: 1 runtime: go -api_version: go1.4beta +api_version: go1 handlers: - url: /.* diff --git a/godoc/appengine.go b/godoc/appengine.go index 2a685585..fe5e6875 100644 --- a/godoc/appengine.go +++ b/godoc/appengine.go @@ -6,7 +6,7 @@ package godoc -import "appengine" +import "google.golang.org/appengine" func init() { onAppengine = !appengine.IsDevAppServer() diff --git a/godoc/proxy/proxy.go b/godoc/proxy/proxy.go index 0ddaa008..08795e9c 100644 --- a/godoc/proxy/proxy.go +++ b/godoc/proxy/proxy.go @@ -4,8 +4,7 @@ // +build appengine -// Package proxy proxies requests to the sandbox compiler service and the -// playground share handler. +// Package proxy proxies requests to the playground's compile and share handlers. // It is designed to run only on the instance of godoc that serves golang.org. package proxy @@ -26,7 +25,6 @@ import ( "google.golang.org/appengine" "google.golang.org/appengine/log" - "google.golang.org/appengine/memcache" "google.golang.org/appengine/urlfetch" ) @@ -45,13 +43,7 @@ type Event struct { Delay time.Duration // time to wait before printing Message } -const ( - // We need to use HTTP here for "reasons", but the traffic isn't - // sensitive and it only travels across Google's internal network - // so we should be OK. - sandboxURL = "http://sandbox.golang.org/compile" - playgroundURL = "https://play.golang.org" -) +const playgroundURL = "https://play.golang.org" const expires = 7 * 24 * time.Hour // 1 week var cacheControlHeader = fmt.Sprintf("public, max-age=%d", int(expires.Seconds())) @@ -67,27 +59,15 @@ func compile(w http.ResponseWriter, r *http.Request) { return } - c := appengine.NewContext(r) + ctx := appengine.NewContext(r) body := r.FormValue("body") res := &Response{} - key := cacheKey(body) - if _, err := memcache.Gob.Get(c, key, res); err != nil { - if err != memcache.ErrCacheMiss { - log.Errorf(c, "getting response cache: %v", err) - } - - req := &Request{Body: body} - if err := makeSandboxRequest(c, req, res); err != nil { - log.Errorf(c, "compile error: %v", err) - http.Error(w, "Internal Server Error", http.StatusInternalServerError) - return - } - - item := &memcache.Item{Key: key, Object: res} - if err := memcache.Gob.Set(c, item); err != nil { - log.Errorf(c, "setting response cache: %v", err) - } + req := &Request{Body: body} + if err := makeCompileRequest(ctx, req, res); err != nil { + log.Errorf(ctx, "compile error: %v", err) + http.Error(w, "Internal Server Error", http.StatusInternalServerError) + return } expiresTime := time.Now().Add(expires).UTC() @@ -105,18 +85,18 @@ func compile(w http.ResponseWriter, r *http.Request) { }{res.Errors, flatten(res.Events)} } if err := json.NewEncoder(w).Encode(out); err != nil { - log.Errorf(c, "encoding response: %v", err) + log.Errorf(ctx, "encoding response: %v", err) } } -// makeSandboxRequest sends the given Request to the sandbox -// and stores the response in the given Response. -func makeSandboxRequest(c context.Context, req *Request, res *Response) error { +// makePlaygroundRequest sends the given Request to the playground compile +// endpoint and stores the response in the given Response. +func makeCompileRequest(ctx context.Context, req *Request, res *Response) error { reqJ, err := json.Marshal(req) if err != nil { return fmt.Errorf("marshalling request: %v", err) } - r, err := urlfetch.Client(c).Post(sandboxURL, "application/json", bytes.NewReader(reqJ)) + r, err := urlfetch.Client(ctx).Post(playgroundURL+"/compile", "application/json", bytes.NewReader(reqJ)) if err != nil { return fmt.Errorf("making request: %v", err) }