From f2298e3d923d974625ea187f615be3a3ea8f243b Mon Sep 17 00:00:00 2001
From: Runxi Yu <me@runxiyu.org>
Date: Sat, 15 Feb 2025 09:59:57 +0800
Subject: [PATCH] http_server.go: Redirect tree to tree/, same for raw

---
 http_server.go | 8 ++++++++

diff --git a/http_server.go b/http_server.go
index 355ac9cb719cad4f74372280dd5d3971bd02a23d..346ace33f7cb033dd761212a0dd87f6f21eae28c 100644
--- a/http_server.go
+++ b/http_server.go
@@ -137,9 +137,17 @@ 			case "info":
 				handle_repo_info(w, r, params)
 			case "tree":
 				params["rest"] = strings.Join(segments[separator_index+4:], "/")
+				if len(segments) < separator_index+5 {
+					http.Redirect(w, r, r.URL.Path+"/", http.StatusSeeOther)
+					return
+				}
 				handle_repo_tree(w, r, params)
 			case "raw":
 				params["rest"] = strings.Join(segments[separator_index+4:], "/")
+				if len(segments) < separator_index+5 {
+					http.Redirect(w, r, r.URL.Path+"/", http.StatusSeeOther)
+					return
+				}
 				handle_repo_raw(w, r, params)
 			case "log":
 				if non_empty_last_segments_len > separator_index+4 {

-- 
2.48.1