10
10
import com .squareup .okhttp .MultipartBuilder ;
11
11
import com .squareup .okhttp .MediaType ;
12
12
import com .squareup .okhttp .Headers ;
13
+ import com .squareup .okhttp .internal .http .HttpMethod ;
13
14
14
15
import java .lang .reflect .Type ;
15
16
@@ -697,7 +698,7 @@ public <T> T handleResponse(Response response, Type returnType) throws ApiExcept
697
698
* Build HTTP call with the given options.
698
699
*
699
700
* @param path The sub-path of the HTTP URL
700
- * @param method The request method, one of "GET", "HEAD", "POST", "PUT", "PATCH" and "DELETE"
701
+ * @param method The request method, one of "GET", "HEAD", "OPTIONS", " POST", "PUT", "PATCH" and "DELETE"
701
702
* @param queryParams The query parameters
702
703
* @param body The request body object
703
704
* @param headerParams The header parameters
@@ -717,7 +718,7 @@ public Call buildCall(String path, String method, List<Pair> queryParams, Object
717
718
if (contentType == null ) contentType = "application/json" ;
718
719
719
720
RequestBody reqBody ;
720
- if ("GET" . equals ( method ) || "HEAD" . equals (method )) {
721
+ if (! HttpMethod . permitsRequestBody (method )) {
721
722
reqBody = null ;
722
723
} else if ("application/x-www-form-urlencoded" .equals (contentType )) {
723
724
reqBody = buildRequestBodyFormEncoding (formParams );
@@ -735,28 +736,7 @@ public Call buildCall(String path, String method, List<Pair> queryParams, Object
735
736
reqBody = RequestBody .create (MediaType .parse (contentType ), serialize (body , contentType ));
736
737
}
737
738
738
- Request request ;
739
- if ("GET" .equals (method )) {
740
- request = reqBuilder .get ().build ();
741
- } else if ("HEAD" .equals (method )) {
742
- request = reqBuilder .head ().build ();
743
- } else if ("POST" .equals (method )) {
744
- request = reqBuilder .post (reqBody ).build ();
745
- } else if ("PUT" .equals (method )) {
746
- request = reqBuilder .put (reqBody ).build ();
747
- } else if ("PATCH" .equals (method )) {
748
- request = reqBuilder .patch (reqBody ).build ();
749
- } else if ("DELETE" .equals (method )) {
750
- if (reqBody == null ) {
751
- // calling DELETE without sending a request body
752
- request = reqBuilder .delete ().build ();
753
- } else {
754
- request = reqBuilder .delete (reqBody ).build ();
755
- }
756
- } else {
757
- throw new ApiException ("unknown method type: " + method );
758
- }
759
-
739
+ Request request = reqBuilder .method (method , reqBody ).build ();
760
740
return httpClient .newCall (request );
761
741
}
762
742
0 commit comments