Skip to content

Commit 087d239

Browse files
committed
Merge branch '6.2.x'
2 parents 73c4b46 + 18c3b63 commit 087d239

File tree

6 files changed

+60
-30
lines changed

6 files changed

+60
-30
lines changed

Diff for: spring-test/src/main/java/org/springframework/mock/web/server/MockServerWebExchange.java

+25-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
1919
import org.jspecify.annotations.Nullable;
2020
import reactor.core.publisher.Mono;
2121

22+
import org.springframework.context.ApplicationContext;
2223
import org.springframework.http.codec.ServerCodecConfigurer;
2324
import org.springframework.mock.http.server.reactive.MockServerHttpRequest;
2425
import org.springframework.mock.http.server.reactive.MockServerHttpResponse;
@@ -39,9 +40,15 @@
3940
*/
4041
public final class MockServerWebExchange extends DefaultServerWebExchange {
4142

42-
private MockServerWebExchange(MockServerHttpRequest request, WebSessionManager sessionManager) {
43-
super(request, new MockServerHttpResponse(), sessionManager,
44-
ServerCodecConfigurer.create(), new AcceptHeaderLocaleContextResolver());
43+
44+
private MockServerWebExchange(
45+
MockServerHttpRequest request, @Nullable WebSessionManager sessionManager,
46+
@Nullable ApplicationContext applicationContext) {
47+
48+
super(request, new MockServerHttpResponse(),
49+
sessionManager != null ? sessionManager : new DefaultWebSessionManager(),
50+
ServerCodecConfigurer.create(), new AcceptHeaderLocaleContextResolver(),
51+
applicationContext);
4552
}
4653

4754

@@ -100,6 +107,9 @@ public static class Builder {
100107

101108
private @Nullable WebSessionManager sessionManager;
102109

110+
@Nullable
111+
private ApplicationContext applicationContext;
112+
103113
public Builder(MockServerHttpRequest request) {
104114
this.request = request;
105115
}
@@ -126,12 +136,21 @@ public Builder sessionManager(WebSessionManager sessionManager) {
126136
return this;
127137
}
128138

139+
/**
140+
* Provide the {@code ApplicationContext} to expose through the exchange.
141+
* @param applicationContext the context to use
142+
* @since 6.2.5
143+
*/
144+
public Builder applicationContext(ApplicationContext applicationContext) {
145+
this.applicationContext = applicationContext;
146+
return this;
147+
}
148+
129149
/**
130150
* Build the {@code MockServerWebExchange} instance.
131151
*/
132152
public MockServerWebExchange build() {
133-
return new MockServerWebExchange(this.request,
134-
this.sessionManager != null ? this.sessionManager : new DefaultWebSessionManager());
153+
return new MockServerWebExchange(this.request, this.sessionManager, this.applicationContext);
135154
}
136155
}
137156

Diff for: spring-web/src/main/java/org/springframework/web/cors/CorsConfiguration.java

+4-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -287,14 +287,7 @@ private static void parseCommaDelimitedOrigin(String rawValue, Consumer<String>
287287
* allowCredentials} is set to {@code true}, that combination is handled
288288
* by copying the method specified in the CORS preflight request.
289289
* <p>If not set, only {@code "GET"} and {@code "HEAD"} are allowed.
290-
* <p>By default this is not set.
291-
* <p><strong>Note:</strong> CORS checks use values from "Forwarded"
292-
* (<a href="https://tools.ietf.org/html/rfc7239">RFC 7239</a>),
293-
* "X-Forwarded-Host", "X-Forwarded-Port", and "X-Forwarded-Proto" headers,
294-
* if present, in order to reflect the client-originated address.
295-
* Consider using the {@code ForwardedHeaderFilter} in order to choose from a
296-
* central place whether to extract and use, or to discard such headers.
297-
* See the Spring Framework reference for more on this filter.
290+
* <p>By default, this is not set.
298291
*/
299292
public void setAllowedMethods(@Nullable List<String> allowedMethods) {
300293
this.allowedMethods = (allowedMethods != null ? new ArrayList<>(allowedMethods) : null);
@@ -443,7 +436,7 @@ public void addExposedHeader(String exposedHeader) {
443436
* level of trust with the configured domains and also increases the surface
444437
* attack of the web application by exposing sensitive user-specific
445438
* information such as cookies and CSRF tokens.
446-
* <p>By default this is not set (i.e. user credentials are not supported).
439+
* <p>By default, this is not set (i.e. user credentials are not supported).
447440
*/
448441
public void setAllowCredentials(@Nullable Boolean allowCredentials) {
449442
this.allowCredentials = allowCredentials;
@@ -466,7 +459,7 @@ public void setAllowCredentials(@Nullable Boolean allowCredentials) {
466459
* <p>Setting this property has an impact on how {@link #setAllowedOrigins(List)
467460
* origins} and {@link #setAllowedOriginPatterns(List) originPatterns} are processed,
468461
* see related API documentation for more details.
469-
* <p>By default this is not set (i.e. private network access is not supported).
462+
* <p>By default, this is not set (i.e. private network access is not supported).
470463
* @since 5.3.32
471464
* @see <a href="https://wicg.github.io/private-network-access/">Private network access specifications</a>
472465
*/

Diff for: spring-web/src/main/java/org/springframework/web/server/adapter/DefaultServerWebExchange.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -117,7 +117,7 @@ public DefaultServerWebExchange(ServerHttpRequest request, ServerHttpResponse re
117117
this(request, response, sessionManager, codecConfigurer, localeContextResolver, null);
118118
}
119119

120-
DefaultServerWebExchange(ServerHttpRequest request, ServerHttpResponse response,
120+
protected DefaultServerWebExchange(ServerHttpRequest request, ServerHttpResponse response,
121121
WebSessionManager sessionManager, ServerCodecConfigurer codecConfigurer,
122122
LocaleContextResolver localeContextResolver, @Nullable ApplicationContext applicationContext) {
123123

Diff for: spring-webmvc/src/main/java/org/springframework/web/servlet/function/SseServerResponse.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -171,7 +171,6 @@ public SseBuilder retry(Duration duration) {
171171

172172
@Override
173173
public SseBuilder comment(String comment) {
174-
Assert.hasLength(comment, "Comment must not be empty");
175174
String[] lines = comment.split("\n");
176175
for (String line : lines) {
177176
field("", line);

Diff for: spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilder.java

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -84,13 +84,12 @@
8484
* {@link #relativeTo(org.springframework.web.util.UriComponentsBuilder)}.
8585
* </ul>
8686
*
87-
* <p><strong>Note:</strong> This class uses values from "Forwarded"
88-
* (<a href="https://tools.ietf.org/html/rfc7239">RFC 7239</a>),
89-
* "X-Forwarded-Host", "X-Forwarded-Port", and "X-Forwarded-Proto" headers,
90-
* if present, in order to reflect the client-originated protocol and address.
91-
* Consider using the {@code ForwardedHeaderFilter} in order to choose from a
92-
* central place whether to extract and use, or to discard such headers.
93-
* See the Spring Framework reference for more on this filter.
87+
* <p><strong>Note:</strong> As of 5.1, methods in this class do not extract
88+
* {@code "Forwarded"} and {@code "X-Forwarded-*"} headers that specify the
89+
* client-originated address. Please, use
90+
* {@link org.springframework.web.filter.ForwardedHeaderFilter
91+
* ForwardedHeaderFilter}, or similar from the underlying server, to extract
92+
* and use such headers, or to discard them.
9493
*
9594
* @author Oliver Gierke
9695
* @author Rossen Stoyanchev

Diff for: spring-webmvc/src/test/java/org/springframework/web/servlet/function/SseServerResponseTests.java

+21-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -173,6 +173,26 @@ void sendWithoutData() throws Exception {
173173
assertThat(this.mockResponse.getContentAsString()).isEqualTo(expected);
174174
}
175175

176+
@Test // gh-34608
177+
void sendHeartbeat() throws Exception {
178+
ServerResponse response = ServerResponse.sse(sse -> {
179+
try {
180+
sse.comment("").send();
181+
}
182+
catch (IOException ex) {
183+
throw new UncheckedIOException(ex);
184+
}
185+
});
186+
187+
ServerResponse.Context context = Collections::emptyList;
188+
189+
ModelAndView mav = response.writeTo(this.mockRequest, this.mockResponse, context);
190+
assertThat(mav).isNull();
191+
192+
String expected = ":\n\n";
193+
assertThat(this.mockResponse.getContentAsString()).isEqualTo(expected);
194+
}
195+
176196

177197
private static final class Person {
178198

0 commit comments

Comments
 (0)