]> gitweb.ps.run Git - zighttp/blobdiff - src/http.zig
add debug output
[zighttp] / src / http.zig
index 2c47d1df0d8ec6d43afefd609395357341b3299c..bc8f3b1b9a8bc0e6b065c0f17382922e8e4db9c5 100644 (file)
@@ -59,6 +59,10 @@ pub const Server = struct {
                 errdefer posix.close(client_socket);
                 var event = linux.epoll_event{ .events = linux.EPOLL.IN, .data = .{ .fd = client_socket } };
                 try posix.epoll_ctl(self.efd, linux.EPOLL.CTL_ADD, client_socket, &event);
+                var addr: std.c.sockaddr = undefined;
+                var addr_size: std.c.socklen_t = @sizeOf(std.c.sockaddr);
+                _ = std.c.getpeername(client_socket, &addr, &addr_size);
+                std.debug.print("new connection from {}\n", .{addr});
             } else {
                 var closed = false;
                 var req = Request{ .fd = ready_socket };
@@ -109,6 +113,7 @@ pub const Request = struct {
     body: ?[]u8 = null,
 
     pub fn parse(self: *Request, buf: []u8) bool {
+        std.debug.print("buf: {s}\n", .{buf});
         var state: u8 = 0;
 
         var start: u32 = 0;
@@ -260,7 +265,7 @@ pub const Request = struct {
         }
     }
 
-    pub fn get_value(self: *Request, name: []const u8) ?[]const u8 {
+    pub fn get_value(self: Request, name: []const u8) ?[]const u8 {
         const body = self.body orelse return null;
         const name_index = std.mem.indexOf(u8, body, name) orelse return null;
         const eql_index = std.mem.indexOfScalarPos(u8, body, name_index, '=') orelse return null;