web: fix compile errors and critical runtime errors
This commit is contained in:
@@ -22,7 +22,7 @@ const vec_len = @typeInfo(Vec).vector.len;
|
||||
const Pattern = struct {
|
||||
value: Vec,
|
||||
mask: Vec,
|
||||
len: u6,
|
||||
len: u32,
|
||||
|
||||
pub fn init(comptime prefix: []const u8) Pattern {
|
||||
if (prefix.len > vec_len) {
|
||||
@@ -40,6 +40,12 @@ const Pattern = struct {
|
||||
mask[i] = 0x00;
|
||||
}
|
||||
}
|
||||
|
||||
return .{
|
||||
.value = value,
|
||||
.mask = mask,
|
||||
.len = prefix.len,
|
||||
};
|
||||
}
|
||||
|
||||
inline fn check(self: Pattern, vec: Vec) bool {
|
||||
@@ -199,21 +205,22 @@ pub fn consume(self: *Parser, chars: []const u8) Error!ConsumeResult {
|
||||
};
|
||||
},
|
||||
else => {
|
||||
if (chars.len - i >= vec_len) {
|
||||
const vec_res = try self.consumeVec(chars[i..][0..vec_len]);
|
||||
i += vec_res.consumed;
|
||||
// TODO Fix
|
||||
// if (chars.len - i >= vec_len) {
|
||||
// const vec_res = try self.consumeVec(chars[i..][0..vec_len]);
|
||||
// i += vec_res.consumed;
|
||||
|
||||
if (vec_res.done) {
|
||||
return .{
|
||||
.consumed = i,
|
||||
.done = true,
|
||||
};
|
||||
}
|
||||
// if (vec_res.done) {
|
||||
// return .{
|
||||
// .consumed = i,
|
||||
// .done = true,
|
||||
// };
|
||||
// }
|
||||
|
||||
if (vec_res.consumed > 0) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// if (vec_res.consumed > 0) {
|
||||
// continue;
|
||||
// }
|
||||
// }
|
||||
|
||||
const char_res = try self.consumeChar(&chars[i]);
|
||||
i += 1;
|
||||
@@ -231,7 +238,8 @@ pub fn consume(self: *Parser, chars: []const u8) Error!ConsumeResult {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn consumeVec(self: *Parser, vec: *const [vec_len]u8) Error!ConsumeResult {
|
||||
pub fn consumeVec(self: *Parser, vec_ptr: *const [vec_len]u8) Error!ConsumeResult {
|
||||
const vec: Vec = vec_ptr.*;
|
||||
switch (self.state) {
|
||||
.init => {
|
||||
inline for (@typeInfo(patterns.methods).@"struct".decls) |decl| {
|
||||
@@ -257,6 +265,10 @@ pub fn consumeVec(self: *Parser, vec: *const [vec_len]u8) Error!ConsumeResult {
|
||||
}
|
||||
|
||||
self.state = .pathname(s.method, s.pathname.ptr[0 .. s.pathname.len + vec_len]);
|
||||
return .{
|
||||
.consumed = vec_len,
|
||||
.done = false,
|
||||
};
|
||||
},
|
||||
.pathname_complete => {
|
||||
if (patterns.@"version_http/1.1".check(vec)) {
|
||||
@@ -279,6 +291,10 @@ pub fn consumeVec(self: *Parser, vec: *const [vec_len]u8) Error!ConsumeResult {
|
||||
}
|
||||
|
||||
self.state = .headerValue(s.name, s.value.ptr[0 .. s.value.len + vec_len]);
|
||||
return .{
|
||||
.consumed = vec_len,
|
||||
.done = false,
|
||||
};
|
||||
},
|
||||
else => {
|
||||
// Delegate to `consumeChar`.
|
||||
@@ -444,7 +460,7 @@ pub fn consumeChar(self: *Parser, c_ptr: *const u8) Error!ConsumeCharResult {
|
||||
self.content_length = std.fmt.parseInt(usize, header.value, 10) catch return error.InvalidContentLength;
|
||||
}
|
||||
|
||||
self.request_handler.rawHeader(header) catch |err| {
|
||||
self.request_handler.?.rawHeader(self.response, header) catch |err| {
|
||||
self.last_handler_error = err;
|
||||
return error.HandlerError;
|
||||
};
|
||||
@@ -458,7 +474,10 @@ pub fn consumeChar(self: *Parser, c_ptr: *const u8) Error!ConsumeCharResult {
|
||||
.headers_end => switch (c) {
|
||||
'\n' => {
|
||||
if (self.content_length == 0) {
|
||||
self.handler.rawBody(self.request, &.{});
|
||||
self.request_handler.?.rawBody(self.response, &.{}) catch |err| {
|
||||
self.last_handler_error = err;
|
||||
return error.HandlerError;
|
||||
};
|
||||
return .done;
|
||||
}
|
||||
self.state = .{ .body = @as([*]const u8, @ptrCast(c_ptr))[1..1] };
|
||||
@@ -469,7 +488,10 @@ pub fn consumeChar(self: *Parser, c_ptr: *const u8) Error!ConsumeCharResult {
|
||||
const new_body = body.ptr[0 .. body.len + 1];
|
||||
self.state = .{ .body = new_body };
|
||||
if (new_body.len >= self.content_length) {
|
||||
self.handler.rawBody(self.request, new_body);
|
||||
self.request_handler.?.rawBody(self.response, new_body) catch |err| {
|
||||
self.last_handler_error = err;
|
||||
return error.HandlerError;
|
||||
};
|
||||
return .done;
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user