Documentation
¶
Overview ¶
Package detect classifies a fetched page as usable, blocked, a captcha or challenge, or suspiciously empty.
The generic detectors here look at the status code, at markers common to the big bot-protection vendors, and at body size. They are heuristics: they will miss a site's own block page, and that is what custom Detectors are for. A consumer chains its site-specific detectors in front of Default().
Index ¶
Constants ¶
const DefaultMinBody = 256
DefaultMinBody is the body size, in bytes after trimming whitespace, below which ShortBody calls a successful HTML page Empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Chain ¶
type Chain []Detector
Chain runs detectors in order and returns the first outcome that is not OK. An empty chain returns OK.
type Detector ¶
Detector classifies a page.
func Default ¶
func Default() Detector
Default is the generic chain: challenge markers first, so a 403 that carries a captcha reads as a captcha, then status codes, then a short body.
func MarkersFrom ¶
MarkersFrom returns a detector that looks for the given markers. Captcha markers are checked before block markers.
type MarkerSet ¶
type MarkerSet struct {
CaptchaTitles []string
BlockTitles []string
CaptchaTokens []string
BlockTokens []string
// SmallPage is the visible-text length, in bytes, under which body
// tokens are trusted on a 2xx page.
SmallPage int
}
MarkerSet is the vocabulary Markers looks for. Every string is matched case-insensitively.
Title phrases are decisive: a page titled "Just a moment..." is a challenge whatever else it holds. Body tokens are not, because the same scripts and widgets appear on ordinary pages (a reCAPTCHA on a login form, Cloudflare's bot-management script on every page it fronts); they count only when the page is also an error or carries little visible text.
func DefaultMarkers ¶
func DefaultMarkers() MarkerSet
DefaultMarkers covers Cloudflare, Akamai, Imperva/Incapsula, DataDome, PerimeterX/HUMAN, reCAPTCHA, hCaptcha and Turnstile.