MCPcopy Create free account
hub / github.com/golang/appengine / handle

Function handle

remote_api/remote_api.go:31–119  ·  view source on GitHub ↗
(w http.ResponseWriter, req *http.Request)

Source from the content-addressed store, hash-verified

29}
30
31func handle(w http.ResponseWriter, req *http.Request) {
32 c := appengine.NewContext(req)
33
34 u := user.Current(c)
35 if u == nil {
36 u, _ = user.CurrentOAuth(c,
37 "https://www.googleapis.com/auth/cloud-platform",
38 "https://www.googleapis.com/auth/appengine.apis",
39 )
40 }
41
42 if !appengine.IsDevAppServer() && (u == nil || !u.Admin) {
43 w.Header().Set("Content-Type", "text/plain; charset=utf-8")
44 w.WriteHeader(http.StatusUnauthorized)
45 io.WriteString(w, "You must be logged in as an administrator to access this.\n")
46 return
47 }
48 if req.Header.Get("X-Appcfg-Api-Version") == "" {
49 w.Header().Set("Content-Type", "text/plain; charset=utf-8")
50 w.WriteHeader(http.StatusForbidden)
51 io.WriteString(w, "This request did not contain a necessary header.\n")
52 return
53 }
54
55 if req.Method != "POST" {
56 // Response must be YAML.
57 rtok := req.FormValue("rtok")
58 if rtok == "" {
59 rtok = "0"
60 }
61 w.Header().Set("Content-Type", "text/yaml; charset=utf-8")
62 fmt.Fprintf(w, `{app_id: %q, rtok: %q}`, internal.FullyQualifiedAppID(c), rtok)
63 return
64 }
65
66 defer req.Body.Close()
67 body, err := ioutil.ReadAll(req.Body)
68 if err != nil {
69 w.WriteHeader(http.StatusBadRequest)
70 log.Errorf(c, "Failed reading body: %v", err)
71 return
72 }
73 remReq := &pb.Request{}
74 if err := proto.Unmarshal(body, remReq); err != nil {
75 w.WriteHeader(http.StatusBadRequest)
76 log.Errorf(c, "Bad body: %v", err)
77 return
78 }
79
80 service, method := *remReq.ServiceName, *remReq.Method
81 if !requestSupported(service, method) {
82 w.WriteHeader(http.StatusBadRequest)
83 log.Errorf(c, "Unsupported RPC /%s.%s", service, method)
84 return
85 }
86
87 rawReq := &rawMessage{remReq.Request}
88 rawRes := &rawMessage{}

Callers

nothing calls this directly

Calls 15

NewContextFunction · 0.92
CurrentFunction · 0.92
CurrentOAuthFunction · 0.92
IsDevAppServerFunction · 0.92
FullyQualifiedAppIDFunction · 0.92
ErrorfFunction · 0.92
CallFunction · 0.92
InfofFunction · 0.92
requestSupportedFunction · 0.85
UnmarshalMethod · 0.80
MarshalMethod · 0.80
SetMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…