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