Documentation
¶
Index ¶
- type Filter
- func (f *Filter) AddReader(listRules io.Reader, listName string, listTrusted bool) error
- func (f *Filter) AddURL(listURL string, listName string, listTrusted bool) error
- func (f *Filter) Finalize()
- func (f *Filter) HandleRequest(req *http.Request) (*http.Response, error)
- func (f *Filter) HandleResponse(req *http.Request, res *http.Response) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Filter ¶
type Filter struct {
// contains filtered or unexported fields
}
Filter is capable of parsing Adblock-style filter lists and hosts rules and matching URLs against them.
Safe for concurrent use.
func NewFilter ¶
func NewFilter(networkRules networkRules, injector documentInjector, filterListStore filterListStore, eventsEmitter filterEventsEmitter, whitelistSrv whitelistSrv) (*Filter, error)
NewFilter creates and initializes a new filter.
func (*Filter) AddReader ¶ added in v1.3.0
AddReader parses the rules from the given reader and adds them to the filter.
func (*Filter) AddURL ¶ added in v1.3.0
AddURL fetches a filter list from a URL, expands !#include directives, and adds rules to the filter.
func (*Filter) Finalize ¶ added in v1.2.1
func (f *Filter) Finalize()
Finalize optimizes internal data structures after all filter lists have been loaded. This method should be called once after all AddURL/AddReader calls are complete and before the filter starts handling requests. Calling Finalize is not required for correctness, but improves memory usage and lookup performance.
func (*Filter) HandleRequest ¶
HandleRequest handles the given request by matching it against the filter rules. If the request should be blocked, it returns a response that blocks the request. If the request should be modified, it modifies it in-place.
func (*Filter) HandleResponse ¶
HandleResponse handles the given response by matching it against the filter rules. If the response should be modified, it modifies it in-place.
As of April 2024, there are no response-only rules that can block or redirect responses. For that reason, this method does not return a blocking or redirecting response itself.