Skip to content

Commit 5816443

Browse files
committed
improve XHR test reliability
1 parent e9fce92 commit 5816443

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/main.zig

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -561,13 +561,16 @@ fn serveHTTPS(address: std.net.Address) !void {
561561
_ = it.next() orelse unreachable; // method
562562
const path = it.next() orelse unreachable;
563563

564-
std.debug.print("http server: {s} ", .{path});
564+
var fragment = false;
565565
var response: []const u8 = undefined;
566566
if (std.mem.eql(u8, path, "/http_client/simple")) {
567+
fragment = true;
567568
response = "HTTP/1.1 200 \r\nContent-Length: 0\r\n\r\n";
568569
} else if (std.mem.eql(u8, path, "/http_client/body")) {
570+
fragment = true;
569571
response = "HTTP/1.1 201 CREATED\r\nContent-Length: 20\r\n Another : HEaDer \r\n\r\n1234567890abcdefhijk";
570572
} else if (std.mem.eql(u8, path, "/http_client/redirect/insecure")) {
573+
fragment = true;
571574
response = "HTTP/1.1 307 GOTO\r\nLocation: http://127.0.0.1:9582/http_client/redirect\r\n\r\n";
572575
} else if (std.mem.eql(u8, path, "/xhr")) {
573576
response = "HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=utf-8\r\nContent-Length: 100\r\n\r\n" ++ ("1234567890" ** 10);
@@ -580,13 +583,11 @@ fn serveHTTPS(address: std.net.Address) !void {
580583

581584
var unsent = response;
582585
while (unsent.len > 0) {
583-
const to_send = rand.intRangeAtMost(usize, 1, unsent.len);
584-
std.debug.print(" {d} ", .{to_send});
586+
const to_send = if (fragment) rand.intRangeAtMost(usize, 1, unsent.len) else unsent.len;
585587
const sent = try conn.write(unsent[0..to_send]);
586588
unsent = unsent[sent..];
587589
std.time.sleep(std.time.ns_per_us * 5);
588590
}
589-
std.debug.print("\n", .{});
590591
break;
591592
}
592593
}

0 commit comments

Comments
 (0)