1package upstream 2 3import ( 4 "compress/gzip" 5 "fmt" 6 "io" 7 "net/http" 8 9 "gitlab.com/gitlab-org/gitlab/workhorse/internal/helper" 10) 11 12func contentEncodingHandler(h http.Handler) http.Handler { 13 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 14 var body io.ReadCloser 15 var err error 16 17 // The client request body may have been gzipped. 18 contentEncoding := r.Header.Get("Content-Encoding") 19 switch contentEncoding { 20 case "": 21 body = r.Body 22 case "gzip": 23 body, err = gzip.NewReader(r.Body) 24 default: 25 err = fmt.Errorf("unsupported content encoding: %s", contentEncoding) 26 } 27 28 if err != nil { 29 helper.Fail500(w, r, fmt.Errorf("contentEncodingHandler: %v", err)) 30 return 31 } 32 defer body.Close() 33 34 r.Body = body 35 r.Header.Del("Content-Encoding") 36 37 h.ServeHTTP(w, r) 38 }) 39} 40