diff --git a/playground/appengine.go b/playground/appengine.go index 073b419d37..94c5d52325 100644 --- a/playground/appengine.go +++ b/playground/appengine.go @@ -13,6 +13,10 @@ import ( "appengine/urlfetch" ) +func init() { + onAppengine = !appengine.IsDevAppServer() +} + func client(r *http.Request) *http.Client { return urlfetch.Client(appengine.NewContext(r)) } diff --git a/playground/common.go b/playground/common.go index 3ffce88337..9f428f5136 100644 --- a/playground/common.go +++ b/playground/common.go @@ -9,6 +9,7 @@ package playground // import "golang.org/x/tools/playground" import ( "bytes" + "errors" "fmt" "io" "net/http" @@ -32,6 +33,9 @@ func bounce(w http.ResponseWriter, r *http.Request) { } func passThru(w io.Writer, req *http.Request) error { + if req.URL.Path == "/share" && !allowShare(req) { + return errors.New("Forbidden") + } defer req.Body.Close() url := baseURL + req.URL.Path r, err := client(req).Post(url, req.Header.Get("Content-type"), req.Body) @@ -44,3 +48,16 @@ func passThru(w io.Writer, req *http.Request) error { } return nil } + +var onAppengine = false // will be overriden by appengine.go + +func allowShare(r *http.Request) bool { + if !onAppengine { + return true + } + switch r.Header.Get("X-AppEngine-Country") { + case "", "ZZ", "HK", "CN", "RC": + return false + } + return true +}