Skip to content

Commit

Permalink
Add PUT method for HTTP requests
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 403220062
Change-Id: I7319cec7e168850ec9461237cce7f85ec3cc3eab
  • Loading branch information
Albert Cui authored and copybara-github committed Oct 14, 2021
1 parent ac8c852 commit 8c66bd0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,9 @@ private static Request buildOkHttpRequest(HttpRequest httpRequest) {
case HEAD:
okRequestBuilder.head();
break;
case PUT:
okRequestBuilder.put(buildRequestBody(httpRequest));
break;
case POST:
okRequestBuilder.post(buildRequestBody(httpRequest));
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public enum HttpMethod {
GET("GET"),
HEAD("HEAD"),
POST("POST"),
PUT("PUT"),
DELETE("DELETE");

private final String string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,28 @@ public static Builder post(HttpUrl uri) {
return builder().setMethod(HttpMethod.POST).setUrl(uri);
}

/**
* Create a new HTTP PUT request with the given {@code url}.
*
* @param url the url of the PUT request.
* @return a {@link Builder} object for configuring {@link HttpRequest}.
*/
public static Builder put(String url) {
checkArgument(!Strings.isNullOrEmpty(url));
return put(HttpUrl.parse(url));
}

/**
* Create a new HTTP PUT request with the given {@code uri}.
*
* @param uri the url of the PUT request.
* @return a {@link Builder} object for configuring {@link HttpRequest}.
*/
public static Builder put(HttpUrl uri) {
checkNotNull(uri);
return builder().setMethod(HttpMethod.PUT).setUrl(uri);
}

/**
* Create a new HTTP DELETE request with the given {@code url}.
*
Expand Down Expand Up @@ -164,6 +186,7 @@ public HttpRequest build() {
"A request body is not allowed for HTTP GET/HEAD request");
break;
case POST:
case PUT:
case DELETE:
break;
}
Expand Down

0 comments on commit 8c66bd0

Please sign in to comment.