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

Method ServeHTTP

v2/internal/api_test.go:44–142  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

42}
43
44func (f *fakeAPIHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
45 writeResponse := func(res *remotepb.Response) {
46 hresBody, err := proto.Marshal(res)
47 if err != nil {
48 http.Error(w, fmt.Sprintf("Failed encoding API response: %v", err), 500)
49 return
50 }
51 w.Write(hresBody)
52 }
53
54 if r.URL.Path != "/rpc_http" {
55 http.NotFound(w, r)
56 return
57 }
58 hreqBody, err := ioutil.ReadAll(r.Body)
59 if err != nil {
60 http.Error(w, fmt.Sprintf("Bad body: %v", err), 500)
61 return
62 }
63 apiReq := &remotepb.Request{}
64 if err := proto.Unmarshal(hreqBody, apiReq); err != nil {
65 http.Error(w, fmt.Sprintf("Bad encoded API request: %v", err), 500)
66 return
67 }
68 if *apiReq.RequestId != "s3cr3t" && !f.allowMissingTicket {
69 writeResponse(&remotepb.Response{
70 RpcError: &remotepb.RpcError{
71 Code: proto.Int32(int32(remotepb.RpcError_SECURITY_VIOLATION)),
72 Detail: proto.String("bad security ticket"),
73 },
74 })
75 return
76 }
77 if got, want := r.Header.Get(dapperHeader), "trace-001"; got != want {
78 writeResponse(&remotepb.Response{
79 RpcError: &remotepb.RpcError{
80 Code: proto.Int32(int32(remotepb.RpcError_BAD_REQUEST)),
81 Detail: proto.String(fmt.Sprintf("trace info = %q, want %q", got, want)),
82 },
83 })
84 return
85 }
86
87 service, method := *apiReq.ServiceName, *apiReq.Method
88 var resOut proto.Message
89 if service == "actordb" && method == "LookupActor" {
90 req := &basepb.StringProto{}
91 res := &basepb.StringProto{}
92 if err := proto.Unmarshal(apiReq.Request, req); err != nil {
93 http.Error(w, fmt.Sprintf("Bad encoded request: %v", err), 500)
94 return
95 }
96 if *req.Value == "Doctor Who" {
97 res.Value = proto.String("David Tennant")
98 }
99 resOut = res
100 }
101 if service == "errors" {

Callers 4

handleHTTPMiddlewareFunction · 0.45
TestRemoteAddrFunction · 0.45
TestPanickingHandlerFunction · 0.45

Calls 8

MarshalMethod · 0.80
UnmarshalMethod · 0.80
ErrorMethod · 0.45
WriteMethod · 0.45
StringMethod · 0.45
GetMethod · 0.45
SetMethod · 0.45
HeaderMethod · 0.45

Tested by

no test coverage detected