zigwebserver

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 3710fda82ef98929af141feaa57ccafd9d7a7d9d
parent 47214a1b045ed8aac7166828bf67dea2769148f0
Author: Martin Ashby <martin@ashbysoft.com>
Date:   Tue, 18 Jul 2023 13:48:36 +0000

added status message to error response

Diffstat:
Msrc/main.zig | 12++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git 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}); }