code.gitea.io/gitea@v1.21.7/routers/web/misc/misc.go (about) 1 // Copyright 2023 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package misc 5 6 import ( 7 "net/http" 8 "path" 9 10 "code.gitea.io/gitea/modules/git" 11 "code.gitea.io/gitea/modules/httpcache" 12 "code.gitea.io/gitea/modules/log" 13 "code.gitea.io/gitea/modules/setting" 14 "code.gitea.io/gitea/modules/util" 15 ) 16 17 func SSHInfo(rw http.ResponseWriter, req *http.Request) { 18 if !git.SupportProcReceive { 19 rw.WriteHeader(http.StatusNotFound) 20 return 21 } 22 rw.Header().Set("content-type", "text/json;charset=UTF-8") 23 _, err := rw.Write([]byte(`{"type":"gitea","version":1}`)) 24 if err != nil { 25 log.Error("fail to write result: err: %v", err) 26 rw.WriteHeader(http.StatusInternalServerError) 27 return 28 } 29 rw.WriteHeader(http.StatusOK) 30 } 31 32 func DummyOK(w http.ResponseWriter, req *http.Request) { 33 w.WriteHeader(http.StatusOK) 34 } 35 36 func RobotsTxt(w http.ResponseWriter, req *http.Request) { 37 robotsTxt := util.FilePathJoinAbs(setting.CustomPath, "public/robots.txt") 38 if ok, _ := util.IsExist(robotsTxt); !ok { 39 robotsTxt = util.FilePathJoinAbs(setting.CustomPath, "robots.txt") // the legacy "robots.txt" 40 } 41 httpcache.SetCacheControlInHeader(w.Header(), setting.StaticCacheTime) 42 http.ServeFile(w, req, robotsTxt) 43 } 44 45 func StaticRedirect(target string) func(w http.ResponseWriter, req *http.Request) { 46 return func(w http.ResponseWriter, req *http.Request) { 47 http.Redirect(w, req, path.Join(setting.StaticURLPrefix, target), http.StatusMovedPermanently) 48 } 49 }