diff --git a/server/authorizer/authorizer.go b/server/authorizer/authorizer.go index 1f706c56d51..62182ce5e22 100644 --- a/server/authorizer/authorizer.go +++ b/server/authorizer/authorizer.go @@ -6,6 +6,8 @@ package authorizer import ( + "bytes" + "compress/gzip" "context" "io" "net/http" @@ -151,7 +153,6 @@ func (h *Basic) ServeHTTP(w http.ResponseWriter, r *http.Request) { } func makeInput(r *http.Request) (*http.Request, interface{}, error) { - path, err := parsePath(r.URL.Path) if err != nil { return r, nil, err @@ -164,7 +165,11 @@ func makeInput(r *http.Request) (*http.Request, interface{}, error) { if expectBody(r.Method, path) { var err error - rawBody, err = io.ReadAll(r.Body) + plaintextBody, err := readPlainBody(r) + if err != nil { + return r, nil, err + } + rawBody, err = io.ReadAll(plaintextBody) if err != nil { return r, nil, err } @@ -277,3 +282,20 @@ func GetBodyOnContext(ctx context.Context) (interface{}, bool) { } return input.parsed, true } + +// Note(philipc): Copied over from server/server.go +func readPlainBody(r *http.Request) (io.ReadCloser, error) { + if strings.Contains(r.Header.Get("Content-Encoding"), "gzip") { + gzReader, err := gzip.NewReader(r.Body) + if err != nil { + return nil, err + } + bytesBody, err := io.ReadAll(gzReader) + if err != nil { + return nil, err + } + defer gzReader.Close() + return io.NopCloser(bytes.NewReader(bytesBody)), err + } + return r.Body, nil +}