-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic support for reading and clearing cookies
- Loading branch information
Thomas Goodwin
committed
Jun 24, 2024
1 parent
464a7a2
commit 6c1a06b
Showing
5 changed files
with
222 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
framework/src/main/java/nz/geek/goodwin/melinoe/framework/api/web/Cookie.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package nz.geek.goodwin.melinoe.framework.api.web; | ||
|
||
import java.util.Date; | ||
|
||
/** | ||
* @author Goodie | ||
*/ | ||
public interface Cookie { | ||
static Cookie create() { | ||
return new CookieImpl(); | ||
} | ||
|
||
String getName(); | ||
|
||
Cookie setName(String name); | ||
|
||
String getValue(); | ||
|
||
Cookie setValue(String value); | ||
|
||
String getPath(); | ||
|
||
Cookie setPath(String path); | ||
|
||
String getDomain(); | ||
|
||
Cookie setDomain(String domain); | ||
|
||
Date getExpiry(); | ||
|
||
Cookie setExpiry(Date expiry); | ||
|
||
boolean isSecure(); | ||
|
||
Cookie setSecure(boolean secure); | ||
|
||
boolean isHttpOnly(); | ||
|
||
Cookie setHttpOnly(boolean httpOnly); | ||
|
||
String getSameSite(); | ||
|
||
Cookie setSameSite(String sameSite); | ||
} |
137 changes: 137 additions & 0 deletions
137
framework/src/main/java/nz/geek/goodwin/melinoe/framework/api/web/CookieImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
package nz.geek.goodwin.melinoe.framework.api.web; | ||
|
||
import java.util.Date; | ||
import java.util.Objects; | ||
|
||
/** | ||
* @author Goodie | ||
*/ | ||
public final class CookieImpl implements Cookie { | ||
private String name; | ||
private String value; | ||
private String path; | ||
private String domain; | ||
private Date expiry; | ||
private boolean isSecure; | ||
private boolean isHttpOnly; | ||
private String sameSite; | ||
|
||
public CookieImpl() { | ||
} | ||
|
||
public CookieImpl(org.openqa.selenium.Cookie cookie) { | ||
this.name = cookie.getName(); | ||
this.value = cookie.getValue(); | ||
this.path = cookie.getPath(); | ||
this.domain = cookie.getDomain(); | ||
this.expiry = cookie.getExpiry(); | ||
this.isSecure = cookie.isSecure(); | ||
this.isHttpOnly = cookie.isHttpOnly(); | ||
this.sameSite = cookie.getSameSite(); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public Cookie setName(String name) { | ||
this.name = name; | ||
return this; | ||
} | ||
|
||
@Override | ||
public String getValue() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public Cookie setValue(String value) { | ||
this.value = value; | ||
return this; | ||
} | ||
|
||
@Override | ||
public String getPath() { | ||
return path; | ||
} | ||
|
||
@Override | ||
public Cookie setPath(String path) { | ||
this.path = path; | ||
return this; | ||
} | ||
|
||
@Override | ||
public String getDomain() { | ||
return domain; | ||
} | ||
|
||
@Override | ||
public Cookie setDomain(String domain) { | ||
this.domain = domain; | ||
return this; | ||
} | ||
|
||
@Override | ||
public Date getExpiry() { | ||
return expiry; | ||
} | ||
|
||
@Override | ||
public Cookie setExpiry(Date expiry) { | ||
this.expiry = expiry; | ||
return this; | ||
} | ||
|
||
@Override | ||
public boolean isSecure() { | ||
return isSecure; | ||
} | ||
|
||
@Override | ||
public Cookie setSecure(boolean secure) { | ||
isSecure = secure; | ||
return this; | ||
} | ||
|
||
@Override | ||
public boolean isHttpOnly() { | ||
return isHttpOnly; | ||
} | ||
|
||
@Override | ||
public Cookie setHttpOnly(boolean httpOnly) { | ||
isHttpOnly = httpOnly; | ||
return this; | ||
} | ||
|
||
@Override | ||
public String getSameSite() { | ||
return sameSite; | ||
} | ||
|
||
@Override | ||
public Cookie setSameSite(String sameSite) { | ||
this.sameSite = sameSite; | ||
return this; | ||
} | ||
@Override | ||
public boolean equals(Object other) { | ||
if (this == other) { | ||
return true; | ||
} | ||
|
||
if (other instanceof Cookie otherCookie) { | ||
return name.equals(otherCookie.getName()); | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return name.hashCode(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters