Skip to content

Commit

Permalink
performance: revert r.method enum back to ?[]const u8
Browse files Browse the repository at this point in the history
new http.Method enum is available via r.methodAsEnum()
  • Loading branch information
renerocksai committed Feb 24, 2024
1 parent db579a9 commit 8a18a02
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
5 changes: 3 additions & 2 deletions examples/hello2/hello2.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const std = @import("std");
const zap = @import("zap");

fn on_request(r: zap.Request) void {
const m = r.method_str orelse "";
const m = r.methodAsEnum();
const m_str = r.method orelse "";
const p = r.path orelse "/";
const qm = if (r.query) |_| "?" else "";
const qq = r.query orelse "";
Expand All @@ -13,7 +14,7 @@ fn on_request(r: zap.Request) void {
} else {
std.debug.print(">> Special Header: <unknown>\n", .{});
}
std.debug.print(">> {s} {s}{s}{s}\n", .{ m, p, qm, qq });
std.debug.print(">> {s}({}) {s}{s}{s}\n", .{ m_str, m, p, qm, qq });

if (r.body) |the_body| {
std.debug.print(">> BODY: {s}\n", .{the_body});
Expand Down
7 changes: 5 additions & 2 deletions src/request.zig
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,7 @@ pub const CookieArgs = struct {
path: ?[]const u8,
query: ?[]const u8,
body: ?[]const u8,
method: http.Method,
method_str: ?[]const u8,
method: ?[]const u8,
h: [*c]fio.http_s,

/// NEVER touch this field!!!!
Expand Down Expand Up @@ -792,3 +791,7 @@ pub fn getParamSlices(self: *const Self) ParamSliceIterator {
const query = self.query orelse "";
return ParamSliceIterator.init(query);
}

pub fn methodAsEnum(self: *const Self) http.Method {
return http.methodToEnum(self.method);
}
9 changes: 3 additions & 6 deletions src/zap.zig
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,7 @@ pub const HttpListener = struct {
.path = util.fio2str(r.*.path),
.query = util.fio2str(r.*.query),
.body = util.fio2str(r.*.body),
.method = http.methodToEnum(util.fio2str(r.*.method)),
.method_str = util.fio2str(r.*.method),
.method = util.fio2str(r.*.method),
.h = r,
._is_finished_request_global = false,
._user_context = undefined,
Expand All @@ -234,8 +233,7 @@ pub const HttpListener = struct {
.path = util.fio2str(r.*.path),
.query = util.fio2str(r.*.query),
.body = util.fio2str(r.*.body),
.method = http.methodToEnum(util.fio2str(r.*.method)),
.method_str = util.fio2str(r.*.method),
.method = util.fio2str(r.*.method),
.h = r,
._is_finished_request_global = false,
._user_context = undefined,
Expand All @@ -256,8 +254,7 @@ pub const HttpListener = struct {
.path = util.fio2str(r.*.path),
.query = util.fio2str(r.*.query),
.body = util.fio2str(r.*.body),
.method = http.methodToEnum(util.fio2str(r.*.method)),
.method_str = util.fio2str(r.*.method),
.method = util.fio2str(r.*.method),
.h = r,
._is_finished_request_global = false,
._user_context = undefined,
Expand Down

0 comments on commit 8a18a02

Please sign in to comment.