From ada2bd1837a7fe5a344e8de3017e9109633d6b46 Mon Sep 17 00:00:00 2001 From: Jora Troosh Date: Fri, 27 Oct 2023 12:27:23 +0300 Subject: [PATCH] Fix tiny typos --- README.md | 19 +- blazingly-fast.md | 87 +++-- doc/authentication.md | 8 +- doc/build-localhost.md | 8 +- doc/other-versions.md | 4 +- doc/release-template.md | 2 +- doc/why-no-errors.md | 6 +- doc/zig-ception.md | 2 +- examples/bindataformpost/bindataformpost.zig | 18 +- examples/cookies/cookies.zig | 16 +- examples/endpoint/endpoint.zig | 1 - examples/endpoint/html/index.html | 349 ++++++++++-------- examples/endpoint_auth/endpoint_auth.zig | 2 +- examples/hello_json/hello_json.zig | 2 +- examples/http_params/http_params.zig | 16 +- .../middleware_with_endpoint.zig | 1 - examples/sendfile/sendfile.zig | 16 +- .../userpass_session_auth/html/login.html | 162 ++++---- examples/websockets/frontend/index.html | 342 ++++++++--------- introducing.md | 22 +- src/http_auth.zig | 2 +- src/middleware.zig | 2 +- src/tests/test_auth.zig | 6 +- 23 files changed, 559 insertions(+), 534 deletions(-) diff --git a/README.md b/README.md index 9907eb0..01fa053 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,3 @@ - - # ⚡zap⚡ - blazingly fast backends in zig ![](https://github.com/zigzap/zap/actions/workflows/build-zig-11.yml/badge.svg) [![Discord](https://img.shields.io/discord/1107835896356675706?label=chat&logo=discord&style=plastic)](https://discord.gg/jQAAN6Ubyj) @@ -135,7 +133,7 @@ simplistic testing scenario. So, being somewhere in the ballpark of basic GO performance, zig zap seems to be -... of reasonable performance 😎. +... of reasonable performance 😎. I can rest my case that developing ZAP was a good idea because it's faster than both alternatives: a) staying with Python, and b) creating a GO + Zig hybrid. @@ -211,7 +209,7 @@ $ git init ## (optional) **Note**: Nix/NixOS users are lucky; you can use the existing `flake.nix` and run `nix develop` to get a development shell providing zig and all dependencies to build and run the GO, python, and rust examples for the -`wrk` performance tests. For the mere building of zap projects, +`wrk` performance tests. For the mere building of zap projects, `nix develop .#build` will only fetch zig 0.11.0. With an existing Zig project, adding Zap to it is easy: @@ -364,16 +362,3 @@ pub fn main() !void { }); } ``` - - - - - - - - - - - - - diff --git a/blazingly-fast.md b/blazingly-fast.md index 41f186a..061dc2a 100644 --- a/blazingly-fast.md +++ b/blazingly-fast.md @@ -9,23 +9,23 @@ since I used to write my REST APIs in python before creating zig zap. You can check out the scripts I used for the tests in [./wrk](wrk/). -## Why +## Why I aimed to enhance the performance of my Python + Flask backends by replacing them with a Zig version. To evaluate the success of this transition, I compared the performance of a static HTTP server implemented in Python and its Zig -counterpart, which showed significant improvements. +counterpart, which showed significant improvements. To further assess the Zig server's performance, I compared it with a Go implementation, to compare against a widely used industry-standard. I expected similar performance levels but was pleasantly surprised when Zap outperformed Go -by approximately 30% on my test machine. +by approximately 30% on my test machine. Intrigued by Rust's reputed performance capabilities, I also experimented with a Rust version. The results of this experiment are discussed in the [Flaws](#flaws) section below. -## What +## What So, what are the benchmarks testing? @@ -114,21 +114,21 @@ different computers. It's interesting to see the variation in relative numbers. ``` ➜ neofetch --stdout -rs@ryzen --------- -OS: NixOS 23.05.997.ddf4688dc7a (Stoat) x86_64 -Host: Micro-Star International Co., Ltd. B550-A PRO (MS-7C56) -Kernel: 6.3.7 -Uptime: 15 days, 11 hours, 13 mins -Packages: 2094 (nix-system), 1356 (nix-user), 7 (flatpak) -Shell: bash 5.2.15 -Resolution: 3840x2160 -DE: none+i3 -WM: i3 -Terminal: tmux -CPU: AMD Ryzen 5 5600X (12) @ 3.700GHz -GPU: AMD ATI Radeon RX 6700/6700 XT/6750 XT / 6800M/6850M XT -Memory: 4981MiB / 32028MiB +rs@ryzen +-------- +OS: NixOS 23.05.997.ddf4688dc7a (Stoat) x86_64 +Host: Micro-Star International Co., Ltd. B550-A PRO (MS-7C56) +Kernel: 6.3.7 +Uptime: 15 days, 11 hours, 13 mins +Packages: 2094 (nix-system), 1356 (nix-user), 7 (flatpak) +Shell: bash 5.2.15 +Resolution: 3840x2160 +DE: none+i3 +WM: i3 +Terminal: tmux +CPU: AMD Ryzen 5 5600X (12) @ 3.700GHz +GPU: AMD ATI Radeon RX 6700/6700 XT/6750 XT / 6800M/6850M XT +Memory: 4981MiB / 32028MiB ➜ lscpu @@ -151,25 +151,25 @@ Vendor ID: AuthenticAMD CPU max MHz: 4650.2920 CPU min MHz: 2200.0000 BogoMIPS: 7399.43 - Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt - pdpe1gb rdtscp lm constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 + Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt + pdpe1gb rdtscp lm constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefet ch osvw ibs skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb cat_l3 cdp_l3 hw_pstate ssbd mba ibrs ib pb stibp vmmcall fsgsbase bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xget bv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local clzero irperf xsaveerptr rdpru wbnoinvd arat npt lbrv svm_lock nrip _save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif v_spec_ctrl umip pku ospk e vaes vpclmulqdq rdpid overflow_recov succor smca fsrm -Virtualization features: +Virtualization features: Virtualization: AMD-V -Caches (sum of all): +Caches (sum of all): L1d: 192 KiB (6 instances) L1i: 192 KiB (6 instances) L2: 3 MiB (6 instances) L3: 32 MiB (1 instance) -NUMA: +NUMA: NUMA node(s): 1 NUMA node0 CPU(s): 0-11 -Vulnerabilities: +Vulnerabilities: Itlb multihit: Not affected L1tf: Not affected Mds: Not affected @@ -185,7 +185,7 @@ Vulnerabilities: ### Workstation at work -A beast. Many cores (which we don't use). +A beast. Many cores (which we don't use). ![](./wrk/samples/workstation_req_per_sec_graph.png) @@ -193,19 +193,19 @@ A beast. Many cores (which we don't use). ``` [rene@nixos:~]$ neofetch --stdout -rene@nixos ----------- -OS: NixOS 23.05.2947.475d5ae2c4cb (Stoat) x86_64 -Host: LENOVO 1038 -Kernel: 6.1.46 -Uptime: 26 mins -Packages: 5804 (nix-system), 566 (nix-user) -Shell: bash 5.2.15 -Terminal: /dev/pts/2 -CPU: Intel Xeon Gold 5218 (64) @ 3.900GHz -GPU: NVIDIA Quadro P620 -GPU: NVIDIA Tesla M40 -Memory: 1610MiB / 95247MiB +rene@nixos +---------- +OS: NixOS 23.05.2947.475d5ae2c4cb (Stoat) x86_64 +Host: LENOVO 1038 +Kernel: 6.1.46 +Uptime: 26 mins +Packages: 5804 (nix-system), 566 (nix-user) +Shell: bash 5.2.15 +Terminal: /dev/pts/2 +CPU: Intel Xeon Gold 5218 (64) @ 3.900GHz +GPU: NVIDIA Quadro P620 +GPU: NVIDIA Tesla M40 +Memory: 1610MiB / 95247MiB [rene@nixos:~]$ lscpu @@ -233,18 +233,18 @@ Vendor ID: GenuineIntel ority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm mpx rdt_a avx512f avx512dq rdseed adx smap clflushopt clwb intel_pt avx512cd avx512bw avx512vl xsaveopt xs avec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts hwp hwp_act_window hwp_epp hwp_pkg_req pku ospke avx512_vnni md_clear flush_l1d arch_capabi lities -Virtualization features: +Virtualization features: Virtualization: VT-x -Caches (sum of all): +Caches (sum of all): L1d: 1 MiB (32 instances) L1i: 1 MiB (32 instances) L2: 32 MiB (32 instances) L3: 44 MiB (2 instances) -NUMA: +NUMA: NUMA node(s): 2 NUMA node0 CPU(s): 0-15,32-47 NUMA node1 CPU(s): 16-31,48-63 -Vulnerabilities: +Vulnerabilities: Gather data sampling: Mitigation; Microcode Itlb multihit: KVM: Mitigation: VMX disabled L1tf: Not affected @@ -329,4 +329,3 @@ Vulnerability Spectre v2: Mitigation; Enhanced IBRS, IBPB conditional, Vulnerability Srbds: Mitigation; Microcode Vulnerability Tsx async abort: Not affected ``` - diff --git a/doc/authentication.md b/doc/authentication.md index 931b7e5..20bd44e 100644 --- a/doc/authentication.md +++ b/doc/authentication.md @@ -24,7 +24,7 @@ The `zap.BasicAuth` Authenticator accepts 2 comptime values: - `Lookup`: either a map to look up passwords for users or a set to lookup base64 encoded tokens (user:pass -> base64-encode = token) -- `kind` : +- `kind` : - `UserPass` : decode the authentication header, split into user and password, then lookup the password in the provided map and compare it. - `Token68` : don't bother decoding, the 'lookup' set is filled with @@ -122,7 +122,7 @@ var map = Map.init(allocator); defer map.deinit(); // create user / pass entry -const user = "Alladdin"; +const user = "Aladdin"; const pass = "opensesame"; try map.put(user, pass); @@ -253,7 +253,7 @@ pub fn main() !void { listener.listen() catch {}; std.debug.print( \\ Run the following: - \\ + \\ \\ curl http://localhost:3000/test -i -H "Authorization: Bearer ABCDEFG" -v \\ curl http://localhost:3000/test -i -H "Authorization: Bearer invalid" -v \\ @@ -268,5 +268,3 @@ pub fn main() !void { }); } ``` - - diff --git a/doc/build-localhost.md b/doc/build-localhost.md index 8725fde..8002a93 100644 --- a/doc/build-localhost.md +++ b/doc/build-localhost.md @@ -3,7 +3,7 @@ Recently, GitHub started hosting release archives on a dedicated host codeload.github.com. This is when the problems started. Back then, zig's package manager was not expecting to be re-directed to a different URL. On top of that, -GitHub changed the redirected-to URLs so they wouldn't end in `.tar.gz` anymore. +GitHub changed the redirected-to URLs so they wouldn't end in `.tar.gz` anymore. Above issues were fixed but after some progress on `zig.http` related standard library stuff, a similar error started impacting the package manager: parsing @@ -51,7 +51,7 @@ $ wget https://github.com/zigzap/facil.io/archive/refs/tags/zap-0.0.8.tar.gz $ # get zap itself $ wget https://github.com/zigzap/zap/archive/refs/tags/release-0.0.20-localhost.tar.gz $ # start a http server on port 8000 -$ python -m http.server +$ python -m http.server ``` ... and use the following in your build.zig.zon: @@ -85,7 +85,7 @@ hashes, as well as a `MY_TAG.tar.gz`. You can then host this via python HTTP server and proceed as if you had downloaded it from github. -If all goes well, your dependend code should be able to use your freshly-built +If all goes well, your dependent code should be able to use your freshly-built zap release, depending on it via localhost URL in its `build.zig.zon`. If not, fix bugs, rinse, and repeat. @@ -97,5 +97,3 @@ with the non-localhost version from the master branch. Commit it, make sure your worktree is clean, and perform above steps again. This time, using a tag that doesn't contain `localhost`. You can then push to your fork and create a release for the future when zig's bug is fixed. - - diff --git a/doc/other-versions.md b/doc/other-versions.md index c8c1005..f4b01f8 100644 --- a/doc/other-versions.md +++ b/doc/other-versions.md @@ -28,7 +28,7 @@ the `.hash` value in `build.zig.zon`. ## Using an arbitrary (last) commit -Use the same workflow as above for tags, excpept for the URL, use this schema: +Use the same workflow as above for tags, except for the URL, use this schema: ```zig .url = "https://github.com/zigzap/zap/archive/[COMMIT-HASH].tar.gz", @@ -36,5 +36,3 @@ Use the same workflow as above for tags, excpept for the URL, use this schema: Replace `[COMMIT-HASH]` with the full commit hash as provided, e.g. by `git log`. - - diff --git a/doc/release-template.md b/doc/release-template.md index e41db51..6df98f9 100644 --- a/doc/release-template.md +++ b/doc/release-template.md @@ -31,7 +31,7 @@ Here is a complete `build.zig.zon` example: Then, in your `build.zig`'s `build` function, add the following before `b.installArtifact(exe)`: -```zig +```zig const zap = b.dependency("zap", .{ .target = target, .optimize = optimize, diff --git a/doc/why-no-errors.md b/doc/why-no-errors.md index db80377..f5aac84 100644 --- a/doc/why-no-errors.md +++ b/doc/why-no-errors.md @@ -13,7 +13,7 @@ that points you directly to where the exception happened, plus a stack-trace. Wouldn't that be handy? Wouldn't that be a good idea to also make ZAP behave that way? -My argument is: NO. Not unconditionally like this. +My argument is: NO. Not unconditionally like this. Let me elaborate: First, ZAP the library cannot know what YOU want to do in case of an error. If some `on_request()` returns an error, ZAP would only be able to @@ -64,7 +64,7 @@ fn on_request_with_errors(r: zap.SimpleHttpRequest) !void { ``` ```zig -// THIS IS WHAT YOU PASS TO THE LISTENER / ENDPONT / ... +// THIS IS WHAT YOU PASS TO THE LISTENER / ENDPOINT / ... fn on_request(r: zap.SimpleHttpRequest) void { on_request_with_errors(r) catch |err| { // log the error or use: @@ -84,5 +84,3 @@ To better support the use-case of flask-like error returning, we will "soon": - only in debug builds would it return the stack traces and in release builds it would return more generic 50x responses. - - diff --git a/doc/zig-ception.md b/doc/zig-ception.md index 4d70551..9a12541 100644 --- a/doc/zig-ception.md +++ b/doc/zig-ception.md @@ -93,6 +93,6 @@ const UserMiddleWare = struct { ## 🤯 -The comments in the code say it all. +The comments in the code say it all. **Isn't ZIG AMAZING?** diff --git a/examples/bindataformpost/bindataformpost.zig b/examples/bindataformpost/bindataformpost.zig index 1a60849..73ddb71 100644 --- a/examples/bindataformpost/bindataformpost.zig +++ b/examples/bindataformpost/bindataformpost.zig @@ -92,16 +92,14 @@ pub fn main() !void { Handler.alloc = allocator; // setup listener - var listener = zap.SimpleHttpListener.init( - .{ - .port = 3000, - .on_request = Handler.on_request, - .log = true, - .max_clients = 10, - .max_body_size = 10 * 1024 * 1024, - .public_folder = ".", - }, - ); + var listener = zap.SimpleHttpListener.init(.{ + .port = 3000, + .on_request = Handler.on_request, + .log = true, + .max_clients = 10, + .max_body_size = 10 * 1024 * 1024, + .public_folder = ".", + }); zap.enableDebugLog(); try listener.listen(); std.log.info("\n\nURL is http://localhost:3000\n", .{}); diff --git a/examples/cookies/cookies.zig b/examples/cookies/cookies.zig index 67ab034..26e18f3 100644 --- a/examples/cookies/cookies.zig +++ b/examples/cookies/cookies.zig @@ -98,15 +98,13 @@ pub fn main() !void { Handler.alloc = allocator; // setup listener - var listener = zap.SimpleHttpListener.init( - .{ - .port = 3000, - .on_request = Handler.on_request, - .log = false, - .max_clients = 10, - .max_body_size = 1 * 1024, - }, - ); + var listener = zap.SimpleHttpListener.init(.{ + .port = 3000, + .on_request = Handler.on_request, + .log = false, + .max_clients = 10, + .max_body_size = 1 * 1024, + }); zap.enableDebugLog(); try listener.listen(); std.log.info("\n\nTerminate with CTRL+C", .{}); diff --git a/examples/endpoint/endpoint.zig b/examples/endpoint/endpoint.zig index ac4b408..75cde2c 100644 --- a/examples/endpoint/endpoint.zig +++ b/examples/endpoint/endpoint.zig @@ -92,7 +92,6 @@ fn postUser(e: *zap.SimpleEndpoint, r: zap.SimpleRequest) void { } } else |err| { std.debug.print("ADDING error: {}\n", .{err}); - return; } } } diff --git a/examples/endpoint/html/index.html b/examples/endpoint/html/index.html index 9f21038..4b2aa8b 100644 --- a/examples/endpoint/html/index.html +++ b/examples/endpoint/html/index.html @@ -1,23 +1,59 @@ + ZAP Demo - + +
-
+

