Restore http.Request body for http.HandlerFunc in api package

This commit is contained in:
Patrick Pacher 2022-05-03 16:09:40 +02:00
parent 85f8832911
commit ba6dee246b
No known key found for this signature in database
GPG key ID: E8CD2DA160925A6D

View file

@ -1,9 +1,11 @@
package api
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"sort"
@ -413,6 +415,9 @@ func (e *Endpoint) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
apiRequest.InputData = inputData
// restore request body for any http.HandlerFunc below
r.Body = io.NopCloser(bytes.NewReader(inputData))
default:
// Defensive.
http.Error(w, "unsupported method for the actions API", http.StatusMethodNotAllowed)