diff --git a/cmd/web/handlers.go b/cmd/web/handlers.go index 91199bc..5dc9566 100644 --- a/cmd/web/handlers.go +++ b/cmd/web/handlers.go @@ -83,8 +83,9 @@ func (app *application) siteEntryCreate(w http.ResponseWriter, r *http.Request) func (app *application) nextSiteEntry(w http.ResponseWriter, r *http.Request) { ref := app.cleanUrl(r.Referer()) - refSite, err := app.siteEntries.GetByUrl(ref) - app.infoLog.Printf("REFERER %s\n", ref) + cleanUrl := app.cleanUrl(ref) + app.infoLog.Printf("REFERER %s. CLEAN %s\n", ref, cleanUrl) + refSite, err := app.siteEntries.GetByUrl(cleanUrl) if err != nil { app.serverError(w, err) return @@ -102,7 +103,9 @@ func (app *application) nextSiteEntry(w http.ResponseWriter, r *http.Request) { func (app *application) prevSiteEntry(w http.ResponseWriter, r *http.Request) { ref := app.cleanUrl(r.Referer()) - refSite, err := app.siteEntries.GetByUrl(ref) + cleanUrl := app.cleanUrl(ref) + app.infoLog.Printf("REFERER %s. CLEAN %s\n", ref, cleanUrl) + refSite, err := app.siteEntries.GetByUrl(cleanUrl) if err != nil { app.serverError(w, err) return diff --git a/cmd/web/helpers.go b/cmd/web/helpers.go index 25d2b22..8d38d5f 100644 --- a/cmd/web/helpers.go +++ b/cmd/web/helpers.go @@ -25,10 +25,9 @@ func (app *application) notFound(w http.ResponseWriter) { } func (app *application) cleanUrl(url string) string { - s, _ := strings.CutPrefix(url, "http://") - s, _ = strings.CutPrefix(s, "https://") + s := strings.TrimPrefix(url, "http://") + s = strings.TrimPrefix(s, "https://") s = path.Base(path.Clean(s)) - s = "http://" + s return s }