Browse Source

Merge branch '5.1.x'

pull/22689/head
Arjen Poutsma 6 years ago
parent
commit
dba04a7338
  1. 6
      spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultEntityResponseBuilder.java
  2. 4
      spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultRenderingResponseBuilder.java
  3. 27
      spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultServerResponseBuilder.java
  4. 12
      spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DefaultServerResponseBuilderTests.java

6
spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultEntityResponseBuilder.java

@ -1,5 +1,5 @@ @@ -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.
@ -202,16 +202,14 @@ class DefaultEntityResponseBuilder<T> implements EntityResponse.Builder<T> { @@ -202,16 +202,14 @@ class DefaultEntityResponseBuilder<T> implements EntityResponse.Builder<T> {
private final BodyInserter<T, ? super ServerHttpResponse> inserter;
private final Map<String, Object> hints;
public DefaultEntityResponse(int statusCode, HttpHeaders headers,
MultiValueMap<String, ResponseCookie> cookies, T entity,
BodyInserter<T, ? super ServerHttpResponse> inserter, Map<String, Object> hints) {
super(statusCode, headers, cookies);
super(statusCode, headers, cookies, hints);
this.entity = entity;
this.inserter = inserter;
this.hints = hints;
}
@Override

4
spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultRenderingResponseBuilder.java

@ -1,5 +1,5 @@ @@ -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.
@ -168,7 +168,7 @@ final class DefaultRenderingResponseBuilder implements RenderingResponse.Builder @@ -168,7 +168,7 @@ final class DefaultRenderingResponseBuilder implements RenderingResponse.Builder
public DefaultRenderingResponse(int statusCode, HttpHeaders headers,
MultiValueMap<String, ResponseCookie> cookies, String name, Map<String, Object> model) {
super(statusCode, headers, cookies);
super(statusCode, headers, cookies, Collections.emptyMap());
this.name = name;
this.model = Collections.unmodifiableMap(new LinkedHashMap<>(model));
}

27
spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultServerResponseBuilder.java

@ -1,5 +1,5 @@ @@ -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.
@ -20,6 +20,7 @@ import java.net.URI; @@ -20,6 +20,7 @@ import java.net.URI;
import java.time.Instant;
import java.time.ZonedDateTime;
import java.util.Arrays;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.LinkedHashSet;
@ -73,9 +74,16 @@ class DefaultServerResponseBuilder implements ServerResponse.BodyBuilder { @@ -73,9 +74,16 @@ class DefaultServerResponseBuilder implements ServerResponse.BodyBuilder {
public DefaultServerResponseBuilder(ServerResponse other) {
Assert.notNull(other, "ServerResponse must not be null");
this.statusCode = (other instanceof AbstractServerResponse ?
((AbstractServerResponse) other).statusCode : other.statusCode().value());
this.headers.addAll(other.headers());
this.cookies.addAll(other.cookies());
if (other instanceof AbstractServerResponse) {
AbstractServerResponse abstractOther = (AbstractServerResponse) other;
this.statusCode = abstractOther.statusCode;
this.hints.putAll(abstractOther.hints);
}
else {
this.statusCode = other.statusCode().value();
}
}
public DefaultServerResponseBuilder(HttpStatus status) {
@ -289,12 +297,17 @@ class DefaultServerResponseBuilder implements ServerResponse.BodyBuilder { @@ -289,12 +297,17 @@ class DefaultServerResponseBuilder implements ServerResponse.BodyBuilder {
private final MultiValueMap<String, ResponseCookie> cookies;
final Map<String, Object> hints;
protected AbstractServerResponse(
int statusCode, HttpHeaders headers, MultiValueMap<String, ResponseCookie> cookies) {
int statusCode, HttpHeaders headers, MultiValueMap<String, ResponseCookie> cookies,
Map<String, Object> hints) {
this.statusCode = statusCode;
this.headers = HttpHeaders.readOnlyHttpHeaders(headers);
this.cookies = CollectionUtils.unmodifiableMultiValueMap(new LinkedMultiValueMap<>(cookies));
this.hints = hints;
}
@Override
@ -361,7 +374,7 @@ class DefaultServerResponseBuilder implements ServerResponse.BodyBuilder { @@ -361,7 +374,7 @@ class DefaultServerResponseBuilder implements ServerResponse.BodyBuilder {
MultiValueMap<String, ResponseCookie> cookies,
BiFunction<ServerWebExchange, Context, Mono<Void>> writeFunction) {
super(statusCode, headers, cookies);
super(statusCode, headers, cookies, Collections.emptyMap());
Assert.notNull(writeFunction, "BiFunction must not be null");
this.writeFunction = writeFunction;
}
@ -377,16 +390,14 @@ class DefaultServerResponseBuilder implements ServerResponse.BodyBuilder { @@ -377,16 +390,14 @@ class DefaultServerResponseBuilder implements ServerResponse.BodyBuilder {
private final BodyInserter<T, ? super ServerHttpResponse> inserter;
private final Map<String, Object> hints;
public BodyInserterResponse(int statusCode, HttpHeaders headers,
MultiValueMap<String, ResponseCookie> cookies,
BodyInserter<T, ? super ServerHttpResponse> body, Map<String, Object> hints) {
super(statusCode, headers, cookies);
super(statusCode, headers, cookies, hints);
Assert.notNull(body, "BodyInserter must not be null");
this.inserter = body;
this.hints = hints;
}
@Override

12
spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DefaultServerResponseBuilderTests.java

@ -1,5 +1,5 @@ @@ -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.
@ -65,11 +65,17 @@ public class DefaultServerResponseBuilderTests { @@ -65,11 +65,17 @@ public class DefaultServerResponseBuilderTests {
@Test
public void from() {
ServerResponse other = ServerResponse.ok().header("foo", "bar").build().block();
ResponseCookie cookie = ResponseCookie.from("foo", "bar").build();
ServerResponse other = ServerResponse.ok().header("foo", "bar")
.cookie(cookie)
.hint("foo", "bar")
.build().block();
Mono<ServerResponse> result = ServerResponse.from(other).build();
StepVerifier.create(result)
.expectNextMatches(response -> HttpStatus.OK.equals(response.statusCode()) &&
"bar".equals(response.headers().getFirst("foo")))
"bar".equals(response.headers().getFirst("foo")) &&
cookie.equals(response.cookies().getFirst("foo")))
.expectComplete()
.verify();
}

Loading…
Cancel
Save