Add RenderingResponse.from
This commit introduces RenderingResponse.from(RenderingResponse), allowing for easier response filtering.
This commit is contained in:
@@ -46,6 +46,20 @@ public interface RenderingResponse extends ServerResponse {
|
||||
|
||||
// Builder
|
||||
|
||||
/**
|
||||
* Create a builder with the template name, status code, headers and model of the given response.
|
||||
* @param other the response to copy the values from
|
||||
* @return the created builder
|
||||
*/
|
||||
static Builder from(RenderingResponse other) {
|
||||
Assert.notNull(other, "'other' must not be null");
|
||||
DefaultRenderingResponseBuilder builder = new DefaultRenderingResponseBuilder(other.name());
|
||||
builder.status(other.statusCode());
|
||||
builder.headers(other.headers());
|
||||
builder.modelAttributes(other.model());
|
||||
return builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a builder with the given template name.
|
||||
* @param name the name of the template to render
|
||||
|
||||
@@ -56,14 +56,9 @@ public class RenderingResponseIntegrationTests extends AbstractRouterFunctionInt
|
||||
RouterFunction<RenderingResponse> normalRoute = route(GET("/normal"), handler::render);
|
||||
RouterFunction<RenderingResponse> filteredRoute = route(GET("/filter"), handler::render)
|
||||
.filter(ofResponseProcessor(
|
||||
response -> {
|
||||
Map<String, Object> model = new LinkedHashMap<>(response.model());
|
||||
model.put("qux", "quux");
|
||||
|
||||
return RenderingResponse.create(response.name())
|
||||
.modelAttributes(model)
|
||||
.build();
|
||||
}));
|
||||
response -> RenderingResponse.from(response)
|
||||
.modelAttribute("qux", "quux")
|
||||
.build()));
|
||||
|
||||
return normalRoute.and(filteredRoute);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user