diff options
author | Martin Ashby <martin@ashbysoft.com> | 2023-07-18 13:48:36 +0000 |
---|---|---|
committer | Martin Ashby <martin@ashbysoft.com> | 2023-07-18 13:48:36 +0000 |
commit | 3710fda82ef98929af141feaa57ccafd9d7a7d9d (patch) | |
tree | b7591f9b8291b00835464d9e9ee938f7624b7043 /src | |
parent | 47214a1b045ed8aac7166828bf67dea2769148f0 (diff) | |
download | zigwebserver-3710fda82ef98929af141feaa57ccafd9d7a7d9d.tar.gz zigwebserver-3710fda82ef98929af141feaa57ccafd9d7a7d9d.tar.bz2 zigwebserver-3710fda82ef98929af141feaa57ccafd9d7a7d9d.tar.xz zigwebserver-3710fda82ef98929af141feaa57ccafd9d7a7d9d.zip |
added status message to error response
Diffstat (limited to 'src')
-rw-r--r-- | src/main.zig | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/main.zig b/src/main.zig index 335e80c..3739218 100644 --- a/src/main.zig +++ b/src/main.zig @@ -54,10 +54,10 @@ fn serve_file(res: *std.http.Server.Response, file: std.fs.File, md: std.fs.File fn serve_error(res: *std.http.Server.Response, status: std.http.Status) !void { res.status = status; - const msg = - \\ <!doctype html><html><body>error!</body></html> - ; - res.transfer_encoding = . { .content_length = msg.len }; - try res.do(); - _ = try res.write(msg); + res.transfer_encoding = .chunked; + try res.do(); + const phrase = status.phrase() orelse "error!"; + try std.fmt.format(res.writer(), + \\ <!doctype html><html><body>{s}</body></html> + , .{phrase}); } |