func logResponse(logger cache.Logger, method string, code int, url string) {
	logger.Printf("HTTP %s %d %s", method, code, url)
}
Helper function for logging responses
package httpproxy
import (
	"context"
	"errors"
	"fmt"
	"io"
	"io/ioutil"
	"net/http"
	"net/url"
	"strconv"
	"strings"
	"github.com/buchgr/bazel-remote/cache"
	"github.com/buchgr/bazel-remote/cache/disk/casblob"
	"github.com/prometheus/client_golang/prometheus"
	"github.com/prometheus/client_golang/prometheus/promauto"
)
type uploadReq struct {
	hash string
	size int64
	kind cache.EntryKind
	rc   io.ReadCloser
}
type remoteHTTPProxyCache struct {
	remote       *http.Client
	baseURL      string
	uploadQueue  chan<- uploadReq
	accessLogger cache.Logger
	errorLogger  cache.Logger
	requestURL   func(hash string, kind cache.EntryKind) string
	v2mode       bool
}
var (
	cacheHits = promauto.NewCounter(prometheus.CounterOpts{
		Name: "bazel_remote_http_cache_hits",
		Help: "The total number of HTTP backend cache hits",
	})
	cacheMisses = promauto.NewCounter(prometheus.CounterOpts{
		Name: "bazel_remote_http_cache_misses",
		Help: "The total number of HTTP backend cache misses",
	})
)
func (r *remoteHTTPProxyCache) uploadFile(item uploadReq) {
	if item.size == 0 {
		item.rc.Close()
		item.rc = http.NoBody
	}
	url := r.requestURL(item.hash, item.kind)
	req, err := http.NewRequestWithContext(context.Background(), http.MethodHead, url, nil)
	if err != nil {
		r.errorLogger.Printf("INTERNAL ERROR, FAILED TO SETUP HTTP PROXY UPLOAD %s: %s", url, err)
		item.rc.Close()
		return
	}
	rsp, err := r.remote.Do(req)
	if err == nil && rsp.StatusCode == http.StatusOK {
		r.accessLogger.Printf("SKIP UPLOAD %s", item.hash)
		item.rc.Close()
		return
	}
	req, err = http.NewRequestWithContext(context.Background(), http.MethodPut, url, item.rc)
	if err != nil {
		r.errorLogger.Printf("INTERNAL ERROR, FAILED TO SETUP HTTP PROXY UPLOAD %s: %s", url, err)
		item.rc.Close()
		return
	}
	req.Header.Set("Content-Type", "application/octet-stream")
	req.ContentLength = item.size
	rsp, err = r.remote.Do(req)
	if err != nil {
		r.errorLogger.Printf("HTTP %s UPLOAD: %s", url, err.Error())
		return
	}
	_, err = io.Copy(ioutil.Discard, rsp.Body)
	if err != nil {
		r.errorLogger.Printf("HTTP %s UPLOAD: %s", url, err.Error())
		return
	}
	rsp.Body.Close()
	logResponse(r.accessLogger, "UPLOAD", rsp.StatusCode, url)
}
func New(baseURL *url.URL, storageMode string, remote *http.Client,
	accessLogger cache.Logger, errorLogger cache.Logger,
	numUploaders, maxQueuedUploads int) (cache.Proxy, error) {
	proxy := &remoteHTTPProxyCache{
		remote:       remote,
		baseURL:      strings.TrimRight(baseURL.String(), "/"),
		accessLogger: accessLogger,
		errorLogger:  errorLogger,
		v2mode:       storageMode == "zstd",
	}
	if storageMode == "zstd" {
		proxy.requestURL = func(hash string, kind cache.EntryKind) string {
			if kind == cache.CAS {
				return fmt.Sprintf("%s/cas.v2/%s", proxy.baseURL, hash)
			}
			return fmt.Sprintf("%s/%s/%s", proxy.baseURL, kind, hash)
		}
	} else if storageMode == "uncompressed" {
		proxy.requestURL = func(hash string, kind cache.EntryKind) string {
			return fmt.Sprintf("%s/%s/%s", proxy.baseURL, kind, hash)
		}
	} else {
		return nil, fmt.Errorf("Invalid http_proxy.mode specified: %q",
			storageMode)
	}
	if maxQueuedUploads > 0 && numUploaders > 0 {
		uploadQueue := make(chan uploadReq, maxQueuedUploads)
		for i := 0; i < numUploaders; i++ {
			go func() {
				for item := range uploadQueue {
					proxy.uploadFile(item)
				}
			}()
		}
		proxy.uploadQueue = uploadQueue
	}
	return proxy, nil
}