diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2024-02-21 00:16:03 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2024-02-23 02:37:11 -0700 |
| commit | b4b9f6aa4a5bfd6a54b59444f3e1a3706358eb76 (patch) | |
| tree | d20273d53d628d62c2284895f10c187a4d062208 /lib/std/http/HeadParser.zig | |
| parent | a8958c99a9ecfd0a95dc8194b5a4fd172739b30e (diff) | |
| download | zig-b4b9f6aa4a5bfd6a54b59444f3e1a3706358eb76.tar.gz zig-b4b9f6aa4a5bfd6a54b59444f3e1a3706358eb76.zip | |
std.http.Server: reimplement chunked uploading
* Uncouple std.http.ChunkParser from protocol.zig
* Fix receiveHead not passing leftover buffer through the header parser.
* Fix content-length read streaming
This implementation handles the final chunk length correctly rather than
"hoping" that the buffer already contains \r\n.
Diffstat (limited to 'lib/std/http/HeadParser.zig')
| -rw-r--r-- | lib/std/http/HeadParser.zig | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/lib/std/http/HeadParser.zig b/lib/std/http/HeadParser.zig index 07c357731a..bb49faa14b 100644 --- a/lib/std/http/HeadParser.zig +++ b/lib/std/http/HeadParser.zig @@ -1,3 +1,5 @@ +//! Finds the end of an HTTP head in a stream. + state: State = .start, pub const State = enum { @@ -17,13 +19,12 @@ pub const State = enum { /// `bytes[result]`. pub fn feed(p: *HeadParser, bytes: []const u8) usize { const vector_len: comptime_int = @max(std.simd.suggestVectorLength(u8) orelse 1, 8); - const len: u32 = @intCast(bytes.len); - var index: u32 = 0; + var index: usize = 0; while (true) { switch (p.state) { .finished => return index, - .start => switch (len - index) { + .start => switch (bytes.len - index) { 0 => return index, 1 => { switch (bytes[index]) { @@ -218,7 +219,7 @@ pub fn feed(p: *HeadParser, bytes: []const u8) usize { continue; }, }, - .seen_n => switch (len - index) { + .seen_n => switch (bytes.len - index) { 0 => return index, else => { switch (bytes[index]) { @@ -230,7 +231,7 @@ pub fn feed(p: *HeadParser, bytes: []const u8) usize { continue; }, }, - .seen_r => switch (len - index) { + .seen_r => switch (bytes.len - index) { 0 => return index, 1 => { switch (bytes[index]) { @@ -286,7 +287,7 @@ pub fn feed(p: *HeadParser, bytes: []const u8) usize { continue; }, }, - .seen_rn => switch (len - index) { + .seen_rn => switch (bytes.len - index) { 0 => return index, 1 => { switch (bytes[index]) { @@ -317,7 +318,7 @@ pub fn feed(p: *HeadParser, bytes: []const u8) usize { continue; }, }, - .seen_rnr => switch (len - index) { + .seen_rnr => switch (bytes.len - index) { 0 => return index, else => { switch (bytes[index]) { |
