-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
320 additions
and
13 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
51 changes: 51 additions & 0 deletions
51
scx-http-helidon/src/main/java/cool/scx/http/helidon/HelidonCookies.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,51 @@ | ||
package cool.scx.http.helidon; | ||
|
||
import cool.scx.http.cookie.Cookie; | ||
import cool.scx.http.cookie.Cookies; | ||
import io.helidon.common.parameters.Parameters; | ||
|
||
import java.util.Iterator; | ||
|
||
public class HelidonCookies implements Cookies { | ||
|
||
private final Parameters cookies; | ||
|
||
public HelidonCookies(Parameters cookies) { | ||
this.cookies = cookies; | ||
} | ||
|
||
@Override | ||
public long size() { | ||
return cookies.size(); | ||
} | ||
|
||
@Override | ||
public Cookie get(String name) { | ||
var value = cookies.get(name); | ||
if (value == null) { | ||
return null; | ||
} else { | ||
return Cookie.of(name, value); | ||
} | ||
} | ||
|
||
@Override | ||
public Iterator<Cookie> iterator() { | ||
var itr = cookies.toMap().entrySet().iterator(); | ||
return new Iterator<Cookie>() { | ||
@Override | ||
public boolean hasNext() { | ||
return itr.hasNext(); | ||
} | ||
|
||
@Override | ||
public Cookie next() { | ||
var next = itr.next(); | ||
var key = next.getKey(); | ||
var value = next.getValue(); | ||
return Cookie.of(key, value.size() > 0 ? value.get(0) : null); | ||
} | ||
}; | ||
} | ||
|
||
} |
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
4 changes: 3 additions & 1 deletion
4
scx-http/src/main/java/cool/scx/http/ScxHttpClientOptions.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 |
---|---|---|
@@ -1,6 +1,8 @@ | ||
package cool.scx.http; | ||
|
||
//todo | ||
/** | ||
* ScxHttpClientOptions | ||
*/ | ||
public class ScxHttpClientOptions { | ||
|
||
} |
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
5 changes: 4 additions & 1 deletion
5
.../main/java/cool/scx/http/ContentType.java → ...ol/scx/http/content_type/ContentType.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
5 changes: 4 additions & 1 deletion
5
...n/java/cool/scx/http/ContentTypeImpl.java → ...cx/http/content_type/ContentTypeImpl.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
5 changes: 4 additions & 1 deletion
5
...va/cool/scx/http/ContentTypeWritable.java → ...ttp/content_type/ContentTypeWritable.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
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,25 @@ | ||
package cool.scx.http.cookie; | ||
|
||
public interface Cookie { | ||
|
||
static CookieWritable of(String name, String value) { | ||
return new CookieImpl(name, value); | ||
} | ||
|
||
String name(); | ||
|
||
String value(); | ||
|
||
String domain(); | ||
|
||
String path(); | ||
|
||
long maxAge(); | ||
|
||
boolean secure(); | ||
|
||
boolean httpOnly(); | ||
|
||
CookieSameSite sameSite(); | ||
|
||
} |
126 changes: 126 additions & 0 deletions
126
scx-http/src/main/java/cool/scx/http/cookie/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,126 @@ | ||
package cool.scx.http.cookie; | ||
|
||
class CookieImpl implements CookieWritable { | ||
|
||
private String name; | ||
private String value; | ||
private String domain; | ||
private String path; | ||
private long maxAge; | ||
private boolean secure; | ||
private boolean httpOnly; | ||
private CookieSameSite sameSite; | ||
|
||
public CookieImpl(String name, String value) { | ||
this.name = name; | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public CookieWritable domain(String domain) { | ||
this.domain = domain; | ||
return this; | ||
} | ||
|
||
@Override | ||
public CookieWritable path(String path) { | ||
this.path = path; | ||
return this; | ||
} | ||
|
||
@Override | ||
public CookieWritable maxAge(long maxAge) { | ||
this.maxAge = maxAge; | ||
return this; | ||
} | ||
|
||
@Override | ||
public CookieWritable secure(boolean secure) { | ||
this.secure = secure; | ||
return this; | ||
} | ||
|
||
@Override | ||
public CookieWritable httpOnly(boolean httpOnly) { | ||
this.httpOnly = httpOnly; | ||
return this; | ||
} | ||
|
||
@Override | ||
public CookieWritable sameSite(CookieSameSite sameSite) { | ||
this.sameSite = sameSite; | ||
return this; | ||
} | ||
|
||
@Override | ||
public String name() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public String value() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public String domain() { | ||
return domain; | ||
} | ||
|
||
@Override | ||
public String path() { | ||
return path; | ||
} | ||
|
||
@Override | ||
public long maxAge() { | ||
return maxAge; | ||
} | ||
|
||
@Override | ||
public boolean secure() { | ||
return secure; | ||
} | ||
|
||
@Override | ||
public boolean httpOnly() { | ||
return httpOnly; | ||
} | ||
|
||
@Override | ||
public CookieSameSite sameSite() { | ||
return sameSite; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
var buf = new StringBuilder() | ||
.append(name) | ||
.append('=') | ||
.append(value); | ||
if (domain != null) { | ||
buf.append(", domain=") | ||
.append(domain); | ||
} | ||
if (path != null) { | ||
buf.append(", path=") | ||
.append(path); | ||
} | ||
if (maxAge >= 0) { | ||
buf.append(", maxAge=") | ||
.append(maxAge) | ||
.append('s'); | ||
} | ||
if (secure) { | ||
buf.append(", secure"); | ||
} | ||
if (httpOnly) { | ||
buf.append(", HTTPOnly"); | ||
} | ||
if (sameSite != null) { | ||
buf.append(", SameSite=").append(sameSite.value()); | ||
} | ||
return buf.toString(); | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
scx-http/src/main/java/cool/scx/http/cookie/CookieSameSite.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,21 @@ | ||
package cool.scx.http.cookie; | ||
|
||
public enum CookieSameSite { | ||
|
||
NONE("None"), | ||
|
||
STRICT("Strict"), | ||
|
||
LAX("Lax"); | ||
|
||
private final String value; | ||
|
||
CookieSameSite(String label) { | ||
this.value = label; | ||
} | ||
|
||
public String value() { | ||
return value; | ||
} | ||
|
||
} |
Oops, something went wrong.