MockServerHttpRequest and Response set cookie headers
Issue: SPR-15522
This commit is contained in:
@@ -71,4 +71,9 @@ public class HttpCookie {
|
||||
return (this.name.equalsIgnoreCase(otherCookie.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.name + '=' + this.value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.time.Duration;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* An {@code HttpCookie} subclass with the additional attributes allowed in
|
||||
@@ -125,6 +126,34 @@ public final class ResponseCookie extends HttpCookie {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(getName()).append('=').append(getValue());
|
||||
if (StringUtils.hasText(getPath())) {
|
||||
sb.append("; Path=").append(getPath());
|
||||
}
|
||||
if (StringUtils.hasText(this.domain)) {
|
||||
sb.append("; Domain=").append(this.domain);
|
||||
}
|
||||
if (!this.maxAge.isNegative()) {
|
||||
sb.append("; Max-Age=").append(this.maxAge);
|
||||
sb.append("; Expires=");
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
long seconds = this.maxAge.getSeconds();
|
||||
headers.setExpires(seconds > 0 ? System.currentTimeMillis() + seconds : 0);
|
||||
sb.append(headers.getFirst(HttpHeaders.EXPIRES));
|
||||
}
|
||||
|
||||
if (this.secure) {
|
||||
sb.append("; Secure");
|
||||
}
|
||||
if (this.httpOnly) {
|
||||
sb.append("; HttpOnly");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Factory method to obtain a builder for a server-defined cookie that starts
|
||||
|
||||
Reference in New Issue
Block a user