Middlewares refactored to multiple files in middleware package.
Extractors removed as they introduce complexity to scraper. Both in learning and developing.
This commit is contained in:
19
middleware/allowed_domains.go
Normal file
19
middleware/allowed_domains.go
Normal file
@ -0,0 +1,19 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"github.com/geziyor/geziyor/client"
|
||||
"github.com/geziyor/geziyor/internal"
|
||||
)
|
||||
|
||||
// AllowedDomains checks for request host if it exists in AllowedDomains
|
||||
type AllowedDomains struct {
|
||||
AllowedDomains []string
|
||||
}
|
||||
|
||||
func (a *AllowedDomains) ProcessRequest(r *client.Request) {
|
||||
if len(a.AllowedDomains) != 0 && !internal.Contains(a.AllowedDomains, r.Host) {
|
||||
//log.Printf("Domain not allowed: %s\n", req.Host)
|
||||
r.Cancel()
|
||||
return
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user