Have ReactiveTypeHandler consider +x-ndjson suffix as streaming
This commit adds `application/*+x-ndjson`, a wildcard media type which covers all types that can be parsed as nd-json, to the list of media types the ReactiveTypeHandler considers for a streaming response in WebMVC. As a result, a request which for example `Accept` the `application/vnd.myapp.v1+x-ndjson` media type will generate a response with the same `Content-Type`, with newline-delimited json objects being streamed in the response body. Closes gh-26817
This commit is contained in:
@@ -255,6 +255,32 @@ public class ReactiveTypeHandlerTests {
|
||||
assertThat(emitterHandler.getValues()).isEqualTo(Arrays.asList(bar1, "\n", bar2, "\n"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void writeStreamJsonWithVendorSubtype() throws Exception {
|
||||
this.servletRequest.addHeader("Accept", "application/vnd.myapp.v1+x-ndjson");
|
||||
|
||||
Sinks.Many<Bar> sink = Sinks.many().unicast().onBackpressureBuffer();
|
||||
ResponseBodyEmitter emitter = handleValue(sink.asFlux(), Flux.class, forClass(Bar.class));
|
||||
|
||||
assertThat(emitter).as("emitter").isNotNull();
|
||||
|
||||
EmitterHandler emitterHandler = new EmitterHandler();
|
||||
emitter.initialize(emitterHandler);
|
||||
|
||||
ServletServerHttpResponse message = new ServletServerHttpResponse(this.servletResponse);
|
||||
emitter.extendResponse(message);
|
||||
|
||||
Bar bar1 = new Bar("foo");
|
||||
Bar bar2 = new Bar("bar");
|
||||
|
||||
sink.tryEmitNext(bar1);
|
||||
sink.tryEmitNext(bar2);
|
||||
sink.tryEmitComplete();
|
||||
|
||||
assertThat(message.getHeaders().getContentType().toString()).isEqualTo("application/vnd.myapp.v1+x-ndjson");
|
||||
assertThat(emitterHandler.getValues()).isEqualTo(Arrays.asList(bar1, "\n", bar2, "\n"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void writeText() throws Exception {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user