cgifun

A basic example of CGI + Caddy web server
Log | Files | Refs | README

main.zig (717B)


      1 const std = @import("std");
      2 
      3 /// Produces an HTML page listing the environment variables.
      4 pub fn main() !void {
      5     const stdout = std.io.getStdOut().writer();
      6     //
      7     try stdout.writeAll("Content-Type: text/html\r\n");
      8     try stdout.writeAll("\r\n");
      9     try stdout.writeAll(
     10         \\<!doctype HTML>
     11         \\<html>
     12         \\<body>
     13         \\<p>Environment variables passed to CGI script:</p>
     14         \\<ul>
     15     );
     16     for (std.os.environ) |env| {
     17         try stdout.writeAll("<li>");
     18         const env_slice = std.mem.sliceTo(env, 0);
     19         try stdout.writeAll(env_slice);
     20         try stdout.writeAll("</li>\n");
     21     }
     22     try stdout.writeAll(
     23         \\</ul>
     24         \\</body>
     25         \\</html>
     26     );
     27 }