|
20 | 20 | import java.security.cert.CertificateException; |
21 | 21 | import java.time.Duration; |
22 | 22 | import java.util.ArrayList; |
| 23 | +import java.util.Arrays; |
23 | 24 | import java.util.List; |
24 | 25 | import java.util.concurrent.BlockingQueue; |
25 | 26 | import java.util.concurrent.LinkedBlockingQueue; |
@@ -215,41 +216,24 @@ void testIssue253() { |
215 | 216 | .bindNow(); |
216 | 217 |
|
217 | 218 | HttpClient client = createClient(disposableServer::address); |
218 | | - |
219 | | - String value = |
220 | | - client.followRedirect(true) |
221 | | - .get() |
222 | | - .uri("/1") |
223 | | - .responseContent() |
224 | | - .aggregate() |
225 | | - .asString() |
226 | | - .block(Duration.ofSeconds(30)); |
227 | | - assertThat(value).isEqualTo("OK"); |
228 | | - |
229 | | - value = client.get() |
230 | | - .uri("/1") |
231 | | - .responseContent() |
232 | | - .aggregate() |
233 | | - .asString() |
234 | | - .block(Duration.ofSeconds(30)); |
235 | | - assertThat(value).isNull(); |
236 | | - |
237 | | - value = client.followRedirect(true) |
238 | | - .get() |
239 | | - .uri("/2") |
240 | | - .responseContent() |
241 | | - .aggregate() |
242 | | - .asString() |
243 | | - .block(Duration.ofSeconds(30)); |
244 | | - assertThat(value).isEqualTo("OK"); |
245 | | - |
246 | | - value = client.get() |
247 | | - .uri("/2") |
248 | | - .responseContent() |
249 | | - .aggregate() |
250 | | - .asString() |
251 | | - .block(Duration.ofSeconds(30)); |
252 | | - assertThat(value).isNull(); |
| 219 | + HttpClient redirectingClient = client.followRedirect(true); |
| 220 | + |
| 221 | + Flux<String> urls = Flux.just("/1", "/1", "/2", "/2"); |
| 222 | + Flux<HttpClient> clients = Flux.just(redirectingClient, client, redirectingClient, client); |
| 223 | + |
| 224 | + Flux.zip(urls, clients) |
| 225 | + .concatMap(t -> t.getT2() |
| 226 | + .get() |
| 227 | + .uri(t.getT1()) |
| 228 | + .responseContent() |
| 229 | + .aggregate() |
| 230 | + .asString() |
| 231 | + .defaultIfEmpty("null")) |
| 232 | + .collectList() |
| 233 | + .as(StepVerifier::create) |
| 234 | + .expectNext(Arrays.asList("OK", "null", "OK", "null")) |
| 235 | + .expectComplete() |
| 236 | + .verify(Duration.ofSeconds(30)); |
253 | 237 | } |
254 | 238 |
|
255 | 239 | /** |
@@ -358,66 +342,23 @@ void testIssue522() { |
358 | 342 |
|
359 | 343 | HttpClient client = createClient(disposableServer::address); |
360 | 344 |
|
361 | | - StepVerifier.create(client.followRedirect(true) |
362 | | - .get() |
363 | | - .uri("/301") |
364 | | - .responseContent() |
365 | | - .aggregate() |
366 | | - .asString()) |
367 | | - .expectNextMatches("OK"::equals) |
368 | | - .expectComplete() |
369 | | - .verify(Duration.ofSeconds(30)); |
370 | | - |
371 | | - StepVerifier.create(client.followRedirect(true) |
372 | | - .get() |
373 | | - .uri("/302") |
374 | | - .responseContent() |
375 | | - .aggregate() |
376 | | - .asString()) |
377 | | - .expectNextMatches("OK"::equals) |
378 | | - .expectComplete() |
379 | | - .verify(Duration.ofSeconds(30)); |
| 345 | + Flux.just("/301", "/302", "/303", "/307", "/308", "/predicate") |
| 346 | + .flatMap(s -> { |
| 347 | + HttpClient localClient = "/predicate".equals(s) ? |
| 348 | + client.followRedirect((req, res) -> res.responseHeaders().contains("test")) : |
| 349 | + client.followRedirect(true); |
| 350 | + return localClient.get() |
| 351 | + .uri(s) |
| 352 | + .responseContent() |
| 353 | + .aggregate() |
| 354 | + .asString(); |
| 355 | + }) |
| 356 | + .collectList() |
| 357 | + .as(StepVerifier::create) |
| 358 | + .assertNext(l -> assertThat(l).allMatch("OK"::equals)) |
| 359 | + .expectComplete() |
| 360 | + .verify(Duration.ofSeconds(30)); |
380 | 361 |
|
381 | | - StepVerifier.create(client.followRedirect(true) |
382 | | - .post() |
383 | | - .uri("/303") |
384 | | - .responseContent() |
385 | | - .aggregate() |
386 | | - .asString()) |
387 | | - .expectNextMatches("OK"::equals) |
388 | | - .expectComplete() |
389 | | - .verify(Duration.ofSeconds(30)); |
390 | | - |
391 | | - StepVerifier.create(client.followRedirect(true) |
392 | | - .get() |
393 | | - .uri("/307") |
394 | | - .responseContent() |
395 | | - .aggregate() |
396 | | - .asString()) |
397 | | - .expectNextMatches("OK"::equals) |
398 | | - .expectComplete() |
399 | | - .verify(Duration.ofSeconds(30)); |
400 | | - |
401 | | - StepVerifier.create(client.followRedirect(true) |
402 | | - .get() |
403 | | - .uri("/308") |
404 | | - .responseContent() |
405 | | - .aggregate() |
406 | | - .asString()) |
407 | | - .expectNextMatches("OK"::equals) |
408 | | - .expectComplete() |
409 | | - .verify(Duration.ofSeconds(30)); |
410 | | - |
411 | | - StepVerifier.create(client.followRedirect((req, res) -> res.responseHeaders() |
412 | | - .contains("test")) |
413 | | - .get() |
414 | | - .uri("/predicate") |
415 | | - .responseContent() |
416 | | - .aggregate() |
417 | | - .asString()) |
418 | | - .expectNextMatches("OK"::equals) |
419 | | - .expectComplete() |
420 | | - .verify(Duration.ofSeconds(30)); |
421 | 362 |
|
422 | 363 | StepVerifier.create(client.followRedirect(true) |
423 | 364 | .get() |
|
0 commit comments