aboutsummaryrefslogtreecommitdiffstats
path: root/jdisc_http_service/src/main/java/com/yahoo/jdisc/http/Cookie.java
diff options
context:
space:
mode:
Diffstat (limited to 'jdisc_http_service/src/main/java/com/yahoo/jdisc/http/Cookie.java')
-rw-r--r--jdisc_http_service/src/main/java/com/yahoo/jdisc/http/Cookie.java139
1 files changed, 13 insertions, 126 deletions
diff --git a/jdisc_http_service/src/main/java/com/yahoo/jdisc/http/Cookie.java b/jdisc_http_service/src/main/java/com/yahoo/jdisc/http/Cookie.java
index a43310aff51..06c93db7ede 100644
--- a/jdisc_http_service/src/main/java/com/yahoo/jdisc/http/Cookie.java
+++ b/jdisc_http_service/src/main/java/com/yahoo/jdisc/http/Cookie.java
@@ -7,15 +7,11 @@ import org.eclipse.jetty.server.Response;
import java.net.HttpCookie;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
-import java.util.StringTokenizer;
import java.util.concurrent.TimeUnit;
-import java.util.logging.Level;
-import java.util.logging.Logger;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
@@ -24,22 +20,17 @@ import java.util.stream.StreamSupport;
*
* Note: RFC 2109 and RFC 2965 is no longer supported. All fields that are not part of RFC 6265 are deprecated.
*
- * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a>
+ * @author Einar M R Rosenvinge
* @author bjorncs
*/
public class Cookie {
- private final static Logger log = Logger.getLogger(Cookie.class.getName());
-
private final Set<Integer> ports = new HashSet<>();
private String name;
private String value;
private String domain;
private String path;
- private String comment;
- private String commentUrl;
private long maxAgeSeconds = Integer.MIN_VALUE;
- private int version;
private boolean secure;
private boolean httpOnly;
private boolean discard;
@@ -53,10 +44,7 @@ public class Cookie {
value = cookie.value;
domain = cookie.domain;
path = cookie.path;
- comment = cookie.comment;
- commentUrl = cookie.commentUrl;
maxAgeSeconds = cookie.maxAgeSeconds;
- version = cookie.version;
secure = cookie.secure;
httpOnly = cookie.httpOnly;
discard = cookie.discard;
@@ -103,38 +91,6 @@ public class Cookie {
return this;
}
- @Deprecated
- public String getComment() {
- return comment;
- }
-
- @Deprecated
- public Cookie setComment(String comment) {
- this.comment = comment;
- return this;
- }
-
- @Deprecated
- public String getCommentURL() {
- return getCommentUrl();
- }
-
- @Deprecated
- public Cookie setCommentURL(String commentUrl) {
- return setCommentUrl(commentUrl);
- }
-
- @Deprecated
- public String getCommentUrl() {
- return commentUrl;
- }
-
- @Deprecated
- public Cookie setCommentUrl(String commentUrl) {
- this.commentUrl = commentUrl;
- return this;
- }
-
public int getMaxAge(TimeUnit unit) {
return (int)unit.convert(maxAgeSeconds, TimeUnit.SECONDS);
}
@@ -144,17 +100,6 @@ public class Cookie {
return this;
}
- @Deprecated
- public int getVersion() {
- return version;
- }
-
- @Deprecated
- public Cookie setVersion(int version) {
- this.version = version;
- return this;
- }
-
public boolean isSecure() {
return secure;
}
@@ -173,29 +118,12 @@ public class Cookie {
return this;
}
- @Deprecated
- public boolean isDiscard() {
- return discard;
- }
-
- @Deprecated
- public Cookie setDiscard(boolean discard) {
- this.discard = discard;
- return this;
- }
-
- @Deprecated
- public Set<Integer> ports() {
- return ports;
- }
-
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Cookie cookie = (Cookie) o;
return maxAgeSeconds == cookie.maxAgeSeconds &&
- version == cookie.version &&
secure == cookie.secure &&
httpOnly == cookie.httpOnly &&
discard == cookie.discard &&
@@ -203,14 +131,12 @@ public class Cookie {
Objects.equals(name, cookie.name) &&
Objects.equals(value, cookie.value) &&
Objects.equals(domain, cookie.domain) &&
- Objects.equals(path, cookie.path) &&
- Objects.equals(comment, cookie.comment) &&
- Objects.equals(commentUrl, cookie.commentUrl);
+ Objects.equals(path, cookie.path);
}
@Override
public int hashCode() {
- return Objects.hash(ports, name, value, domain, path, comment, commentUrl, maxAgeSeconds, version, secure, httpOnly, discard);
+ return Objects.hash(ports, name, value, domain, path, maxAgeSeconds, secure, httpOnly, discard);
}
@Override
@@ -229,19 +155,12 @@ public class Cookie {
return StreamSupport.stream(cookies.spliterator(), false)
.map(cookie -> {
HttpCookie httpCookie = new HttpCookie(cookie.getName(), cookie.getValue());
- httpCookie.setComment(cookie.getComment());
- httpCookie.setCommentURL(cookie.getCommentURL());
- httpCookie.setDiscard(cookie.isDiscard());
httpCookie.setDomain(cookie.getDomain());
httpCookie.setHttpOnly(cookie.isHttpOnly());
httpCookie.setMaxAge(cookie.getMaxAge(TimeUnit.SECONDS));
httpCookie.setPath(cookie.getPath());
httpCookie.setSecure(cookie.isSecure());
- httpCookie.setVersion(cookie.getVersion());
- String portList = cookie.ports().stream()
- .map(Number::toString)
- .collect(Collectors.joining(","));
- httpCookie.setPortlist(portList);
+ httpCookie.setVersion(0);
return httpCookie.toString();
})
.collect(Collectors.joining(";"));
@@ -255,29 +174,17 @@ public class Cookie {
Cookie cookie = new Cookie();
cookie.setName(servletCookie.getName());
cookie.setValue(servletCookie.getValue());
- cookie.setComment(servletCookie.getComment());
cookie.setPath(servletCookie.getPath());
cookie.setDomain(servletCookie.getDomain());
cookie.setMaxAge(servletCookie.getMaxAge(), TimeUnit.SECONDS);
cookie.setSecure(servletCookie.getSecure());
- cookie.setVersion(servletCookie.getVersion());
cookie.setHttpOnly(servletCookie.isHttpOnly());
return cookie;
})
.collect(Collectors.toList());
}
- /**
- * @deprecated Use {@link #toSetCookieHeaderAll(Iterable)} instead.
- */
- @Deprecated
- public static String toSetCookieHeader(Iterable<? extends Cookie> cookies) {
- List<String> encodedCookies = toSetCookieHeaderAll(cookies);
- return encodedCookies.isEmpty() ? null : encodedCookies.get(0);
- }
-
- // TODO Rename to toSetCookieHeader for Vespa 7
- public static List<String> toSetCookieHeaderAll(Iterable<? extends Cookie> cookies) {
+ public static List<String> toSetCookieHeaders(Iterable<? extends Cookie> cookies) {
// Ugly, bot Jetty does not provide a dedicated cookie parser (will be included in Jetty 10)
Response response = new Response(null, null);
for (Cookie cookie : cookies) {
@@ -293,45 +200,25 @@ public class Cookie {
return new ArrayList<>(response.getHeaders("Set-Cookie"));
}
- // TODO Change return type to Cookie for Vespa 7
- public static List<Cookie> fromSetCookieHeader(String headerVal) {
+ @Deprecated // TODO Vespa 8 Remove
+ public static List<String> toSetCookieHeaderAll(Iterable<? extends Cookie> cookies) {
+ return toSetCookieHeaders(cookies);
+ }
+
+ public static Cookie fromSetCookieHeader(String headerVal) {
return HttpCookie.parse(headerVal).stream()
.map(httpCookie -> {
Cookie cookie = new Cookie();
cookie.setName(httpCookie.getName());
cookie.setValue(httpCookie.getValue());
- cookie.setComment(httpCookie.getComment());
- cookie.setCommentUrl(httpCookie.getCommentURL());
- cookie.setDiscard(httpCookie.getDiscard());
cookie.setDomain(httpCookie.getDomain());
cookie.setHttpOnly(httpCookie.isHttpOnly());
- cookie.setMaxAge((int)httpCookie.getMaxAge(), TimeUnit.SECONDS);
+ cookie.setMaxAge((int) httpCookie.getMaxAge(), TimeUnit.SECONDS);
cookie.setPath(httpCookie.getPath());
cookie.setSecure(httpCookie.getSecure());
- cookie.setVersion(httpCookie.getVersion());
- cookie.ports().addAll(parsePortList(httpCookie.getPortlist()));
return cookie;
})
- .collect(Collectors.toList());
- }
-
-
- private static List<Integer> parsePortList(String rawPortList) {
- if (rawPortList == null) return Collections.emptyList();
-
- List<Integer> ports = new ArrayList<>();
- StringTokenizer tokenizer = new StringTokenizer(rawPortList, ",");
- while (tokenizer.hasMoreTokens()) {
- String rawPort = tokenizer.nextToken().trim();
- if (!rawPort.isEmpty()) {
- try {
- ports.add(Integer.parseInt(rawPort));
- } catch (NumberFormatException e) {
- log.log(Level.FINE, "Unable to parse port: " + rawPort, e);
- }
- }
- }
- return ports;
+ .findFirst().get();
}
}