srctree

Jeremy Hertel parent 03d5bb1d 96f00dd9
set content type to json when using sendJSON

src/content-type.zig added: 12, removed: 3, total 9
@@ -50,6 +50,7 @@ pub const Application = enum {
@"x-www-form-urlencoded",
@"x-git-upload-pack-request",
@"octet-stream",
json,
 
pub fn string(comptime app: Application) [:0]const u8 {
return switch (app) {
 
src/request_data.zig added: 12, removed: 3, total 9
@@ -303,6 +303,9 @@ fn parseApplication(a: Allocator, ap: ContentType.Application, data: []u8, htype
.@"octet-stream" => {
unreachable; // Not implemented
},
.json => {
unreachable; // TODO: implement parsing json
},
}
}
 
 
src/verse.zig added: 12, removed: 3, total 9
@@ -308,6 +308,11 @@ pub fn sendJSON(vrs: *Verse, json: anytype, comptime code: std.http.Status) !voi
}
 
vrs.status = code;
vrs.content_type = .{
.base = .{ .application = .json },
.parameter = .@"utf-8",
};
 
try vrs.quickStart();
const data = std.json.stringifyAlloc(vrs.alloc, json, .{
.emit_null_optional_fields = false,