Add DataBuffer management in fragment rendering
See gh-33194
This commit is contained in:
parent
8e2b27e5d8
commit
062c18a81d
|
|
@ -282,8 +282,9 @@ public class ViewResolutionResultHandler extends HandlerResultHandlerSupport imp
|
||||||
streamHandler.updateResponse(exchange);
|
streamHandler.updateResponse(exchange);
|
||||||
}
|
}
|
||||||
|
|
||||||
Flux<Flux<DataBuffer>> renderFlux = render.fragments().concatMap(fragment ->
|
Flux<Flux<DataBuffer>> renderFlux = render.fragments()
|
||||||
renderFragment(fragment, streamHandler, locale, bindingContext, exchange));
|
.concatMap(fragment -> renderFragment(fragment, streamHandler, locale, bindingContext, exchange))
|
||||||
|
.doOnDiscard(DataBuffer.class, DataBufferUtils::release);
|
||||||
|
|
||||||
return response.writeAndFlushWith(renderFlux);
|
return response.writeAndFlushWith(renderFlux);
|
||||||
}
|
}
|
||||||
|
|
@ -552,9 +553,16 @@ public class ViewResolutionResultHandler extends HandlerResultHandlerSupport imp
|
||||||
DataBuffer suffix = encodeText("\n\n", charset, bufferFactory);
|
DataBuffer suffix = encodeText("\n\n", charset, bufferFactory);
|
||||||
|
|
||||||
Mono<DataBuffer> content = DataBufferUtils.join(fragmentFlux)
|
Mono<DataBuffer> content = DataBufferUtils.join(fragmentFlux)
|
||||||
.map(dataBuffer -> {
|
.map(buffer -> {
|
||||||
String s = dataBuffer.toString(charset).replace("\n", "\ndata:");
|
String text;
|
||||||
return bufferFactory.wrap(s.getBytes(charset));
|
try {
|
||||||
|
text = buffer.toString(charset);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
DataBufferUtils.release(buffer);
|
||||||
|
}
|
||||||
|
text = text.replace("\n", "\ndata:");
|
||||||
|
return bufferFactory.wrap(text.getBytes(charset));
|
||||||
});
|
});
|
||||||
|
|
||||||
return Flux.concat(Flux.just(prefix), content, Flux.just(suffix));
|
return Flux.concat(Flux.just(prefix), content, Flux.just(suffix));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue