diff options
author | 2022-03-01 22:19:15 -0800 | |
---|---|---|
committer | 2022-03-01 22:19:15 -0800 | |
commit | 78cae049d2c8f7fa4f7cde8ed5b8895b3e32b5fc (patch) | |
tree | 0998a2e0787b4e5dac8c0ecb0a333d91232863d5 /src | |
parent | 7b4f239d33f2c9641350ce32cede2141e3075c72 (diff) | |
download | bun-78cae049d2c8f7fa4f7cde8ed5b8895b3e32b5fc.tar.gz bun-78cae049d2c8f7fa4f7cde8ed5b8895b3e32b5fc.tar.zst bun-78cae049d2c8f7fa4f7cde8ed5b8895b3e32b5fc.zip |
cleanup code that checks if it should send an HTTP body
Diffstat (limited to 'src')
-rw-r--r-- | src/http.zig | 12 | ||||
-rw-r--r-- | src/http/method.zig | 12 |
2 files changed, 18 insertions, 6 deletions
diff --git a/src/http.zig b/src/http.zig index 634d9f1f4..fa0e806ea 100644 --- a/src/http.zig +++ b/src/http.zig @@ -2092,7 +2092,7 @@ pub const RequestContext = struct { ctx.appendHeader("Content-Type", "text/plain"); } - const send_body = ctx.method == .GET; + const send_body = ctx.method.hasBody(); switch (result.file.value) { .pending => |resolve_result| { @@ -2570,7 +2570,7 @@ pub const RequestContext = struct { if (buffer.len == 0) { return try ctx.sendNoContent(); } - const send_body = ctx.method == .GET; + const send_body = ctx.method.hasBody(); defer ctx.done(); try ctx.writeStatus(200); try ctx.prepareToSendBody(buffer.len, false); @@ -2593,7 +2593,7 @@ pub const RequestContext = struct { if (buffer.len == 0) { return try ctx.sendNoContent(); } - const send_body = ctx.method == .GET; + const send_body = ctx.method.hasBody(); defer ctx.done(); try ctx.writeStatus(200); try ctx.prepareToSendBody(buffer.len, false); @@ -2630,7 +2630,7 @@ pub const RequestContext = struct { if (buffer.len == 0) { return try ctx.sendNoContent(); } - const send_body = ctx.method == .GET; + const send_body = ctx.method.hasBody(); defer ctx.done(); try ctx.writeStatus(200); try ctx.prepareToSendBody(buffer.len, false); @@ -2656,7 +2656,7 @@ pub const RequestContext = struct { if (buffer.len == 0) { return try ctx.sendNoContent(); } - const send_body = ctx.method == .GET; + const send_body = ctx.method.hasBody(); defer ctx.done(); try ctx.writeStatus(200); try ctx.prepareToSendBody(buffer.len, false); @@ -2708,7 +2708,7 @@ pub const RequestContext = struct { if (buffer.len == 0) { return try ctx.sendNoContent(); } - const send_body = ctx.method == .GET; + const send_body = ctx.method.hasBody(); defer ctx.done(); try ctx.writeStatus(200); try ctx.prepareToSendBody(buffer.len, false); diff --git a/src/http/method.zig b/src/http/method.zig index 8c3e30c7f..91074d1b3 100644 --- a/src/http/method.zig +++ b/src/http/method.zig @@ -8,6 +8,7 @@ const MutableString = _global.MutableString; const stringZ = _global.stringZ; const default_allocator = _global.default_allocator; const C = _global.C; +const std = @import("std"); pub const Method = enum { GET, @@ -19,6 +20,17 @@ pub const Method = enum { CONNECT, TRACE, + const with_body: std.enums.EnumSet(Method) = brk: { + var values = std.enums.EnumSet(Method).initFull(); + values.remove(.HEAD); + values.remove(.TRACE); + break :brk values; + }; + + pub fn hasBody(this: Method) bool { + return with_body.contains(this); + } + pub fn which(str: []const u8) ?Method { if (str.len < 3) { return null; |