| ... | @@ -197,9 +197,9 @@ pub const Request = struct { | ... | @@ -197,9 +197,9 @@ pub const Request = struct { |
| 197 | }; | 197 | }; |
| 198 | | 198 | |
| 199 | pub fn parse(req: *Request, bytes: []const u8) ParseError!void { | 199 | pub fn parse(req: *Request, bytes: []const u8) ParseError!void { |
| 200 | var it = mem.tokenizeAny(u8, bytes, "\r\n"); | 200 | var it = mem.splitSequence(u8, bytes, "\r\n"); |
| 201 | | 201 | |
| 202 | const first_line = it.next() orelse return error.HttpHeadersInvalid; | 202 | const first_line = it.next().?; |
| 203 | if (first_line.len < 10) | 203 | if (first_line.len < 10) |
| 204 | return error.HttpHeadersInvalid; | 204 | return error.HttpHeadersInvalid; |
| 205 | | 205 | |
| ... | @@ -229,15 +229,16 @@ pub const Request = struct { | ... | @@ -229,15 +229,16 @@ pub const Request = struct { |
| 229 | req.version = version; | 229 | req.version = version; |
| 230 | | 230 | |
| 231 | while (it.next()) |line| { | 231 | while (it.next()) |line| { |
| 232 | if (line.len == 0) return error.HttpHeadersInvalid; | 232 | if (line.len == 0) return; |
| 233 | switch (line[0]) { | 233 | switch (line[0]) { |
| 234 | ' ', '\t' => return error.HttpHeaderContinuationsUnsupported, | 234 | ' ', '\t' => return error.HttpHeaderContinuationsUnsupported, |
| 235 | else => {}, | 235 | else => {}, |
| 236 | } | 236 | } |
| 237 | | 237 | |
| 238 | var line_it = mem.tokenizeAny(u8, line, ": "); | 238 | var line_it = mem.splitSequence(u8, line, ": "); |
| 239 | const header_name = line_it.next() orelse return error.HttpHeadersInvalid; | 239 | const header_name = line_it.next().?; |
| 240 | const header_value = line_it.rest(); | 240 | const header_value = line_it.rest(); |
| | 241 | if (header_value.len == 0) return error.HttpHeadersInvalid; |
| 241 | | 242 | |
| 242 | if (std.ascii.eqlIgnoreCase(header_name, "connection")) { | 243 | if (std.ascii.eqlIgnoreCase(header_name, "connection")) { |
| 243 | req.keep_alive = !std.ascii.eqlIgnoreCase(header_value, "close"); | 244 | req.keep_alive = !std.ascii.eqlIgnoreCase(header_value, "close"); |
| ... | @@ -291,6 +292,7 @@ pub const Request = struct { | ... | @@ -291,6 +292,7 @@ pub const Request = struct { |
| 291 | if (iter.next()) |_| return error.HttpTransferEncodingUnsupported; | 292 | if (iter.next()) |_| return error.HttpTransferEncodingUnsupported; |
| 292 | } | 293 | } |
| 293 | } | 294 | } |
| | 295 | return error.HttpHeadersInvalid; // missing empty line |
| 294 | } | 296 | } |
| 295 | | 297 | |
| 296 | inline fn int64(array: *const [8]u8) u64 { | 298 | inline fn int64(array: *const [8]u8) u64 { |