Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/proxy/server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ const ResponseTruncated = struct {
max_size: usize,
};

const ModifiedPayloadBypassed = struct {
reason: []const u8,
};

const UpstreamRetry = struct {
attempt: u8,
max_retries: u8,
Expand Down Expand Up @@ -529,9 +533,13 @@ fn proxyHandler(ctx: *ServerContext, req: *httpz.Request, res: *httpz.Response,
if (encoding != .none) {
body_to_send = compressIfNeeded(req.arena, module_result.modified_body, encoding) catch |err| blk: {
ctx.bus.warn(CompressError{ .err = @errorName(err) });
break :blk module_result.modified_body; // Fall back to uncompressed
// Payload integrity first: if we cannot safely re-encode a modified payload,
// bypass modification and forward the original body unchanged.
ctx.bus.warn(ModifiedPayloadBypassed{ .reason = "recompression_failed" });
break :blk original_body;
};
compressed_allocated = (body_to_send.ptr != module_result.modified_body.ptr);
compressed_allocated = (body_to_send.ptr != module_result.modified_body.ptr and
body_to_send.ptr != original_body.ptr);
}
defer if (compressed_allocated) req.arena.free(body_to_send);

Expand Down
Loading