Skip to content

Commit 78549d4

Browse files
Matteo Cristofororstoyanchev
Matteo Cristoforo
authored andcommitted
Fix cookie management in reactive JdkClientHttpRequest
Prevent cookies to be set to empty in the HTTP request if no cookie is present See gh-32799
1 parent e4e6910 commit 78549d4

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Diff for: spring-web/src/main/java/org/springframework/http/client/reactive/JdkClientHttpRequest.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.springframework.http.HttpHeaders;
3838
import org.springframework.http.HttpMethod;
3939
import org.springframework.util.Assert;
40+
import org.springframework.util.MultiValueMap;
4041

4142
/**
4243
* {@link ClientHttpRequest} for the Java {@link HttpClient}.
@@ -108,8 +109,11 @@ protected void applyHeaders() {
108109

109110
@Override
110111
protected void applyCookies() {
111-
this.builder.header(HttpHeaders.COOKIE, getCookies().values().stream()
112-
.flatMap(List::stream).map(HttpCookie::toString).collect(Collectors.joining(";")));
112+
MultiValueMap<String, HttpCookie> cookies = getCookies();
113+
if (!cookies.isEmpty()) {
114+
this.builder.header(HttpHeaders.COOKIE, cookies.values().stream()
115+
.flatMap(List::stream).map(HttpCookie::toString).collect(Collectors.joining(";")));
116+
}
113117
}
114118

115119
@Override

0 commit comments

Comments
 (0)