mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-29 15:13:28 +00:00
Merge pull request #623 from lightpanda-io/http_client_keepalive
add keepalive to http client
This commit is contained in:
@@ -813,7 +813,7 @@ test "Browser.XHR.XMLHttpRequest" {
|
||||
.{ "req.status", "200" },
|
||||
.{ "req.statusText", "OK" },
|
||||
.{ "req.getResponseHeader('Content-Type')", "text/html; charset=utf-8" },
|
||||
.{ "req.getAllResponseHeaders().length", "61" },
|
||||
.{ "req.getAllResponseHeaders().length", "80" },
|
||||
.{ "req.responseText.length", "100" },
|
||||
.{ "req.response.length == req.responseText.length", "true" },
|
||||
.{ "req.responseXML instanceof Document", "true" },
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
36
src/main.zig
36
src/main.zig
@@ -470,7 +470,6 @@ fn serveHTTP(address: std.net.Address) !void {
|
||||
defer conn.stream.close();
|
||||
var http_server = std.http.Server.init(conn, &read_buffer);
|
||||
|
||||
while (http_server.state == .ready) {
|
||||
var request = http_server.receiveHead() catch |err| switch (err) {
|
||||
error.HttpConnectionClosing => continue :ACCEPT,
|
||||
else => {
|
||||
@@ -481,23 +480,30 @@ fn serveHTTP(address: std.net.Address) !void {
|
||||
|
||||
const path = request.head.target;
|
||||
if (std.mem.eql(u8, path, "/loader")) {
|
||||
try request.respond("Hello!", .{});
|
||||
try request.respond("Hello!", .{
|
||||
.extra_headers = &.{.{ .name = "Connection", .value = "close" }},
|
||||
});
|
||||
} else if (std.mem.eql(u8, path, "/http_client/simple")) {
|
||||
try request.respond("", .{});
|
||||
try request.respond("", .{
|
||||
.extra_headers = &.{.{ .name = "Connection", .value = "close" }},
|
||||
});
|
||||
} else if (std.mem.eql(u8, path, "/http_client/redirect")) {
|
||||
try request.respond("", .{
|
||||
.status = .moved_permanently,
|
||||
.extra_headers = &.{.{ .name = "LOCATION", .value = "../http_client/echo" }},
|
||||
.extra_headers = &.{
|
||||
.{ .name = "Connection", .value = "close" },
|
||||
.{ .name = "LOCATION", .value = "../http_client/echo" },
|
||||
},
|
||||
});
|
||||
} else if (std.mem.eql(u8, path, "/http_client/redirect/secure")) {
|
||||
try request.respond("", .{
|
||||
.status = .moved_permanently,
|
||||
.extra_headers = &.{.{ .name = "LOCATION", .value = "https://127.0.0.1:9581/http_client/body" }},
|
||||
.extra_headers = &.{ .{ .name = "Connection", .value = "close" }, .{ .name = "LOCATION", .value = "https://127.0.0.1:9581/http_client/body" } },
|
||||
});
|
||||
} else if (std.mem.eql(u8, path, "/http_client/gzip")) {
|
||||
const body = &.{ 0x1f, 0x8b, 0x08, 0x08, 0x01, 0xc6, 0x19, 0x68, 0x00, 0x03, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x68, 0x74, 0x6d, 0x6c, 0x00, 0x73, 0x54, 0xc8, 0x4b, 0x2d, 0x57, 0x48, 0x2a, 0xca, 0x2f, 0x2f, 0x4e, 0x2d, 0x52, 0x48, 0x2a, 0xcd, 0xcc, 0x29, 0x51, 0x48, 0xcb, 0x2f, 0x52, 0xc8, 0x4d, 0x4c, 0xce, 0xc8, 0xcc, 0x4b, 0x2d, 0xe6, 0x02, 0x00, 0xe7, 0xc3, 0x4b, 0x27, 0x21, 0x00, 0x00, 0x00 };
|
||||
try request.respond(body, .{
|
||||
.extra_headers = &.{.{ .name = "Content-Encoding", .value = "gzip" }},
|
||||
.extra_headers = &.{ .{ .name = "Connection", .value = "close" }, .{ .name = "Content-Encoding", .value = "gzip" } },
|
||||
});
|
||||
} else if (std.mem.eql(u8, path, "/http_client/echo")) {
|
||||
var headers: std.ArrayListUnmanaged(std.http.Header) = .{};
|
||||
@@ -509,6 +515,7 @@ fn serveHTTP(address: std.net.Address) !void {
|
||||
.value = hdr.value,
|
||||
});
|
||||
}
|
||||
try headers.append(aa, .{ .name = "Connection", .value = "Close" });
|
||||
|
||||
try request.respond("over 9000!", .{
|
||||
.status = .created,
|
||||
@@ -517,7 +524,6 @@ fn serveHTTP(address: std.net.Address) !void {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This is a lot of work for testing TLS, but the TLS (async) code is complicated
|
||||
// This "server" is written specifically to test the client. It assumes the client
|
||||
@@ -528,9 +534,6 @@ fn serveHTTPS(address: std.net.Address) !void {
|
||||
var listener = try address.listen(.{ .reuse_address = true });
|
||||
defer listener.deinit();
|
||||
|
||||
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer arena.deinit();
|
||||
|
||||
test_wg.finish();
|
||||
|
||||
var seed: u64 = undefined;
|
||||
@@ -540,9 +543,6 @@ fn serveHTTPS(address: std.net.Address) !void {
|
||||
|
||||
var read_buffer: [1024]u8 = undefined;
|
||||
while (true) {
|
||||
// defer _ = arena.reset(.{ .retain_with_limit = 1024 });
|
||||
// const aa = arena.allocator();
|
||||
|
||||
const stream = blk: {
|
||||
const conn = try listener.accept();
|
||||
break :blk conn.stream;
|
||||
@@ -570,17 +570,17 @@ fn serveHTTPS(address: std.net.Address) !void {
|
||||
var response: []const u8 = undefined;
|
||||
if (std.mem.eql(u8, path, "/http_client/simple")) {
|
||||
fragment = true;
|
||||
response = "HTTP/1.1 200 \r\nContent-Length: 0\r\n\r\n";
|
||||
response = "HTTP/1.1 200 \r\nContent-Length: 0\r\nConnection: Close\r\n\r\n";
|
||||
} else if (std.mem.eql(u8, path, "/http_client/body")) {
|
||||
fragment = true;
|
||||
response = "HTTP/1.1 201 CREATED\r\nContent-Length: 20\r\n Another : HEaDer \r\n\r\n1234567890abcdefhijk";
|
||||
response = "HTTP/1.1 201 CREATED\r\nContent-Length: 20\r\nConnection: Close\r\n Another : HEaDer \r\n\r\n1234567890abcdefhijk";
|
||||
} else if (std.mem.eql(u8, path, "/http_client/redirect/insecure")) {
|
||||
fragment = true;
|
||||
response = "HTTP/1.1 307 GOTO\r\nLocation: http://127.0.0.1:9582/http_client/redirect\r\n\r\n";
|
||||
response = "HTTP/1.1 307 GOTO\r\nLocation: http://127.0.0.1:9582/http_client/redirect\r\nConnection: Close\r\n\r\n";
|
||||
} else if (std.mem.eql(u8, path, "/xhr")) {
|
||||
response = "HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=utf-8\r\nContent-Length: 100\r\n\r\n" ++ ("1234567890" ** 10);
|
||||
response = "HTTP/1.1 200 OK\r\nContent-Type: text/html; charset=utf-8\r\nContent-Length: 100\r\nConnection: Close\r\n\r\n" ++ ("1234567890" ** 10);
|
||||
} else if (std.mem.eql(u8, path, "/xhr/json")) {
|
||||
response = "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: 18\r\n\r\n{\"over\":\"9000!!!\"}";
|
||||
response = "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: 18\r\nConnection: Close\r\n\r\n{\"over\":\"9000!!!\"}";
|
||||
} else {
|
||||
// should not have an unknown path
|
||||
unreachable;
|
||||
|
||||
Reference in New Issue
Block a user