clean referer URLs

This commit is contained in:
yequari 2023-07-30 01:06:38 -07:00
parent 1160727b62
commit c09d870b40
2 changed files with 8 additions and 6 deletions

View File

@ -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

View File

@ -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
}