Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public static String getHTTPTime(int days) {
}

private final String n, v, e;
private final boolean secure, httpOnly;

public Cookie(String name, String value) {
this(name, value, 30);
Expand All @@ -70,9 +71,21 @@ public Cookie(String name, String value, String expires) {
this.v = value;
this.e = expires;
}

public Cookie(String name, String value, int numDays, boolean secure, boolean httpOnly) {
this(name, value, getHTTPTime(numDays), secure, httpOnly);
}
public Cookie(String name, String value, String expires, boolean secure, boolean httpOnly) {
this(name, value, expires);
this.secure = secure;
this.httpOnly = httpOnly;

}
public String getHTTPHeader() {
String fmt = "%s=%s; expires=%s";
return String.format(fmt, this.n, this.v, this.e);
String header = String.format("%s=%s; expires=%s", this.n, this.v, this.e);
if(secure)
header += "; secure";
if(httpOnly)
header += "; HttpOnly";
return header;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,27 @@ public void set(Cookie cookie) {
* The cookie's value.
* @param expires
* How many days until the cookie expires.
* @param secure
* Cookies with the 'secure' attribute will only be sent over encrypted connections
* @param httpOnly
* Cookies withthe 'httponly' attribute will not be accessible to JavaScript's cookies API
*/
public void set(String name, String value, int expires) {
this.queue.add(new Cookie(name, value, Cookie.getHTTPTime(expires)));
public void set(String name, String value, int expires, boolean secure, boolean httpOnly) {
this.queue.add(new Cookie(name, value, Cookie.getHTTPTime(expires)), secure, httpOnly);
}

/**
* Sets a cookie.
*
* @param name
* The cookie's name.
* @param value
* The cookie's value.
* @param expires
* How many days until the cookie expires.
*/
public void set(String name, String value, int expires) {
this.queue.add(new Cookie(name, value, Cookie.getHTTPTime(expires)), false, false);
}

/**
Expand Down