geziyor/middleware/duplicate_requests.go
Musab Gültekin 2cab68d2ce Middlewares refactored to multiple files in middleware package.
Extractors removed as they introduce complexity to scraper. Both in learning and developing.
2019-07-04 21:04:29 +03:00

22 lines
487 B
Go

package middleware
import (
"github.com/geziyor/geziyor/client"
"sync"
)
// DuplicateRequests checks for already visited URLs
type DuplicateRequests struct {
RevisitEnabled bool
visitedURLs sync.Map
}
func (a *DuplicateRequests) ProcessRequest(r *client.Request) {
if !a.RevisitEnabled && r.Request.Method == "GET" {
if _, visited := a.visitedURLs.LoadOrStore(r.Request.URL.String(), struct{}{}); visited {
//log.Printf("URL already visited %s\n")
r.Cancel()
}
}
}