Documentation
¶
Overview ¶
Package trafficclass sorts each edge request into one class so analytics can tell page views from API calls, assets and bots. It is a pure function of the request and response headers: no state, no allocation on the hot path.
Index ¶
Constants ¶
const Count = int(Ignored)
Count is the number of user-visible classes (Ignored is not one of them).
const DefaultRulesMax = 50
DefaultRulesMax caps path rules per app when APP_TRAFFIC_RULES_MAX is unset.
const UnknownBot = "unknown automated"
UnknownBot labels an automated client that matched no named token.
Variables ¶
This section is empty.
Functions ¶
func IsPageView ¶
IsPageView reports whether a page-class request counts as a page view: a successful GET. Redirects and error documents are not views.
Types ¶
type Class ¶
type Class uint8
Class is the kind of request the edge saw. The zero value is Other.
type Response ¶
type Response struct {
Status int
ContentType string
// Shielded is true when the abuse shield already turned the request away.
Shielded bool
}
Response is what the classifier needs from the answer.
type Result ¶
type Result struct {
Class Class
// Soft is a client-side navigation (a Next.js RSC fetch), counted as a page view.
Soft bool
// Bot names the matched crawler token, or UnknownBot.
Bot string
// Rule is the 1-based index of the path rule that decided, 0 when none did.
Rule int
}
Result is the class plus the facts a caller may record next to it.
type Rule ¶
Rule maps a path glob to a class. Only page, api, asset and ignored are valid targets. In Pattern, "*" matches any run of characters including "/"; a pattern with no "*" matches exactly.
type Rules ¶
type Rules struct {
// contains filtered or unexported fields
}
Rules is an ordered, immutable list of path rules; the first match wins.
func DefaultRules ¶
func DefaultRules() *Rules
DefaultRules returns the built-in rules the spec ships; callers replace them per app.