aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/http.zig12
-rw-r--r--src/http/method.zig12
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;