mirror of
https://github.com/golang/go
synced 2024-11-18 10:14:45 -07:00
playground: block share functionality from specific countries
This will permit us to serve *.golang.org to Chinese users. Change-Id: If184760d7f4c9e49a3df3785c15af770958413de Reviewed-on: https://go-review.googlesource.com/14190 Reviewed-by: Jason Buberel <jbuberel@google.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
b9fbbb8e31
commit
4df6ae9fad
@ -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))
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user