diff options
author | Runxi Yu <me@runxiyu.org> | 2025-02-11 12:43:36 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-02-11 12:43:36 +0800 |
commit | 0ef4deb35d59aa0df54dfbc886503ec2c14bfadd (patch) | |
tree | 12418820e3ceaef5a0274e579387bda11cf92b13 /handle_repo_raw.go | |
parent | repo_tree: Add link to raw (diff) | |
download | forge-0ef4deb35d59aa0df54dfbc886503ec2c14bfadd.tar.gz forge-0ef4deb35d59aa0df54dfbc886503ec2c14bfadd.tar.zst forge-0ef4deb35d59aa0df54dfbc886503ec2c14bfadd.zip |
repo_{raw,tree}: Redirect if visiting file but path_spec ends with slash
Diffstat (limited to 'handle_repo_raw.go')
-rw-r--r-- | handle_repo_raw.go | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/handle_repo_raw.go b/handle_repo_raw.go index 534ed4d..811fea8 100644 --- a/handle_repo_raw.go +++ b/handle_repo_raw.go @@ -48,6 +48,10 @@ func handle_repo_raw(w http.ResponseWriter, r *http.Request) { _, _ = w.Write([]byte("Error retrieving path: " + err.Error())) return } + if len(raw_path_spec) != 0 && raw_path_spec[len(raw_path_spec)-1] == '/' { + http.Redirect(w, r, "../" + path_spec, http.StatusSeeOther) + return + } file_contents, err := file.Contents() if err != nil { _, _ = w.Write([]byte("Error reading file: " + err.Error())) |