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>
This commit is contained in:
Jamal Carvalho 2022-02-25 11:04:01 -05:00 коммит произвёл Jamal Carvalho
Родитель d6638d3d92
Коммит 832feb7309
2 изменённых файлов: 14 добавлений и 0 удалений

10
cmd/golangorg/testdata/godev.txt поставляемый
Просмотреть файл

@ -43,12 +43,22 @@ GET https://go.dev/play/p/asdfasdf
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

Просмотреть файл

@ -35,6 +35,10 @@ func playHandler(site *web.Site) http.Handler {
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",