If HTTP client asks for JSON, then time out the response
An HTTP response does not have to be an infinite stream, and in fact life is simpler if it is not. The timeout in the web wrappers can be used to close the response and return normally to a client that has been waiting more than (say) 1s, instead of treating it as an error condition. Error handling is still kind of unsolved.
This commit is contained in:
@@ -90,6 +90,14 @@ public class RestApplicationTests {
|
||||
.getBody()).isEqualTo("foobar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void timeoutJson() throws Exception {
|
||||
assertThat(rest
|
||||
.exchange(RequestEntity.get(new URI("/timeout"))
|
||||
.accept(MediaType.APPLICATION_JSON).build(), String.class)
|
||||
.getBody()).isEqualTo("[\"foo\"]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyJson() throws Exception {
|
||||
assertThat(rest
|
||||
@@ -213,6 +221,13 @@ public class RestApplicationTests {
|
||||
return () -> Flux.fromIterable(Collections.emptyList());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Supplier<Flux<String>> timeout() {
|
||||
return () -> Flux.create(emitter -> {
|
||||
emitter.next("foo");
|
||||
});
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Supplier<Flux<List<String>>> sentences() {
|
||||
return () -> Flux.just(Arrays.asList("go", "home"),
|
||||
|
||||
Reference in New Issue
Block a user