Skip to content
Prev Previous commit
Next Next commit
Surface the writeTimeout to HttpRequest
  • Loading branch information
chingor13 committed Sep 26, 2018
commit 6f2122afa25347e4c784b7a2e904f6956d2c3d8f
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ static String executeAndGetValueOfSomeCustomHeader(HttpRequest request) {
*/
private int readTimeout = 20 * 1000;

/**
* Timeout in milliseconds to set POST/PUT data or {@code 0} for an infinite timeout.
*/
private int writeTimeout = 0;

/** HTTP unsuccessful (non-2XX) response handler or {@code null} for none. */
private HttpUnsuccessfulResponseHandler unsuccessfulResponseHandler;

Expand Down Expand Up @@ -493,6 +498,30 @@ public HttpRequest setReadTimeout(int readTimeout) {
return this;
}

/**
* Returns the timeout in milliseconds to send POST/PUT data or {@code 0} for an infinite timeout.
*
* <p>
* By default it is 0 (infinite).
* </p>
*
* @since 1.26
*/
public int getWriteTimeout() {
return writeTimeout;
}

/**
* Sets the timeout in milliseconds to send POST/PUT data or {@code 0} for an infinite timeout.
*
* @since 1.26
*/
public HttpRequest setWriteTimeout(int writeTimeout) {
Preconditions.checkArgument(writeTimeout >= 0);
this.writeTimeout = writeTimeout;
return this;
}

/**
* Returns the HTTP request headers.
*
Expand Down Expand Up @@ -977,6 +1006,7 @@ public HttpResponse execute() throws IOException {

// execute
lowLevelHttpRequest.setTimeout(connectTimeout, readTimeout);
lowLevelHttpRequest.setWriteTimeout(writeTimeout);
try {
LowLevelHttpResponse lowLevelHttpResponse = lowLevelHttpRequest.execute();
// Flag used to indicate if an exception is thrown before the response is constructed.
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@
<configuration>
<signature>
<groupId>org.codehaus.mojo.signature</groupId>
<artifactId>java15</artifactId>
<artifactId>java16</artifactId>
<version>1.0</version>
</signature>
</configuration>
Expand Down