dev.mccue.microhttp.setcookie

What is it

dev.mccue.microhttp.setcookie provides a utility for generating a Set-Cookie header for use in a microhttp Response.

Why use it

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.

Getting Started

import org.microhttp.Header;

import dev.mccue.microhttp.setcookie.SameSite;
import dev.mccue.microhttp.setcookie.SetCookieHeader;

void main() {
    Header header = SetCookieHeader.of("name", "value");
    
    // Header[name=Set-Cookie, value=name=value]
    System.out.println(header);

    Header otherHeader = SetCookieHeader.builder("name2", "value2")
            .sameSite(SameSite.STRICT)
            .secure(true)
            .build();
    
    // Header[name=Set-Cookie, value=name2=value2; SameSite=Strict; Secure]
    System.out.println(otherHeader);
}

<- Index