1
0
Fork 0
mirror of https://github.com/zigzap/zap.git synced 2025-10-20 23:24:09 +00:00

removed unused code

This commit is contained in:
Rene Schallner 2023-04-22 23:29:25 +02:00
parent 9023bdb246
commit f5eb3ca888
4 changed files with 7 additions and 211 deletions

View file

@ -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(.{

View file

@ -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();
}

View file

@ -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);
}

View file

@ -7,3 +7,4 @@ endpoint
wrk
mustache
endpoint_auth
pkghash