Handle empty path

This commit is contained in:
Romain de Laage 2021-03-02 14:10:58 +01:00
parent e173f4d002
commit 49c7ad61df
Signed by: rdelaage
GPG Key ID: 534845FADDF0C329
1 changed files with 3 additions and 6 deletions

View File

@ -156,11 +156,8 @@ func handleConn(conn *tls.Conn, baseURL, title, home_message string) {
return return
} }
// skip first '/'
path = path[1:]
// home // home
if path == "" { if path == "" || path == "/" {
_, err = fmt.Fprintf(conn, "20 text/gemini\r\n# " + title + "\n\n" + home_message) _, err = fmt.Fprintf(conn, "20 text/gemini\r\n# " + title + "\n\n" + home_message)
if err != nil { if err != nil {
log.Println("send error: %s", err) log.Println("send error: %s", err)
@ -170,7 +167,7 @@ func handleConn(conn *tls.Conn, baseURL, title, home_message string) {
} }
// profile // profile
if strings.HasPrefix(path, "profile/") { if strings.HasPrefix(path, "/profile/") {
// skip prefix // skip prefix
path = path[8:] path = path[8:]
_, err = strconv.ParseUint(path, 10, 64) _, err = strconv.ParseUint(path, 10, 64)
@ -187,7 +184,7 @@ func handleConn(conn *tls.Conn, baseURL, title, home_message string) {
log.Println("Received request for account " + path) log.Println("Received request for account " + path)
printProfile(conn, baseURL, path) printProfile(conn, baseURL, path)
} /* thread */ else if strings.HasPrefix(path, "thread/") { } /* thread */ else if strings.HasPrefix(path, "/thread/") {
// skip prefix // skip prefix
path = path[7:] path = path[7:]