aboutsummaryrefslogtreecommitdiff
path: root/src/http/Response.zig
blob: a5f772751e9e93ea0ec53055d19ce45ba804bba2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const std = @import("std");

pub const Message = union(enum) {
    void: void,
    static: []const u8,
    file_content: std.Io.File,

    pub fn string(content: []const u8) Message {
        return .{ .static = content };
    }

    pub fn file(io: std.Io, path: []const u8) !Message {
        return .{ .file_content = try std.Io.Dir.cwd().openFile(io, path, .{
            .allow_directory = false,
        }) };
    }
};

status: std.http.Status,
message: Message,

pub fn with(status: std.http.Status, message: Message) @This() {
    return .{ .status = status, .message = message };
}

pub fn ok(message: Message) @This() {
    return with(.ok, message);
}