╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ serve.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
435 if (segment.len == 0 or std.mem.eql(u8, segment, ".") or std.mem.eql(u8, segment, "..")) { 436 return error.InvalidRepoPath; 437 } 438 } 439 440 return try allocator.realloc(mutable, decoded.len); 441 } 442 443 fn isSubPath(parent: []const u8, child: []const u8) bool { 444 if (std.mem.eql(u8, parent, std.fs.path.sep_str)) return std.fs.path.isAbsolute(child); 445 if (!std.mem.startsWith(u8, child, parent)) return false; 446 return child.len == parent.len or child[parent.len] == std.fs.path.sep; 447 } 448 449 fn normalizeMethod(method: std.http.Method) std.http.Method { 450 return if (method == .HEAD) .GET else method; 451 } 452 453 fn protocolVersionFromHeader(header: ?[]const u8) xit.net_server_common.ProtocolVersion { 454 const git_protocol = header orelse return .v0; 455 var version: xit.net_server_common.ProtocolVersion = .v0; 456 var iter = std.mem.splitScalar(u8, git_protocol, ':'); 457 while (iter.next()) |entry| { 458 const value = std.mem.trimStart(u8, entry, " "); 459 if (std.mem.startsWith(u8, value, "version=")) { 460 const v = value["version=".len..]; 461 if (std.mem.eql(u8, v, "2")) { 462 version = .v2; 463 } else if (std.mem.eql(u8, v, "1") and version != .v2) { 464 version = .v1; 465 } 466 } 467 } 468 return version; 469 } 470 471 fn findHeader(request: *std.http.Server.Request, name: []const u8) ?[]const u8 { 472 var it = request.iterateHeaders(); 473 while (it.next()) |header| { 474 if (std.ascii.eqlIgnoreCase(header.name, name)) return header.value; 475 } 476 return null; 477 } 478 479 fn writeSimpleResponse( 480 http_server: *std.http.Server, 481 code: u16, 482 message: []const u8, 483 content_type: []const u8, 484 body: []const u8, 485 ) !void { 486 try http_server.out.print( 487 "HTTP/1.1 {d} {s}\r\nContent-Type: {s}\r\nContent-Length: {d}\r\n\r\n{s}", 488 .{ code, message, content_type, body.len, body }, 489 ); 490 } 491