Documentation
¶
Index ¶
- type Filter
- func (f *Filter) AddRule(rule string, filterListName *string, filterListTrusted bool) (isException bool, err error)
- func (f *Filter) HandleRequest(req *http.Request) (*http.Response, error)
- func (f *Filter) HandleResponse(req *http.Request, res *http.Response) error
- func (f *Filter) ParseAndAddRules(reader io.Reader, filterListName *string, filterListTrusted bool) (ruleCount, exceptionCount int)
- type FilterList
- type FilterListType
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, scriptletsInjector scriptletsInjector, cosmeticRulesInjector cosmeticRulesInjector, cssRulesInjector cssRulesInjector, jsRuleInjector jsRuleInjector, extendedCSSInjector extendedCSSInjector, eventsEmitter filterEventsEmitter, filterListStore filterListStore, whitelistSrv whitelistSrv, filterLists []FilterList, myRules []string) (*Filter, error)
NewFilter creates and initializes a new filter.
func (*Filter) AddRule ¶
func (f *Filter) AddRule(rule string, filterListName *string, filterListTrusted bool) (isException bool, err error)
AddRule adds a new rule to the filter. It returns true if the rule is an exception, false otherwise.
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.
type FilterList ¶
type FilterList struct {
Name string `json:"name"`
Type FilterListType `json:"type"`
URL string `json:"url"`
Enabled bool `json:"enabled"`
Trusted bool `json:"trusted"`
Locales []string `json:"locales"`
}
func (*FilterList) UnmarshalJSON ¶
func (f *FilterList) UnmarshalJSON(data []byte) error
type FilterListType ¶
type FilterListType string
const (
FilterListTypeCustom FilterListType = "custom"
)