@@ -94,7 +138,7 @@
-
+
@@ -113,149 +157,150 @@
- + function init() { + getUserList(); + } + init(); + + diff --git a/examples/endpoint_auth/endpoint_auth.zig b/examples/endpoint_auth/endpoint_auth.zig index b6056c1..0f4acfd 100644 --- a/examples/endpoint_auth/endpoint_auth.zig +++ b/examples/endpoint_auth/endpoint_auth.zig @@ -58,7 +58,7 @@ pub fn main() !void { listener.listen() catch {}; std.debug.print( \\ Run the following: - \\ + \\ \\ curl http://localhost:3000/test -i -H "Authorization: Bearer ABCDEFG" -v \\ curl http://localhost:3000/test -i -H "Authorization: Bearer invalid" -v \\ diff --git a/examples/hello_json/hello_json.zig b/examples/hello_json/hello_json.zig index b477230..15de756 100644 --- a/examples/hello_json/hello_json.zig +++ b/examples/hello_json/hello_json.zig @@ -52,7 +52,7 @@ pub fn main() !void { std.debug.print( \\ Listening on 0.0.0.0:3000 - \\ + \\ \\ Check out: \\ http://localhost:3000/user/1 # -- first user \\ http://localhost:3000/user/2 # -- second user diff --git a/examples/http_params/http_params.zig b/examples/http_params/http_params.zig index 1bb739d..73b0ffb 100644 --- a/examples/http_params/http_params.zig +++ b/examples/http_params/http_params.zig @@ -98,15 +98,13 @@ pub fn main() !void { Handler.alloc = allocator; // setup listener - var listener = zap.SimpleHttpListener.init( - .{ - .port = 3000, - .on_request = Handler.on_request, - .log = false, - .max_clients = 10, - .max_body_size = 1 * 1024, - }, - ); + var listener = zap.SimpleHttpListener.init(.{ + .port = 3000, + .on_request = Handler.on_request, + .log = false, + .max_clients = 10, + .max_body_size = 1 * 1024, + }); zap.enableDebugLog(); try listener.listen(); std.log.info("\n\nTerminate with CTRL+C or by sending query param terminate=true\n", .{}); diff --git a/examples/middleware_with_endpoint/middleware_with_endpoint.zig b/examples/middleware_with_endpoint/middleware_with_endpoint.zig index f22397f..bb00e7b 100644 --- a/examples/middleware_with_endpoint/middleware_with_endpoint.zig +++ b/examples/middleware_with_endpoint/middleware_with_endpoint.zig @@ -191,7 +191,6 @@ const HtmlEndpoint = struct { r.setContentType(.TEXT) catch unreachable; r.sendBody(message) catch unreachable; - return; } }; diff --git a/examples/sendfile/sendfile.zig b/examples/sendfile/sendfile.zig index daf16dd..ad3bee1 100644 --- a/examples/sendfile/sendfile.zig +++ b/examples/sendfile/sendfile.zig @@ -27,15 +27,13 @@ pub fn on_request(r: zap.SimpleRequest) void { pub fn main() !void { // setup listener - var listener = zap.SimpleHttpListener.init( - .{ - .port = 3000, - .on_request = on_request, - .log = true, - .max_clients = 10, - .max_body_size = 1 * 1024, // careful here - }, - ); + var listener = zap.SimpleHttpListener.init(.{ + .port = 3000, + .on_request = on_request, + .log = true, + .max_clients = 10, + .max_body_size = 1 * 1024, // careful here + }); zap.enableDebugLog(); try listener.listen(); diff --git a/examples/userpass_session_auth/html/login.html b/examples/userpass_session_auth/html/login.html index 7bc6b6a..cc10389 100644 --- a/examples/userpass_session_auth/html/login.html +++ b/examples/userpass_session_auth/html/login.html @@ -1,90 +1,94 @@ - - - - -
-
- Avatar -
- -
- - - - - - - -
-
- + /* Change styles for span and cancel button on extra small screens */ + @media screen and (max-width: 300px) { + span.psw { + display: block; + float: none; + } + + .cancelbtn { + width: 100%; + } + } + + + + +
+
+ Avatar +
+ +
+ + + + + + + +
+
+ + - diff --git a/examples/websockets/frontend/index.html b/examples/websockets/frontend/index.html index 4b643bb..06fabee 100644 --- a/examples/websockets/frontend/index.html +++ b/examples/websockets/frontend/index.html @@ -1,183 +1,192 @@ - - - - - ZAP-Chat - + .user { + align-self: flex-end; + background-color: #cd0f0d; + ; + color: white; + } + + .busy-indicator { + display: inline-block; + width: 20px; + height: 20px; + border: 3px solid rgba(255, 255, 255, 0.3); + border-radius: 50%; + border-top-color: #ffffff; + animation: spin 1s linear infinite; + } + + @keyframes spin { + 0% { + transform: rotate(0deg); + } + + 100% { + transform: rotate(360deg); + } + } + + .input-container { + display: flex; + justify-content: space-between; + position: fixed; + bottom: 0px; + left: 0; + right: 0; + background-color: #f0f0f0; + padding-left: 1rem; + padding-right: 1rem; + padding-bottom: 0.8rem; + padding-top: 1rem; + max-width: 960px; + margin-left: auto; + margin-right: auto; + /* box-shadow: 0 -2px 4px rgba(0, 0, 0, 0.1); */ + } + + .input-container input { + flex-grow: 1; + padding: 1rem; + border-radius: 10px; + border: 2px solid #cd0f0d; + outline: none; + /* font-size: 1.2rem; */ + } + + .input-container button { + background-color: #cd0f0d; + ; + color: white; + border: none; + border-radius: 10px; + padding: 1rem 2rem; + cursor: pointer; + margin-left: 1rem; + outline: none; + transition: 0.3s; + } + + .input-container button:hover { + background-color: #A20000; + } + + .status-bar { + background-color: #8B0000; + color: white; + text-align: center; + padding: 0.5rem; + font-size: 0.9rem; + position: fixed; + /* bottom: 60px; */ + left: 0; + right: 0; + max-width: 960px; + margin-left: auto; + margin-right: auto; + /* border-top-left-radius: 10px; */ + /* border-top-right-radius: 10px; */ + border-bottom-left-radius: 10px; + border-bottom-right-radius: 10px; + box-shadow: 0 -2px 4px rgba(0, 0, 0, 0.1); + } + + .status-online { + /* Green, MediumSeaGreen */ + background-color: #3CB371; + } + + .status-busy { + /* Blue, DodgerBlue */ + background-color: #1E90FF; + } + + .status-thinking { + /* Light Gray, LightSlateGray */ + background-color: #778899; + } + + .status-offline { + /* Red, Tomato */ + background-color: #FF6347; + } + + .status-warning { + /* Yellow, Goldenrod */ + background-color: #DAA520; + } + + .status-error { + /* Dark-Red, Firebrick */ + background-color: #B22222; + } + +
@@ -207,4 +216,5 @@ document.head.appendChild(scriptTag); + diff --git a/introducing.md b/introducing.md index 2d951cb..d77ed53 100644 --- a/introducing.md +++ b/introducing.md @@ -21,31 +21,31 @@ Here's what works: - **Super easy build process**: zap's `build.zig` fetches facilio's git sub-module, applies a patch to its logging for microsecond precision, and then builds and optionally runs everything. - _tested on Linux and macOS (arm, M1)_ - **[hello](https://github.com/renerocksai/zap/blob/master/examples/hello/hello.zig)**: welcomes you with some static HTML -- **[routes](https://github.com/renerocksai/zap/blob/master/examples/routes/routes.zig)**: a super easy example dispatching on the HTTP path +- **[routes](https://github.com/renerocksai/zap/blob/master/examples/routes/routes.zig)**: a super easy example dispatching on the HTTP path - **[serve](https://github.com/renerocksai/zap/blob/master/examples/serve/serve.zig)**: the traditional static web server with optional dynamic request handling - **[hello_json](https://github.com/renerocksai/zap/blob/master/examples/hello_json/hello_json.zig)**: serves you json dependent on HTTP path - **[endpoint](https://github.com/renerocksai/zap/blob/master/examples/endpoint/)**: a simple JSON REST API example featuring a `/users` endpoint for PUTting/DELETE-ing/GET-ting/POST-ing and listing users, together with a static HTML and JavaScript frontend to play with. -If you want to take it for a quick spin: +If you want to take it for a quick spin: ```shell -$ git clone https://github.com/renerocksai/zap.git -$ cd zap -$ zig build run-hello -$ # open http://localhost:3000 in your browser +$ git clone https://github.com/renerocksai/zap.git +$ cd zap +$ zig build run-hello +$ # open http://localhost:3000 in your browser ``` See [the README](https://github.com/renerocksai/zap) for how easy it is to get started, how to run the examples, and how to use zap in your own projects. I'll continue wrapping more of facil.io's functionality and adding stuff to zap to a point where I can use it as the JSON REST API backend for real research projects, serving thousands of concurrent clients. Now that the endpoint example works, ZAP has actually become pretty usable to me. -**Side-note:** It never ceases to amaze me how productive I can be in zig, eventhough I am still considering myself to be a newbie. Sometimes, it's almost like writing python but with all the nice speed and guarantees that zig gives you. Also, the C integration abilities of zig are just phenomenal! I am super excited about zig's future! +**Side-note:** It never ceases to amaze me how productive I can be in zig, even though I am still considering myself to be a newbie. Sometimes, it's almost like writing python but with all the nice speed and guarantees that zig gives you. Also, the C integration abilities of zig are just phenomenal! I am super excited about zig's future! Now, on to the guiding principles of Zap. ## robust -A common recommendation for doing web stuff in zig is to write the actual HTTP server in Go, and use zig for the real work. While there is a selection of notable and cool HTTP server implementations written in zig out there, at the time of writing, most of them seem to a) depend on zig's async facilities which are unsupported until ca. April 2023 when async will return to the self-hosted compiler, and b) have not matured to a point where **I** feel safe using them in production. These are just my opionions and they could be totally wrong though. +A common recommendation for doing web stuff in zig is to write the actual HTTP server in Go, and use zig for the real work. While there is a selection of notable and cool HTTP server implementations written in zig out there, at the time of writing, most of them seem to a) depend on zig's async facilities which are unsupported until ca. April 2023 when async will return to the self-hosted compiler, and b) have not matured to a point where **I** feel safe using them in production. These are just my opinions and they could be totally wrong though. However, when I conduct my next online research experiment with thousands of concurrent clients, I cannot afford to run into potential maturity-problems of the HTTP server. These projects typically feature a you-get-one-shot process with little room for errors or re-tries. @@ -75,7 +75,7 @@ So, being somewhere in the ballpark of basic GO performance, zig zap seems to be See more details in [blazingly-fast.md](https://github.com/renerocksai/zap/blob/master/blazingly-fast.md). -## minimal +## minimal Zap is minimal by necessity. I only (have time to) add what I need - for serving REST APIs and HTML. The primary use-case are frontends that I wrote that communicate with my APIs. Hence, the focus is more on getting stuff done rather than conforming to every standard there is. Even though facilio is able to support TLS, I don't care about that - at least for now. Also, if you present `404 - File not found` as human-readable HTML to the user, nobody forces you to also set the status code to 404, so it can be OK to spare those nanoseconds. Gotta go fast! @@ -91,10 +91,10 @@ I am super excited about both zig and zap's future. I am still impressed by how Provided that the incorporated C code is well-written and -tested, WYSIWYG even holds mostly true for combined Zig and C projects. -You can truly build on the soulders of giants here. Mind you, it took me less than a week to arrive at the current state of zap where I am confident that I can already use it to write the one or other REST API with it and, after stress-testing, just move it into production - from merely researching Zig and C web frameworks a few days ago. +You can truly build on the shoulders of giants here. Mind you, it took me less than a week to arrive at the current state of zap where I am confident that I can already use it to write the one or other REST API with it and, after stress-testing, just move it into production - from merely researching Zig and C web frameworks a few days ago. Oh, and have I mentioned Zig's built-in build system and testing framework? Those are both super amazing and super convenient. `zig build` is so much more useful than `make` (which I quite like to be honest). And `zig test` is just amazing, too. Zig's physical code layout: which file is located where and how can it be built, imported, tested - it all makes so much sense. Such a coherent, pleasant experience. -Looking forward, I am also tempted to try adding some log-and-replay facilities as a kind of backup for when things go wrong. I wouldn't be confident to attemt such things in C because I'd view them as being too much work; too much could go wrong. But with Zig, I am rather excited about the possibilities that open up and eager to try such things. +Looking forward, I am also tempted to try adding some log-and-replay facilities as a kind of backup for when things go wrong. I wouldn't be confident to attempt such things in C because I'd view them as being too much work; too much could go wrong. But with Zig, I am rather excited about the possibilities that open up and eager to try such things. For great justice! diff --git a/src/http_auth.zig b/src/http_auth.zig index c883ef7..412b38a 100644 --- a/src/http_auth.zig +++ b/src/http_auth.zig @@ -156,7 +156,7 @@ pub fn BasicAuth(comptime Lookup: type, comptime kind: BasicAuthStrategy) type { } else |err| { // can't calc slice size --> fallthrough to return false zap.debug( - "ERROR: UserPassAuth: cannot calc slize size for encoded `{s}`: {any} \n", + "ERROR: UserPassAuth: cannot calc slice size for encoded `{s}`: {any} \n", .{ encoded, err }, ); return .AuthFailed; diff --git a/src/middleware.zig b/src/middleware.zig index b435701..027f6c4 100644 --- a/src/middleware.zig +++ b/src/middleware.zig @@ -80,7 +80,7 @@ pub fn Handler(comptime ContextType: anytype) type { }; } -/// A convenience handler for artibrary zap.SimpleEndpoint +/// A convenience handler for arbitrary zap.SimpleEndpoint pub fn EndpointHandler(comptime HandlerType: anytype, comptime ContextType: anytype) type { return struct { handler: HandlerType, diff --git a/src/tests/test_auth.zig b/src/tests/test_auth.zig index 2b5e246..a7d65b0 100644 --- a/src/tests/test_auth.zig +++ b/src/tests/test_auth.zig @@ -74,7 +74,7 @@ test "BasicAuth UserPass" { defer map.deinit(); // create user / pass entry - const user = "Alladdin"; + const user = "Aladdin"; const pass = "opensesame"; try map.put(user, pass); @@ -521,7 +521,7 @@ test "BasicAuth UserPass authenticateRequest" { defer map.deinit(); // create user / pass entry - const user = "Alladdin"; + const user = "Aladdin"; const pass = "opensesame"; try map.put(user, pass); @@ -587,7 +587,7 @@ test "BasicAuth UserPass authenticateRequest test-unauthorized" { defer map.deinit(); // create user / pass entry - const user = "Alladdin"; + const user = "Aladdin"; const pass = "opensesame"; try map.put(user, pass);