func handler()

in http-cache-action/proxy/proxy.go [41:61]


func handler(w http.ResponseWriter, r *http.Request) {
	startTime := time.Now()
	key := r.URL.Path
	if key[0] == '/' {
		key = key[1:]
	}
	if key == "" {
		_, _ = w.Write([]byte("HTTP Cache is running!"))
		w.WriteHeader(200)
	} else if r.Method == "GET" {
		downloadCache(w, r, key)
	} else if r.Method == "HEAD" {
		checkCacheExists(w, key)
	} else if r.Method == "POST" {
		uploadCache(w, r, key)
	} else if r.Method == "PUT" {
		uploadCache(w, r, key)
	}
	duration := time.Since(startTime)
	log.Printf("Served %s request for %s key in %dms\n", r.Method, key, duration.Milliseconds())
}