mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 15:13:28 +00:00
Merge pull request #511 from lightpanda-io/http_chunk_reader_fix
Some checks failed
e2e-test / zig build release (push) Has been cancelled
e2e-test / puppeteer-perf (push) Has been cancelled
e2e-test / demo-scripts (push) Has been cancelled
wpt / web platform tests (push) Has been cancelled
wpt / web platform tests json output (push) Has been cancelled
wpt / perf-fmt (push) Has been cancelled
zig-test / zig build dev (push) Has been cancelled
zig-test / browser fetch (push) Has been cancelled
zig-test / zig test (push) Has been cancelled
zig-test / perf-fmt (push) Has been cancelled
Some checks failed
e2e-test / zig build release (push) Has been cancelled
e2e-test / puppeteer-perf (push) Has been cancelled
e2e-test / demo-scripts (push) Has been cancelled
wpt / web platform tests (push) Has been cancelled
wpt / web platform tests json output (push) Has been cancelled
wpt / perf-fmt (push) Has been cancelled
zig-test / zig build dev (push) Has been cancelled
zig-test / browser fetch (push) Has been cancelled
zig-test / zig test (push) Has been cancelled
zig-test / perf-fmt (push) Has been cancelled
Don't emit incorrect empty chunk
This commit is contained in:
@@ -1342,24 +1342,38 @@ const Reader = struct {
|
|||||||
|
|
||||||
const size = self.size.?;
|
const size = self.size.?;
|
||||||
const missing = self.missing;
|
const missing = self.missing;
|
||||||
|
|
||||||
if (data.len >= missing) {
|
if (data.len >= missing) {
|
||||||
// we have a complete chunk;
|
|
||||||
var chunk: ?[]u8 = data;
|
|
||||||
if (missing == 1) {
|
|
||||||
const last = missing - 1;
|
|
||||||
if (data[last] != '\n') {
|
|
||||||
return error.InvalidChunk;
|
|
||||||
}
|
|
||||||
chunk = null;
|
|
||||||
} else {
|
|
||||||
const last = missing - 2;
|
|
||||||
if (data[last] != '\r' or data[missing - 1] != '\n') {
|
|
||||||
return error.InvalidChunk;
|
|
||||||
}
|
|
||||||
chunk = if (last == 0) null else data[0..last];
|
|
||||||
}
|
|
||||||
self.size = null;
|
self.size = null;
|
||||||
self.missing = 0;
|
self.missing = 0;
|
||||||
|
if (missing == 1) {
|
||||||
|
if (data[0] != '\n') {
|
||||||
|
return error.InvalidChunk;
|
||||||
|
}
|
||||||
|
if (data.len == 1) {
|
||||||
|
return .{ true, .{ .data = null, .done = size == 0, .unprocessed = null } };
|
||||||
|
}
|
||||||
|
return self.process(data[1..]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (missing == 2) {
|
||||||
|
if (data[0] != '\r' or data[1] != '\n') {
|
||||||
|
return error.InvalidChunk;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.len == 2) {
|
||||||
|
return .{ true, .{ .data = null, .done = size == 0, .unprocessed = null } };
|
||||||
|
}
|
||||||
|
return self.process(data[2..]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// we have a complete chunk;
|
||||||
|
var chunk: ?[]u8 = data;
|
||||||
|
const last = missing - 2;
|
||||||
|
if (data[last] != '\r' or data[missing - 1] != '\n') {
|
||||||
|
return error.InvalidChunk;
|
||||||
|
}
|
||||||
|
chunk = if (last == 0) null else data[0..last];
|
||||||
|
|
||||||
const unprocessed = data[missing..];
|
const unprocessed = data[missing..];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user