(w http.ResponseWriter, req *http.Request)
| 29 | } |
| 30 | |
| 31 | func 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{} |
nothing calls this directly
no test coverage detected
searching dependent graphs…