1
0
Fork 0
mirror of https://github.com/zigzap/zap.git synced 2025-10-20 15:14:08 +00:00

better cache-control example f. sendFile

This commit is contained in:
Rene Schallner 2023-05-14 00:21:25 +02:00
parent 9d3126649e
commit a19acaeb83
2 changed files with 4 additions and 0 deletions

View file

@ -17,6 +17,9 @@ pub fn on_request(r: zap.SimpleRequest) void {
// On error, the handle will still be valid and should be used to send an error response
//
// Important: sets last-modified and cache-control headers with a max-age value of 1 hour!
// In this example, we disable caching
r.setHeader("Cache-Control", "no-cache") catch unreachable;
if (r.sendFile("examples/sendfile/testfile.txt")) {} else |err| {
std.log.err("Unable to send file: {any}", .{err});
}

View file

@ -182,6 +182,7 @@ pub const SimpleRequest = struct {
/// On error, the handle will still be valid and should be used to send an error response
///
/// Important: sets last-modified and cache-control headers with a max-age value of 1 hour!
/// You can override that by setting those headers yourself, e.g.: setHeader("Cache-Control", "no-cache")
pub fn sendFile(self: *const Self, file_path: []const u8) !void {
if (fio.http_sendfile2(self.h, util.toCharPtr(file_path), file_path.len, null, 0) != 0)
return error.SendFile;