Hey! I'm writing a web backend in Zig using the new std.http.Server (insane, I know). It's currently serving a HTML document with a stylesheet and a script linked. The browser can request the document and the script just fine, but indefinetely hangs on the stylesheet. This is very strange, as the exact same endpoint works just fine without loading the rest of the document. This makes me conclude that the problem here comes from the large amount of requests the browser sends.
This is how my code looks:
pub fn main() !void {
// create server and make it listen
while (true) {
const res = try server.accept(.{ .dynamic = 1024 * 2 });
(try std.Thread.spawn(.{}, handleRequest, .{ res })).detach();
}
}
fn handleRequest(res: *std.http.Server.Response) !void {
defer res.reset();
try res.wait();
res.headers.connection = res.request.headers.connection;
// this is not reached in the request for the stylesheet from firefox!
std.log.info("req: {s}", .{res.request.headers.target});
// some logic to decide what to serve here
res.headers.custom = &.{.{ .name = "Content-Type", "text/css" }};
res.headers.transfer_encoding = .{ .content_length = data.len };
try res.do();
try res.writer().writeAll(data);
try res.finish();
}
Note: while firefox is waiting for a response (forever), I can request the CSS file with curl just fine.