╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ serve_http.zig ───────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯
242 .run_service => std.mem.eql(u8, suffix, "/git-receive-pack"), 243 .get_info_refs => if (query) |q| 244 std.mem.startsWith(u8, q.percent_encoded, "service=git-receive-pack") 245 else 246 false, 247 }; 248 } 249 250 fn decodeAndValidateRepoPath(allocator: std.mem.Allocator, encoded: []const u8) ![]const u8 { 251 if (encoded.len == 0) return error.InvalidRepoPath; 252 253 const mutable = try allocator.dupe(u8, encoded); 254 errdefer allocator.free(mutable); 255 const decoded = std.Uri.percentDecodeInPlace(mutable); 256 257 var iter = std.Io.Dir.path.componentIterator(decoded); 258 while (iter.next()) |component| { 259 if (component.name.len == 0 or std.mem.eql(u8, component.name, ".") or std.mem.eql(u8, component.name, "..")) { 260 return error.InvalidRepoPath; 261 } 262 } 263 264 return try allocator.realloc(mutable, decoded.len); 265 } 266 267 fn normalizeMethod(method: std.http.Method) std.http.Method { 268 return if (method == .HEAD) .GET else method; 269 } 270 271 fn findHeader(request: *std.http.Server.Request, name: []const u8) ?[]const u8 { 272 var it = request.iterateHeaders(); 273 while (it.next()) |header| { 274 if (std.ascii.eqlIgnoreCase(header.name, name)) return header.value; 275 } 276 return null; 277 } 278 279 fn writeSimpleResponse( 280 http_server: *std.http.Server, 281 code: u16, 282 message: []const u8, 283 content_type: []const u8, 284 body: []const u8, 285 ) !void { 286 try http_server.out.print( 287 "HTTP/1.1 {d} {s}\r\nContent-Type: {s}\r\nContent-Length: {d}\r\n\r\n{s}", 288 .{ code, message, content_type, body.len, body }, 289 ); 290 } 291