clean referer URLs
This commit is contained in:
parent
1160727b62
commit
c09d870b40
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue