mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
std.http: stop assuming previous chunk state
The full file may not be written, either due to a previous chunk being in-progress when `sendFile` was called, or due to `limit`.
This commit is contained in:
parent
bc524a2b1a
commit
b05fefb9c9
1 changed files with 3 additions and 4 deletions
|
|
@ -962,6 +962,7 @@ pub const BodyWriter = struct {
|
||||||
// have to flush the chunk header before knowing the chunk length.
|
// have to flush the chunk header before knowing the chunk length.
|
||||||
return error.Unimplemented;
|
return error.Unimplemented;
|
||||||
};
|
};
|
||||||
|
if (data_len == 0) return error.EndOfStream;
|
||||||
const out = bw.http_protocol_output;
|
const out = bw.http_protocol_output;
|
||||||
l: switch (bw.state.chunk_len) {
|
l: switch (bw.state.chunk_len) {
|
||||||
0 => {
|
0 => {
|
||||||
|
|
@ -975,8 +976,7 @@ pub const BodyWriter = struct {
|
||||||
2 => {
|
2 => {
|
||||||
try out.writeAll("\r\n");
|
try out.writeAll("\r\n");
|
||||||
bw.state.chunk_len = 0;
|
bw.state.chunk_len = 0;
|
||||||
assert(file_reader.atEnd());
|
continue :l 0;
|
||||||
return error.EndOfStream;
|
|
||||||
},
|
},
|
||||||
else => {
|
else => {
|
||||||
const chunk_limit: std.Io.Limit = .limited(bw.state.chunk_len - 2);
|
const chunk_limit: std.Io.Limit = .limited(bw.state.chunk_len - 2);
|
||||||
|
|
@ -985,8 +985,7 @@ pub const BodyWriter = struct {
|
||||||
else
|
else
|
||||||
try out.write(chunk_limit.slice(w.buffered()));
|
try out.write(chunk_limit.slice(w.buffered()));
|
||||||
bw.state.chunk_len -= n;
|
bw.state.chunk_len -= n;
|
||||||
const ret = w.consume(n);
|
return w.consume(n);
|
||||||
return ret;
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue