~sfr/artemis

f7bfaea2ddee3621b0dfe70966c0f6ceb3da71f3 — Sol Fisher Romanoff 4 months ago 26953fa master
Fix bug with relative addresses

hidden index files without trailing slashes would get overridden when clicking a
relative link. artemis now adds a trailing slash to every directory index.

Fixes: https://todo.sr.ht/~sfr/artemis/2
1 files changed, 6 insertions(+), 5 deletions(-)

M main.go
M main.go => main.go +6 -5
@@ 106,11 106,6 @@ func route(conn io.ReadWriteCloser) {
			[]byte("/home/$1/"+config.UserDir+"$2")))
	} else {
		path = config.IndexDir + address.Path

		// remove trailing slash
		if strings.HasSuffix(path, "/") {
			path = path[:len(path)-1]
		}
	}

	// add index.gmi if path not found and index exists


@@ 121,6 116,12 @@ func route(conn io.ReadWriteCloser) {
			sendResponseHeader(conn, 20, "text/plain")
		}
	} else if exists(path + "/index.gmi") {
		// request trailing slash
		if !strings.HasSuffix(path, "/") {
			log.Println("directory index found, requesting trailing slash")
			sendResponseHeader(conn, 31, address.Path+"/")
			return
		}
		path += "/index.gmi"
		sendResponseHeader(conn, 20, "text/gemini; lang=en; charset=utf-8")
	} else {