package server import ( "net/http" "strconv" ) func rewriteHeaders(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { forwardedMethod := r.Header.Get("X-Forwarded-Method") forwardedUri := r.Header.Get("X-Forwarded-Uri") forwardedContentLength := r.Header.Get("X-Forwarded-Content-Length") r.Method = forwardedMethod r.URL.Path = forwardedUri contentLength, err := strconv.Atoi(forwardedContentLength) if err != nil { http.Error(w, "Bad forwarded content length", 400) } r.ContentLength = int64(contentLength) next.ServeHTTP(w, r) }) }