dev.mccue/microhttp-setcookie
dev.mccue.microhttp.setcookie
bowbahdoe/microhttp-setcookie
dev.mccue.microhttp.setcookie
provides a utility for generating a Set-Cookie
header for use in a microhttp Response
.
Whenever a web browser receives a response from a website, depending on user settings, it will look for any SetCookie
headers in that response. Data conveyed in those headers will be sent back to the server with every subsequent request.
This is one of the easiest ways to have persistent state, like user sessions, on a website.
import org.microhttp.Header;
import dev.mccue.microhttp.setcookie.SameSite;
import dev.mccue.microhttp.setcookie.SetCookieHeader;
void main() {
= SetCookieHeader.of("name", "value");
Header header
// Header[name=Set-Cookie, value=name=value]
System.out.println(header);
= SetCookieHeader.builder("name2", "value2")
Header otherHeader .sameSite(SameSite.STRICT)
.secure(true)
.build();
// Header[name=Set-Cookie, value=name2=value2; SameSite=Strict; Secure]
System.out.println(otherHeader);
}