func()

in sharedlibraries/gce/fakehttp/fakehttp.go [44:72]


func (f *FakeServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	bodyBytes, err := ioutil.ReadAll(r.Body)
	if err != nil {
		log.Logger.Fatalf("Error reading body")
	}
	body := strings.TrimSuffix(string(bodyBytes), "\n")
	log.Logger.Infof("RequestURL: %v", string(r.URL.EscapedPath()))
	log.Logger.Infof("RequestBODY: %v", body)
	for _, resp := range f.Responses {
		if r.Method == resp.RequestMethod &&
			string(r.URL.EscapedPath()) == resp.RequestEscapedPath &&
			strings.Contains(body, resp.RequestBody) {
			log.Logger.Infof("Serving matching response for method=%q path=%q body=%q: %d %s",
				resp.RequestMethod, resp.RequestEscapedPath, body, resp.StatusCode, string(resp.Response))
			if resp.StatusCode == 0 {
				w.WriteHeader(http.StatusOK)
			} else {
				w.WriteHeader(resp.StatusCode)
			}
			w.Write(resp.Response)
			return
		}
	}
	w.WriteHeader(http.StatusNotFound)
	errorMsg := fmt.Sprintf("No matching response for method=%s path=%s body=%s",
		r.Method, string(r.URL.EscapedPath()), body)
	log.Logger.Warn(errorMsg)
	w.Write([]byte(errorMsg))
}