mirror of
https://github.com/zigzap/zap.git
synced 2025-10-21 15:44:10 +00:00
potential throwaway-pre-travel commit
This commit is contained in:
parent
503554d649
commit
d4175c08c5
1 changed files with 12 additions and 9 deletions
13
src/zap.zig
13
src/zap.zig
|
@ -72,22 +72,23 @@ pub const SimpleRequest = struct {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sendJson(self: *const Self, json: []const u8) c_int {
|
pub fn sendJson(self: *const Self, json: []const u8) !c_int {
|
||||||
self.setContentType(.JSON);
|
if (self.setContentType(.JSON)) {
|
||||||
return fio.http_send_body(self.h, @intToPtr(
|
return fio.http_send_body(self.h, @intToPtr(
|
||||||
*anyopaque,
|
*anyopaque,
|
||||||
@ptrToInt(json.ptr),
|
@ptrToInt(json.ptr),
|
||||||
), json.len);
|
), json.len);
|
||||||
|
} else return error{ERR_CONTENT_TYPE};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn setContentType(self: *const Self, c: ContentType) void {
|
pub fn setContentType(self: *const Self, c: ContentType) bool {
|
||||||
const s = switch (c) {
|
const s = switch (c) {
|
||||||
.TEXT => "text/plain",
|
.TEXT => "text/plain",
|
||||||
.JSON => "application/json",
|
.JSON => "application/json",
|
||||||
else => "text/html",
|
else => "text/html",
|
||||||
};
|
};
|
||||||
debug("setting content-type to {s}\n", .{s});
|
debug("setting content-type to {s}\n", .{s});
|
||||||
self.setHeader("content-type", s);
|
return self.setHeader("content-type", s);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// shows how to use the logger
|
/// shows how to use the logger
|
||||||
|
@ -113,7 +114,7 @@ pub const SimpleRequest = struct {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn setHeader(self: *const Self, name: []const u8, value: []const u8) void {
|
pub fn setHeader(self: *const Self, name: []const u8, value: []const u8) bool {
|
||||||
const hname: fio.fio_str_info_s = .{
|
const hname: fio.fio_str_info_s = .{
|
||||||
.data = util.toCharPtr(name),
|
.data = util.toCharPtr(name),
|
||||||
.len = name.len,
|
.len = name.len,
|
||||||
|
@ -133,6 +134,8 @@ pub const SimpleRequest = struct {
|
||||||
// Note to self:
|
// Note to self:
|
||||||
// const new_fiobj_str = fio.fiobj_str_new(name.ptr, name.len);
|
// const new_fiobj_str = fio.fiobj_str_new(name.ptr, name.len);
|
||||||
// fio.fiobj_free(new_fiobj_str);
|
// fio.fiobj_free(new_fiobj_str);
|
||||||
|
|
||||||
|
return ret == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn setStatusNumeric(self: *const Self, status: usize) void {
|
pub fn setStatusNumeric(self: *const Self, status: usize) void {
|
||||||
|
|
Loading…
Add table
Reference in a new issue