github.com/xushiwei/go@v0.0.0-20130601165731-2b9d83f45bc9/src/cmd/godoc/play-appengine.go (about) 1 // Copyright 2012 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // App Engine godoc Playground functionality. 6 7 // +build appengine 8 9 package main 10 11 import ( 12 "io" 13 "net/http" 14 15 "appengine" 16 "appengine/urlfetch" 17 ) 18 19 func bounceToPlayground(w http.ResponseWriter, req *http.Request) { 20 c := appengine.NewContext(req) 21 client := urlfetch.Client(c) 22 url := playgroundBaseURL + req.URL.Path 23 defer req.Body.Close() 24 resp, err := client.Post(url, req.Header.Get("Content-type"), req.Body) 25 if err != nil { 26 http.Error(w, "Internal Server Error", 500) 27 c.Errorf("making POST request: %v", err) 28 return 29 } 30 defer resp.Body.Close() 31 if _, err := io.Copy(w, resp.Body); err != nil { 32 http.Error(w, "Internal Server Error", 500) 33 c.Errorf("making POST request: %v", err) 34 } 35 }