dev.mccue/microhttp-cookies
dev.mccue.microhttp.cookies
bowbahdoe/microhttp-cookies
dev.mccue.microhttp.cookies
provides a utility parsing cookie headers sent in requests, specifically microhttp's Request
objects.
If you've asked a user to send you a cookie on subsequent requests, such as with dev.mccue.microhttp.setcookie
, you will most likely want to interpret the data in that cookie when you get it.
This library provides the ability to do that.
import dev.mccue.microhttp.cookies.Cookies;
import dev.mccue.microhttp.setcookie.SetCookieHeader;
import org.microhttp.EventLoop;
import org.microhttp.Options;
import org.microhttp.Response;
import java.util.List;
void main() throws Exception {
= new EventLoop((request, consumer) -> {
var eventLoop = Cookies.parse(request);
var cookies = cookies.get("Counter")
var counter .orElse("0");
= SetCookieHeader.of(
var setCookieHeader "Counter",
Integer.toString(Integer.parseInt(counter) + 1)
);
.accept(
consumernew Response(
200,
"OK",
List.of(setCookieHeader),
.getBytes()
counter)
);
});
.start();
eventLoop.join();
eventLoop}