Check isWritable first so you can't reroute writable domains

This commit is contained in:
Ian Gulliver
2024-12-03 13:15:36 -08:00
parent 1e9cc7516f
commit e6386966a3

View File

@@ -72,6 +72,11 @@ func (sl *ShortLinks) ServeHTTP(w http.ResponseWriter, r *http.Request) {
func (sl *ShortLinks) serveRoot(w http.ResponseWriter, r *http.Request) { func (sl *ShortLinks) serveRoot(w http.ResponseWriter, r *http.Request) {
log.Printf("%s %s %s %s %s", r.RemoteAddr, r.Method, r.Host, sl.getDomain(r.Host), r.URL) log.Printf("%s %s %s %s %s", r.RemoteAddr, r.Method, r.Host, sl.getDomain(r.Host), r.URL)
if sl.isWritable(r.Host) {
sl.serveRootWithPath(w, r, "")
return
}
parts := strings.SplitN(r.Host, ".", 2) parts := strings.SplitN(r.Host, ".", 2)
if len(parts) != 2 { if len(parts) != 2 {
sl.serveRootWithPath(w, r, "") sl.serveRootWithPath(w, r, "")