internal/play: support plain text response
Fixes golang/go#51181
Change-Id: I82f10320e86555a161cbfb5c5b79dfc331017003
Reviewed-on: https://go-review.googlesource.com/c/website/+/388016
Run-TryBot: Jamal Carvalho <jamal@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Trust: Jamal Carvalho <jamalcarvalho@google.com>
diff --git a/cmd/golangorg/testdata/godev.txt b/cmd/golangorg/testdata/godev.txt
index 2775e4c..8624c8b 100644
--- a/cmd/golangorg/testdata/godev.txt
+++ b/cmd/golangorg/testdata/godev.txt
@@ -43,12 +43,22 @@
body contains The Go Playground
body contains About the Playground
+GET https://go.dev/play/p/MAohLsrz7JQ.go
+header Content-Type == text/plain; charset=utf-8
+body !contains The Go Playground
+body !contains About the Playground
+body contains Hello, 世界
+
GET https://golang.google.cn/play/p/asdfasdf
code == 500
body contains Sorry, but shared playground snippets are not visible in China.
body !contains The Go Playground
body !contains About the Playground
+GET https://golang.google.cn/play/p/MAohLsrz7JQ.go
+code == 500
+body contains Sorry, but shared playground snippets are not visible in China.
+
# These $GOROOT/*.md files should not serve.
GET https://go.dev/CONTRIBUTING
code == 404
diff --git a/internal/play/play.go b/internal/play/play.go
index fef6302..4c34672 100644
--- a/internal/play/play.go
+++ b/internal/play/play.go
@@ -35,6 +35,10 @@
site.ServeError(w, r, errors.New("Sorry, but shared playground snippets are not visible in China."))
return
}
+ if strings.HasSuffix(r.URL.Path, ".go") {
+ simpleProxy(w, r, "https://"+backend(r)+strings.TrimPrefix(r.URL.Path, "/play"))
+ return
+ }
site.ServePage(w, r, web.Page{
"URL": r.URL.Path,
"layout": "play",