kevin 4 жил өмнө
parent
commit
d6c7da521e

+ 1 - 11
rest/httpx/requests.go

@@ -34,11 +34,7 @@ func Parse(r *http.Request, v interface{}) error {
 		return err
 	}
 
-	if r.ContentLength > 0 {
-		return ParseJsonBody(r, v)
-	}
-
-	return nil
+	return ParseJsonBody(r, v)
 }
 
 // Parses the form request.
@@ -87,12 +83,6 @@ func ParseHeader(headerValue string) map[string]string {
 
 // Parses the post request which contains json in body.
 func ParseJsonBody(r *http.Request, v interface{}) error {
-	switch r.Method {
-	case http.MethodDelete, http.MethodPatch, http.MethodPost, http.MethodPut:
-	default:
-		return ErrBodylessRequest
-	}
-
 	var reader io.Reader
 	if withJsonBody(r) {
 		reader = io.LimitReader(r.Body, maxBodyLen)

+ 0 - 20
rest/httpx/requests_test.go

@@ -134,26 +134,6 @@ func BenchmarkParseRaw(b *testing.B) {
 	}
 }
 
-func TestParseJsonBodyless(t *testing.T) {
-	methods := []string{
-		http.MethodConnect,
-		http.MethodGet,
-		http.MethodHead,
-		http.MethodOptions,
-		http.MethodTrace,
-	}
-
-	for _, method := range methods {
-		t.Run(method, func(t *testing.T) {
-			r, err := http.NewRequest(http.MethodGet, "http://hello.com", nil)
-			if err != nil {
-				t.Fatal(err)
-			}
-			assert.Equal(t, ErrBodylessRequest, ParseJsonBody(r, nil))
-		})
-	}
-}
-
 func BenchmarkParseAuto(b *testing.B) {
 	r, err := http.NewRequest(http.MethodGet, "http://hello.com/a?name=hello&age=18&percent=3.4", nil)
 	if err != nil {

+ 0 - 4
rest/httpx/vars.go

@@ -1,7 +1,5 @@
 package httpx
 
-import "errors"
-
 const (
 	ApplicationJson = "application/json"
 	ContentEncoding = "Content-Encoding"
@@ -19,5 +17,3 @@ const (
 	CodeSignatureWrongTime
 	CodeSignatureInvalidToken
 )
-
-var ErrBodylessRequest = errors.New("not a POST|PUT|PATCH|DELETE request")