╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ serve.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
595 if (std.mem.eql(u8, v, "2")) { 596 version = .v2; 597 } else if (std.mem.eql(u8, v, "1") and version != .v2) { 598 version = .v1; 599 } 600 } 601 } 602 return version; 603 } 604 605 fn findHeader(request: *std.http.Server.Request, name: []const u8) ?[]const u8 { 606 var it = request.iterateHeaders(); 607 while (it.next()) |header| { 608 if (std.ascii.eqlIgnoreCase(header.name, name)) return header.value; 609 } 610 return null; 611 } 612 613 fn writeSimpleResponse( 614 http_server: *std.http.Server, 615 code: u16, 616 message: []const u8, 617 content_type: []const u8, 618 body: []const u8, 619 ) !void { 620 try http_server.out.print( 621 "HTTP/1.1 {d} {s}\r\nContent-Type: {s}\r\nContent-Length: {d}\r\n\r\n{s}", 622 .{ code, message, content_type, body.len, body }, 623 ); 624 } 625 626 fn logError(err: *std.Io.Writer, comptime fmt: []const u8, args: anytype) void { 627 err.print(fmt, args) catch return; 628 err.flush() catch {}; 629 } 630