You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`HeaderOpts` currently supports `dupe_name: bool` and `dupe_value: bool`, both default to `false`.
578
578
579
+
## Cookies
580
+
You can use the `res.setCookie(name, value, opts)` to set the "Set-Cookie" header.
581
+
582
+
```zig
583
+
try res.setCookie("cookie_name3", "cookie value 3", .{
584
+
.path = "/auth/",
585
+
.domain = "www.openmymind.net",
586
+
.max_age = 9001,
587
+
.secure = true,
588
+
.http_only = true,
589
+
.partitioned = true,
590
+
.same_site = .lax, // or .none, or .strict (or null to leave out)
591
+
});
592
+
```
593
+
594
+
`setCookie` does not validate the name, value, path or domain - it assumes you're setting proper values. It *will* double-quote values which contain spaces or commas (as required).
595
+
596
+
If, for whatever reason, `res.setCookie` doesn't work for you, you always have full control over the cookie value via `res.header("Set-Cookie", value)`.
597
+
598
+
```zig
599
+
var cookies = req.cookies();
600
+
if (cookies.get("auth")) |auth| {
601
+
/// ...
602
+
}
603
+
```
604
+
579
605
## Writing
580
606
By default, httpz will automatically flush your response. In more advance cases, you can use `res.write()` to explicitly flush it. This is useful in cases where you have resources that need to be freed/released only after the response is written. For example, my [LRU cache](https://github.com/karlseguin/cache.zig) uses atomic referencing counting to safely allow concurrent access to cached data. This requires callers to "release" the cached entry:
0 commit comments