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:
parent
9d3126649e
commit
a19acaeb83
2 changed files with 4 additions and 0 deletions
|
@ -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});
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue