|
51 | 51 | import java.io.InputStream;
|
52 | 52 | import java.net.HttpURLConnection;
|
53 | 53 | import java.net.ServerSocket;
|
| 54 | +import java.net.Socket; |
54 | 55 | import java.net.URL;
|
55 | 56 | import java.nio.charset.StandardCharsets;
|
56 | 57 | import java.time.Duration;
|
@@ -140,6 +141,10 @@ static void afterAll() {
|
140 | 141 |
|
141 | 142 | @BeforeEach
|
142 | 143 | void beforeEachTest() {
|
| 144 | + AbstractConfiguration config = ConfigurationManager.getConfigInstance(); |
| 145 | + config.setProperty("server.http.request.headers.read.timeout.enabled", false); |
| 146 | + config.setProperty("server.http.request.headers.read.timeout", 10000); |
| 147 | + |
143 | 148 | this.pathSegment = randomPathSegment();
|
144 | 149 |
|
145 | 150 | this.wireMock = wireMockExtension.getRuntimeInfo().getWireMock();
|
@@ -252,6 +257,63 @@ void httpGetFailsDueToOriginReadTimeout(
|
252 | 257 | verifyResponseHeaders(response);
|
253 | 258 | }
|
254 | 259 |
|
| 260 | + @ParameterizedTest |
| 261 | + @MethodSource("arguments") |
| 262 | + void httpGetHappyPathWithHeadersReadTimeout( |
| 263 | + final String description, |
| 264 | + final OkHttpClient okHttp, |
| 265 | + final boolean requestBodyBuffering, |
| 266 | + final boolean responseBodyBuffering) |
| 267 | + throws Exception { |
| 268 | + AbstractConfiguration config = ConfigurationManager.getConfigInstance(); |
| 269 | + config.setProperty("server.http.request.headers.read.timeout.enabled", true); |
| 270 | + |
| 271 | + wireMock.register(get(anyUrl()).willReturn(ok().withBody("hello world"))); |
| 272 | + |
| 273 | + Request request = setupRequestBuilder(requestBodyBuffering, responseBodyBuffering) |
| 274 | + .get() |
| 275 | + .build(); |
| 276 | + Response response = okHttp.newCall(request).execute(); |
| 277 | + assertThat(response.code()).isEqualTo(200); |
| 278 | + assertThat(response.body().string()).isEqualTo("hello world"); |
| 279 | + verifyResponseHeaders(response); |
| 280 | + } |
| 281 | + |
| 282 | + @ParameterizedTest |
| 283 | + @MethodSource("arguments") |
| 284 | + void httpPostHappyPathWithHeadersReadTimeout( |
| 285 | + final String description, |
| 286 | + final OkHttpClient okHttp, |
| 287 | + final boolean requestBodyBuffering, |
| 288 | + final boolean responseBodyBuffering) |
| 289 | + throws Exception { |
| 290 | + AbstractConfiguration config = ConfigurationManager.getConfigInstance(); |
| 291 | + config.setProperty("server.http.request.headers.read.timeout.enabled", true); |
| 292 | + |
| 293 | + wireMock.register(post(anyUrl()).willReturn(ok().withBody("Thank you next"))); |
| 294 | + |
| 295 | + Request request = setupRequestBuilder(requestBodyBuffering, responseBodyBuffering) |
| 296 | + .post(RequestBody.create("Simple POST request body".getBytes(StandardCharsets.UTF_8))) |
| 297 | + .build(); |
| 298 | + Response response = okHttp.newCall(request).execute(); |
| 299 | + assertThat(response.code()).isEqualTo(200); |
| 300 | + assertThat(response.body().string()).isEqualTo("Thank you next"); |
| 301 | + verifyResponseHeaders(response); |
| 302 | + } |
| 303 | + |
| 304 | + @Test |
| 305 | + void httpGetFailsDueToHeadersReadTimeout() throws Exception { |
| 306 | + AbstractConfiguration config = ConfigurationManager.getConfigInstance(); |
| 307 | + config.setProperty("server.http.request.headers.read.timeout.enabled", true); |
| 308 | + config.setProperty("server.http.request.headers.read.timeout", 100); |
| 309 | + |
| 310 | + Socket slowClient = new Socket("localhost", ZUUL_SERVER_PORT); |
| 311 | + Thread.sleep(500); |
| 312 | + // end of stream reached because zuul closed the connection |
| 313 | + assertThat(slowClient.getInputStream().read()).isEqualTo(-1); |
| 314 | + slowClient.close(); |
| 315 | + } |
| 316 | + |
255 | 317 | @ParameterizedTest
|
256 | 318 | @MethodSource("arguments")
|
257 | 319 | void httpGetFailsDueToMalformedResponseChunk(
|
|
0 commit comments