Merge branch '5.1.x'

This commit is contained in:
Arjen Poutsma
2019-03-26 16:19:57 +01:00
5 changed files with 64 additions and 7 deletions

View File

@@ -157,6 +157,12 @@ class DefaultEntityResponseBuilder<T> implements EntityResponse.Builder<T> {
return this;
}
@Override
public EntityResponse.Builder<T> hints(Consumer<Map<String, Object>> hintsConsumer) {
hintsConsumer.accept(this.hints);
return this;
}
@Override
public EntityResponse.Builder<T> lastModified(ZonedDateTime lastModified) {
this.headers.setLastModified(lastModified);

View File

@@ -165,6 +165,12 @@ class DefaultServerResponseBuilder implements ServerResponse.BodyBuilder {
return this;
}
@Override
public ServerResponse.BodyBuilder hints(Consumer<Map<String, Object>> hintsConsumer) {
hintsConsumer.accept(this.hints);
return this;
}
@Override
public ServerResponse.BodyBuilder lastModified(ZonedDateTime lastModified) {
this.headers.setLastModified(lastModified);
@@ -222,8 +228,10 @@ class DefaultServerResponseBuilder implements ServerResponse.BodyBuilder {
return new DefaultEntityResponseBuilder<>(publisher,
BodyInserters.fromPublisher(publisher, elementClass))
.headers(this.headers)
.status(this.statusCode)
.headers(this.headers)
.cookies(cookies -> cookies.addAll(this.cookies))
.hints(hints -> hints.putAll(this.hints))
.build()
.map(entityResponse -> entityResponse);
}
@@ -237,8 +245,10 @@ class DefaultServerResponseBuilder implements ServerResponse.BodyBuilder {
return new DefaultEntityResponseBuilder<>(publisher,
BodyInserters.fromPublisher(publisher, typeReference))
.headers(this.headers)
.status(this.statusCode)
.headers(this.headers)
.cookies(cookies -> cookies.addAll(this.cookies))
.hints(hints -> hints.putAll(this.hints))
.build()
.map(entityResponse -> entityResponse);
}
@@ -251,8 +261,10 @@ class DefaultServerResponseBuilder implements ServerResponse.BodyBuilder {
return new DefaultEntityResponseBuilder<>(body,
BodyInserters.fromObject(body))
.headers(this.headers)
.status(this.statusCode)
.headers(this.headers)
.cookies(cookies -> cookies.addAll(this.cookies))
.hints(hints -> hints.putAll(this.hints))
.build()
.map(entityResponse -> entityResponse);
}
@@ -266,8 +278,9 @@ class DefaultServerResponseBuilder implements ServerResponse.BodyBuilder {
@Override
public Mono<ServerResponse> render(String name, Object... modelAttributes) {
return new DefaultRenderingResponseBuilder(name)
.headers(this.headers)
.status(this.statusCode)
.headers(this.headers)
.cookies(cookies -> cookies.addAll(this.cookies))
.modelAttributes(modelAttributes)
.build()
.map(renderingResponse -> renderingResponse);
@@ -276,8 +289,9 @@ class DefaultServerResponseBuilder implements ServerResponse.BodyBuilder {
@Override
public Mono<ServerResponse> render(String name, Map<String, ?> model) {
return new DefaultRenderingResponseBuilder(name)
.headers(this.headers)
.status(this.statusCode)
.headers(this.headers)
.cookies(cookies -> cookies.addAll(this.cookies))
.modelAttributes(model)
.build()
.map(renderingResponse -> renderingResponse);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@ package org.springframework.web.reactive.function.server;
import java.net.URI;
import java.time.Instant;
import java.time.ZonedDateTime;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
@@ -262,6 +263,15 @@ public interface EntityResponse<T> extends ServerResponse {
*/
Builder<T> hint(String key, Object value);
/**
* Manipulate serialization hint with the given consumer.
*
* @param hintsConsumer a function that consumes the hints
* @return this builder
* @since 5.1.6
*/
Builder<T> hints(Consumer<Map<String, Object>> hintsConsumer);
/**
* Build the response.
* @return the built response

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -376,6 +376,15 @@ public interface ServerResponse {
*/
BodyBuilder hint(String key, Object value);
/**
* Manipulate serialization hint with the given consumer.
*
* @param hintsConsumer a function that consumes the hints
* @return this builder
* @since 5.1.6
*/
BodyBuilder hints(Consumer<Map<String, Object>> hintsConsumer);
/**
* Set the body of the response to the given asynchronous {@code Publisher} and return it.
* This convenience method combines {@link #body(BodyInserter)} and