|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2018 the original author or authors. |
| 2 | + * Copyright 2002-2019 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
41 | 41 | import java.util.Map;
|
42 | 42 | import java.util.Set;
|
43 | 43 | import java.util.TimeZone;
|
| 44 | +import java.util.stream.Collectors; |
44 | 45 | import javax.servlet.AsyncContext;
|
45 | 46 | import javax.servlet.DispatcherType;
|
46 | 47 | import javax.servlet.RequestDispatcher;
|
|
58 | 59 |
|
59 | 60 | import org.springframework.http.HttpHeaders;
|
60 | 61 | import org.springframework.http.MediaType;
|
| 62 | +import org.springframework.lang.NonNull; |
61 | 63 | import org.springframework.lang.Nullable;
|
62 | 64 | import org.springframework.util.Assert;
|
63 | 65 | import org.springframework.util.LinkedCaseInsensitiveMap;
|
@@ -951,14 +953,20 @@ public String getAuthType() {
|
951 | 953 |
|
952 | 954 | public void setCookies(@Nullable Cookie... cookies) {
|
953 | 955 | this.cookies = (ObjectUtils.isEmpty(cookies) ? null : cookies);
|
954 |
| - this.headers.remove(HttpHeaders.COOKIE); |
955 |
| - if (this.cookies != null) { |
956 |
| - Arrays.stream(this.cookies) |
957 |
| - .map(c -> c.getName() + '=' + (c.getValue() == null ? "" : c.getValue())) |
958 |
| - .forEach(value -> doAddHeaderValue(HttpHeaders.COOKIE, value, false)); |
| 956 | + if (this.cookies == null) { |
| 957 | + removeHeader(HttpHeaders.COOKIE); |
| 958 | + } |
| 959 | + else { |
| 960 | + doAddHeaderValue(HttpHeaders.COOKIE, encodeCookies(this.cookies), true); |
959 | 961 | }
|
960 | 962 | }
|
961 | 963 |
|
| 964 | + private static String encodeCookies(@NonNull Cookie... cookies) { |
| 965 | + return Arrays.stream(cookies) |
| 966 | + .map(c -> c.getName() + '=' + (c.getValue() == null ? "" : c.getValue())) |
| 967 | + .collect(Collectors.joining("; ")); |
| 968 | + } |
| 969 | + |
962 | 970 | @Override
|
963 | 971 | @Nullable
|
964 | 972 | public Cookie[] getCookies() {
|
@@ -1272,6 +1280,7 @@ public HttpSession getSession() {
|
1272 | 1280 | * Otherwise it simply returns the current session id.
|
1273 | 1281 | * @since 4.0.3
|
1274 | 1282 | */
|
| 1283 | + @Override |
1275 | 1284 | public String changeSessionId() {
|
1276 | 1285 | Assert.isTrue(this.session != null, "The request does not have a session");
|
1277 | 1286 | if (this.session instanceof MockHttpSession) {
|
|
0 commit comments