diff --git a/frpc.go b/frpc.go index 008894b..c091277 100644 --- a/frpc.go +++ b/frpc.go @@ -108,7 +108,7 @@ func CreateInstanceHandler(w http.ResponseWriter, r *http.Request) { return } - userID, _, err := ValidateRequest(w, r) + userID, _, err := ValidateRequestWithBody(w, r, body) if err != nil { SendErrorResponse(w, http.StatusUnauthorized, err.Error()) return @@ -185,7 +185,14 @@ func DeleteInstanceHandler(w http.ResponseWriter, r *http.Request, instanceName return } - userID, _, err := ValidateRequest(w, r) + body, err := io.ReadAll(r.Body) + if err != nil { + SendErrorResponse(w, http.StatusBadRequest, "failed to read request body") + return + } + defer r.Body.Close() + + userID, _, err := ValidateRequestWithBody(w, r, body) if err != nil { SendErrorResponse(w, http.StatusUnauthorized, err.Error()) return @@ -263,7 +270,7 @@ func ModifyInstanceHandler(w http.ResponseWriter, r *http.Request, instanceName return } - userID, _, err := ValidateRequest(w, r) + userID, _, err := ValidateRequestWithBody(w, r, body) if err != nil { SendErrorResponse(w, http.StatusUnauthorized, err.Error()) return @@ -393,7 +400,14 @@ func ListInstancesHandler(w http.ResponseWriter, r *http.Request) { return } - userID, _, err := ValidateRequest(w, r) + body, err := io.ReadAll(r.Body) + if err != nil { + SendErrorResponse(w, http.StatusBadRequest, "failed to read request body") + return + } + defer r.Body.Close() + + userID, _, err := ValidateRequestWithBody(w, r, body) if err != nil { SendErrorResponse(w, http.StatusUnauthorized, err.Error()) return diff --git a/handlers.go b/handlers.go index fd6322b..72c1853 100644 --- a/handlers.go +++ b/handlers.go @@ -202,6 +202,10 @@ func ValidateRequest(w http.ResponseWriter, r *http.Request, requiredFields ...s } defer r.Body.Close() + return ValidateRequestWithBody(w, r, body, requiredFields...) +} + +func ValidateRequestWithBody(w http.ResponseWriter, r *http.Request, body []byte, requiredFields ...string) (int, string, error) { var reqMap map[string]interface{} if err := json.Unmarshal(body, &reqMap); err != nil { return 0, "", errors.New("invalid request format") diff --git a/super-frpc-linux b/super-frpc-linux index 198561a..9b40440 100644 Binary files a/super-frpc-linux and b/super-frpc-linux differ