@@ -48,7 +48,8 @@ public class ReactorClientHttpRequestFactory implements ClientHttpRequestFactory
48
48
49
49
private static final Log logger = LogFactory .getLog (ReactorClientHttpRequestFactory .class );
50
50
51
- private static final Function <HttpClient , HttpClient > defaultInitializer = client -> client .compress (true );
51
+ private static final Function <HttpClient , HttpClient > defaultInitializer =
52
+ client -> client .compress (true ).responseTimeout (Duration .ofSeconds (10 ));
52
53
53
54
54
55
@ Nullable
@@ -60,9 +61,11 @@ public class ReactorClientHttpRequestFactory implements ClientHttpRequestFactory
60
61
@ Nullable
61
62
private Integer connectTimeout ;
62
63
63
- private Duration readTimeout = Duration .ofSeconds (10 );
64
+ @ Nullable
65
+ private Duration readTimeout ;
64
66
65
- private Duration exchangeTimeout = Duration .ofSeconds (5 );
67
+ @ Nullable
68
+ private Duration exchangeTimeout ;
66
69
67
70
@ Nullable
68
71
private volatile HttpClient httpClient ;
@@ -120,12 +123,15 @@ private HttpClient createHttpClient(ReactorResourceFactory factory, Function<Htt
120
123
if (this .connectTimeout != null ) {
121
124
client = client .option (ChannelOption .CONNECT_TIMEOUT_MILLIS , this .connectTimeout );
122
125
}
126
+ if (this .readTimeout != null ) {
127
+ client = client .responseTimeout (this .readTimeout );
128
+ }
123
129
return client ;
124
130
}
125
131
126
132
127
133
/**
128
- * Set the underlying connect timeout value on the underlying client.
134
+ * Set the connect timeout value on the underlying client.
129
135
* Effectively, a shortcut for
130
136
* {@code httpClient.option(CONNECT_TIMEOUT_MILLIS, timeout)}.
131
137
* <p>By default, set to 30 seconds.
@@ -152,35 +158,53 @@ public void setConnectTimeout(Duration connectTimeout) {
152
158
}
153
159
154
160
/**
155
- * Set the underlying read timeout in milliseconds.
156
- * <p>Default is 10 seconds.
161
+ * Set the read timeout value on the underlying client.
162
+ * Effectively, a shortcut for {@link HttpClient#responseTimeout(Duration)}.
163
+ * <p>By default, set to 10 seconds.
164
+ * @param timeout the read timeout value in millis; must be > 0.
157
165
*/
158
- public void setReadTimeout (long readTimeout ) {
159
- Assert .isTrue (readTimeout > 0 , "Timeout must be a positive value" );
160
- this .readTimeout = Duration .ofMillis (readTimeout );
166
+ public void setReadTimeout (Duration timeout ) {
167
+ Assert .notNull (timeout , "ReadTimeout must not be null" );
168
+ Assert .isTrue (timeout .toMillis () > 0 , "Timeout must be a positive value" );
169
+ this .readTimeout = timeout ;
170
+ HttpClient httpClient = this .httpClient ;
171
+ if (httpClient != null ) {
172
+ this .httpClient = httpClient .responseTimeout (timeout );
173
+ }
161
174
}
162
175
163
176
/**
164
- * Variant of {@link #setConnectTimeout(int )} with a {@link Duration} value.
177
+ * Variant of {@link #setReadTimeout(Duration )} with a long value.
165
178
*/
166
- public void setReadTimeout (Duration readTimeout ) {
167
- Assert .notNull (readTimeout , "ReadTimeout must not be null" );
168
- setReadTimeout ((int ) readTimeout .toMillis ());
179
+ public void setReadTimeout (long readTimeout ) {
180
+ setReadTimeout (Duration .ofMillis (readTimeout ));
169
181
}
170
182
171
183
/**
172
184
* Set the timeout for the HTTP exchange in milliseconds.
173
- * <p>Default is 5 seconds.
185
+ * <p>By default, as of 6.2 this is no longer set.
186
+ * @see #setConnectTimeout(int)
187
+ * @see #setReadTimeout(Duration)
188
+ * @see <a href="https://projectreactor.io/docs/netty/release/reference/index.html#timeout-configuration">Timeout Configuration</a>
189
+ * @deprecated as of 6.2 and no longer set by default (previously 5 seconds)
190
+ * in favor of using Reactor Netty HttpClient timeout configuration.
174
191
*/
192
+ @ Deprecated (since = "6.2" , forRemoval = true )
175
193
public void setExchangeTimeout (long exchangeTimeout ) {
176
194
Assert .isTrue (exchangeTimeout > 0 , "Timeout must be a positive value" );
177
195
this .exchangeTimeout = Duration .ofMillis (exchangeTimeout );
178
196
}
179
197
180
198
/**
181
- * Set the timeout for the HTTP exchange.
182
- * <p>Default is 5 seconds.
199
+ * Variant of {@link #setExchangeTimeout(long)} with a Duration value.
200
+ * <p>By default, as of 6.2 this is no longer set.
201
+ * @see #setConnectTimeout(int)
202
+ * @see #setReadTimeout(Duration)
203
+ * @see <a href="https://projectreactor.io/docs/netty/release/reference/index.html#timeout-configuration">Timeout Configuration</a>
204
+ * @deprecated as of 6.2 and no longer set by default (previously 5 seconds)
205
+ * in favor of using Reactor Netty HttpClient timeout configuration.
183
206
*/
207
+ @ Deprecated (since = "6.2" , forRemoval = true )
184
208
public void setExchangeTimeout (Duration exchangeTimeout ) {
185
209
Assert .notNull (exchangeTimeout , "ExchangeTimeout must not be null" );
186
210
setExchangeTimeout ((int ) exchangeTimeout .toMillis ());
@@ -195,8 +219,7 @@ public ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IO
195
219
"Expected HttpClient or ResourceFactory and mapper" );
196
220
client = createHttpClient (this .resourceFactory , this .mapper );
197
221
}
198
- return new ReactorClientHttpRequest (
199
- client , uri , httpMethod , this .exchangeTimeout , this .readTimeout );
222
+ return new ReactorClientHttpRequest (client , httpMethod , uri , this .exchangeTimeout );
200
223
}
201
224
202
225
0 commit comments