go-shrt

Shortlinks and go-get redirects
git clone git://git.danielmoch.com/go-shrt.git
Log | Files | Refs | README | LICENSE

commit b350c5923b76b1f73ac5d5d4876e8cb7f0b86d8f
parent 1f715a5201df649ce868a65e2f722aeb6028f0c5
Author: Daniel Moch <daniel@danielmoch.com>
Date:   Thu, 19 Nov 2020 03:01:49 +0000

Handle robots, bad request paths

Diffstat:
Mmain.go | 16++++++++++++++++
1 file changed, 16 insertions(+), 0 deletions(-)

diff --git a/main.go b/main.go @@ -40,6 +40,13 @@ func handl(w http.ResponseWriter, req *http.Request) { key = key[1:] } + if strings.Contains(key, "/") { + log.Println("bad request: " + key) + w.WriteHeader(http.StatusForbidden) + w.Write([]byte("Request path not allowed\n")) + return + } + if key == "" && (*cfg)["barerdr"] != "" { log.Println("shortlink request for /") w.Header().Add("Location", (*cfg)["barerdr"]) @@ -48,6 +55,15 @@ func handl(w http.ResponseWriter, req *http.Request) { return } + if key == "robots.txt" { + log.Println("incoming robot") + resp := "# Welcome to Shrt\n" + resp += "User-Agent: *\n" + resp += "Disallow:\n" + w.Write([]byte(resp)) + return + } + if val, ok := (*shrt)[key]; ok { log.Println("shortlink request for", key) w.Header().Add("Location", val)