mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-10-09 00:29:04 +00:00
Handle zero readTimeout in JdkClientHttpConnector
Prior to this commit, JdkClientHttpConnector#setReadTimeout(Duration)
passed Duration.ZERO through to HttpRequest.Builder#timeout, which
rejects non-positive durations. As a result, every request failed with
an IllegalArgumentException ("Invalid duration: PT0S").
gh-37234 already treats a zero read timeout as an infinite timeout in
JdkClientHttpRequestFactory, which is backed by the same JDK HttpClient
API.
This commit applies the same handling to the reactive
JdkClientHttpConnector so that a zero Duration results in no timeout
being set on the underlying request.
See gh-37232
Closes gh-37412
Signed-off-by: lejuho <52308082+lejuho@users.noreply.github.com>
This commit is contained in:
+2
-1
@@ -101,13 +101,14 @@ public class JdkClientHttpConnector implements ClientHttpConnector {
|
||||
|
||||
/**
|
||||
* Set the underlying {@code HttpClient} read timeout as a {@code Duration}.
|
||||
* A timeout value of 0 specifies an infinite timeout.
|
||||
* <p>Default is the system's default timeout.
|
||||
* @since 6.2
|
||||
* @see java.net.http.HttpRequest.Builder#timeout
|
||||
*/
|
||||
public void setReadTimeout(Duration readTimeout) {
|
||||
Assert.notNull(readTimeout, "readTimeout is required");
|
||||
this.readTimeout = readTimeout;
|
||||
this.readTimeout = (Duration.ZERO.equals(readTimeout) ? null : readTimeout);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+13
@@ -241,6 +241,19 @@ class ClientHttpConnectorTests {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void readTimeoutZeroWithJdk() {
|
||||
JdkClientHttpConnector connector = new JdkClientHttpConnector();
|
||||
connector.setReadTimeout(Duration.ZERO);
|
||||
|
||||
prepareResponse(builder -> builder.code(200));
|
||||
Mono<ClientHttpResponse> futureResponse =
|
||||
connector.connect(HttpMethod.GET, this.server.url("/").uri(), ReactiveHttpOutputMessage::setComplete);
|
||||
StepVerifier.create(futureResponse)
|
||||
.assertNext(response -> assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK))
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
private Buffer randomBody(int size) {
|
||||
Buffer responseBody = new Buffer();
|
||||
Random rnd = new Random();
|
||||
|
||||
Reference in New Issue
Block a user