From f5eb3ca888335dfa05689762a33349cf8a31a733 Mon Sep 17 00:00:00 2001 From: Rene Schallner Date: Sat, 22 Apr 2023 23:29:25 +0200 Subject: [PATCH] removed unused code --- build.zig | 39 +++------------ src/http_client.zig | 88 --------------------------------- src/http_client_testrunner.zig | 90 ---------------------------------- targets.txt | 1 + 4 files changed, 7 insertions(+), 211 deletions(-) delete mode 100644 src/http_client.zig delete mode 100644 src/http_client_testrunner.zig diff --git a/build.zig b/build.zig index 8808ecd..bd74f89 100644 --- a/build.zig +++ b/build.zig @@ -29,9 +29,12 @@ pub fn build(b: *std.build.Builder) !void { }); facil_lib.linkLibrary(facil_dep.artifact("facil.io")); - // facil_lib.install(); - const unused_facil_install_step = b.addInstallArtifact(facil_lib); - _ = unused_facil_install_step; + + // we install the facil dependency, just to see what it's like + // zig build with the default (install) step will install it + facil_lib.installLibraryHeaders(facil_dep.artifact("facil.io")); + const facil_install_step = b.addInstallArtifact(facil_lib); + b.getInstallStep().dependOn(&facil_install_step.step); inline for ([_]struct { name: []const u8, @@ -90,36 +93,6 @@ pub fn build(b: *std.build.Builder) !void { // TOOLS & TESTING // - // authenticating http client for internal testing - // (facil.io based, not used anymore) - // - var http_client_exe = b.addExecutable(.{ - .name = "http_client", - .root_source_file = .{ .path = "./src/http_client.zig" }, - .target = target, - .optimize = optimize, - }); - var http_client_step = b.step("http_client", "Build the http_client for internal testing"); - http_client_exe.linkLibrary(facil_dep.artifact("facil.io")); - http_client_exe.addModule("zap", zap_module); - const http_client_build_step = b.addInstallArtifact(http_client_exe); - http_client_step.dependOn(&http_client_build_step.step); - - // test runner for auth tests - // - var http_client_runner_exe = b.addExecutable(.{ - .name = "http_client_runner", - .root_source_file = .{ .path = "./src/http_client_testrunner.zig" }, - .target = target, - .optimize = optimize, - }); - var http_client_runner_step = b.step("http_client_runner", "Build the http_client test runner for internal testing"); - http_client_runner_exe.linkLibrary(facil_dep.artifact("facil.io")); - http_client_runner_exe.addModule("zap", zap_module); - const http_client_runner_build_step = b.addInstallArtifact(http_client_runner_exe); - http_client_runner_step.dependOn(&http_client_runner_build_step.step); - http_client_runner_exe.step.dependOn(&http_client_build_step.step); - // tests // const auth_tests = b.addTest(.{ diff --git a/src/http_client.zig b/src/http_client.zig deleted file mode 100644 index fe115e1..0000000 --- a/src/http_client.zig +++ /dev/null @@ -1,88 +0,0 @@ -const std = @import("std"); -const zap = @import("zap.zig"); -const fio = @import("fio.zig"); -const util = @import("util.zig"); -const auth = @import("http_auth.zig"); - -var http_header_field: [:0]const u8 = undefined; -var http_header_value: [:0]const u8 = undefined; - -pub fn main() !void { - var allocator = std.heap.page_allocator; - var args_it = std.process.args(); - _ = args_it.skip(); // skip process name - // - const url = args_it.next() orelse "http://127.0.0.1:3000/test"; - const method = args_it.next() orelse "Bearer"; - const token = args_it.next() orelse "ABCDEFG"; - - const scheme: auth.AuthScheme = if (std.mem.eql(u8, method, "Bearer")) .Bearer else .Basic; - http_header_field = scheme.headerFieldStrHeader(); - - http_header_value = switch (scheme) { - .Basic => try std.fmt.allocPrintZ(allocator, "Basic {s}", .{token}), - .Bearer => try std.fmt.allocPrintZ(allocator, "Bearer {s}", .{token}), - }; - - std.debug.print("Connecting to: {s}\n", .{url}); - std.debug.print(" Header: '{s}:{s}'\n", .{ http_header_field, http_header_value }); - - const ret = zap.http_connect(url, null, .{ - .on_response = on_response, - .on_request = null, - .on_upgrade = null, - .on_finish = null, - .udata = null, - .public_folder = null, - .public_folder_length = 0, - .max_header_size = 32 * 1024, - .max_body_size = 500 * 1024, - .max_clients = 1, - .tls = null, - .reserved1 = 0, - .reserved2 = 0, - .reserved3 = 0, - .ws_max_msg_size = 0, - .timeout = 5, - .ws_timeout = 0, - .log = 1, - .is_client = 1, - }); - std.debug.print("\nHTTP CONNECT ret = {d}\n", .{ret}); - zap.fio_start(.{ .threads = 1, .workers = 1 }); -} - -pub fn setHeader(h: [*c]fio.http_s, name: [:0]const u8, value: [:0]const u8) !void { - const hname: fio.fio_str_info_s = .{ - .data = util.toCharPtr(name), - .len = name.len, - .capa = name.len, - }; - - const vname: fio.fio_str_info_s = .{ - .data = util.toCharPtr(value), - .len = value.len, - .capa = value.len, - }; - const ret = fio.http_set_header2(h, hname, vname); - - if (ret == 0) return; - return zap.HttpError.HttpSetHeader; -} - -fn on_response(r: [*c]fio.http_s) callconv(.C) void { - // the first time around, we need to complete the request. E.g. set headers. - if (r.*.status_str == zap.FIOBJ_INVALID) { - setHeader(r, http_header_field, http_header_value) catch return; - zap.http_finish(r); - return; - } - - const response = zap.http_req2str(r); - if (zap.fio2str(response)) |body| { - std.debug.print("{s}\n", .{body}); - } else { - std.debug.print("Oops\n", .{}); - } - zap.fio_stop(); -} diff --git a/src/http_client_testrunner.zig b/src/http_client_testrunner.zig deleted file mode 100644 index 6d3b2a1..0000000 --- a/src/http_client_testrunner.zig +++ /dev/null @@ -1,90 +0,0 @@ -const std = @import("std"); - -const seconds_between_steps: usize = 3; - -pub fn main() !void { - const a = std.heap.page_allocator; - - // Bearer Single - var p = std.ChildProcess.init(&.{ - "./zig-out/bin/http_client", - "http://127.0.0.1:3000/test", - "Bearer", - "ABCDEFG", - }, a); - _ = try p.spawnAndWait(); - - std.time.sleep(seconds_between_steps * std.time.ns_per_s); - - p = std.ChildProcess.init(&.{ - "./zig-out/bin/http_client", - "http://127.0.0.1:3000/test", - "Bearer", - "invalid", - }, a); - _ = try p.spawnAndWait(); - - std.time.sleep(seconds_between_steps * std.time.ns_per_s); - - // Bearer Multi - p = std.ChildProcess.init(&.{ - "./zig-out/bin/http_client", - "http://127.0.0.1:3000/test", - "Bearer", - "ABCDEFG", - }, a); - _ = try p.spawnAndWait(); - - std.time.sleep(seconds_between_steps * std.time.ns_per_s); - - p = std.ChildProcess.init(&.{ - "./zig-out/bin/http_client", - "http://127.0.0.1:3000/test", - "Bearer", - "invalid", - }, a); - _ = try p.spawnAndWait(); - - std.time.sleep(seconds_between_steps * std.time.ns_per_s); - - // Basic - p = std.ChildProcess.init(&.{ - "./zig-out/bin/http_client", - "http://127.0.0.1:3000/test", - "Basic", - "QWxhZGRpbjpvcGVuIHNlc2FtZQ==", - }, a); - _ = try p.spawnAndWait(); - - std.time.sleep(seconds_between_steps * std.time.ns_per_s); - - p = std.ChildProcess.init(&.{ - "./zig-out/bin/http_client", - "http://127.0.0.1:3000/test", - "Basic", - "invalid", - }, a); - _ = try p.spawnAndWait(); - - std.time.sleep(seconds_between_steps * std.time.ns_per_s); - - p = std.ChildProcess.init(&.{ - "./zig-out/bin/http_client", - "http://127.0.0.1:3000/test", - "Basic", - "QWxsYWRkaW46b3BlbnNlc2FtZQ==", - }, a); - _ = try p.spawnAndWait(); - - std.time.sleep(seconds_between_steps * std.time.ns_per_s); - - p = std.ChildProcess.init(&.{ - "./zig-out/bin/http_client", - "http://127.0.0.1:3000/test", - "Basic", - "QWxsYWRkaW46b3BlbnNlc2FtZQ==-invalid", - }, a); - _ = try p.spawnAndWait(); - - // std.time.sleep(seconds_between_steps * std.time.ns_per_s); -} diff --git a/targets.txt b/targets.txt index 4b27699..5263529 100644 --- a/targets.txt +++ b/targets.txt @@ -7,3 +7,4 @@ endpoint wrk mustache endpoint_auth +pkghash