-
Notifications
You must be signed in to change notification settings - Fork 1
Traffic Policy
TrafficPolicy lets different request classes use different network behavior.
It is one of the main engineering abstractions in steam-go.
| Class | Meaning |
|---|---|
TrafficClassOfficialAPI |
Normal typed Steam Web API traffic |
TrafficClassPublicStorePage |
Storefront web JSON or browser-like Store traffic |
TrafficClassCommunityWeb |
Steam Community inventory-style web JSON traffic |
TrafficClassMarketWeb |
Steam Community Market web JSON traffic |
Official API requests and public Store page requests should not always share the same strategy.
Official API traffic usually cares about:
- API key
- retry
- rate limit
- response decoding
- typed responses
Public Store page traffic may care about:
- browser-like headers
- cookies
- Referer
- block detection
- short cache
- lower concurrency
- proxy routing
Community or Market web JSON traffic may also care about:
- separate throttling from official API calls
- cookie jar reuse
- short cache for repeated reads
- block detection on
403,429, or challenge HTML
client, err := steam.NewClient(
steam.WithTrafficPolicy(
steam.TrafficClassPublicStorePage,
steam.TrafficPolicy{
RateLimiter: &steam.TrafficRateLimiterPolicy{
Limit: 10,
Burst: 10,
},
},
),
)profile := steam.DefaultPublicStoreHeaderProfileEN()
client, err := steam.NewClient(
steam.WithTrafficPolicy(
steam.TrafficClassPublicStorePage,
steam.TrafficPolicy{
HeaderProfile: &profile,
Cache: &steam.TrafficCachePolicy{
TTL: time.Minute,
},
BlockPolicy: &steam.TrafficBlockPolicy{
HTMLSniffBytes: 4096,
},
},
),
)ctx := steam.WithTrafficClass(
context.Background(),
steam.TrafficClassPublicStorePage,
)In normal usage, the built-in client.Web.* methods already choose their default traffic class automatically:
-
client.Web.Storefront.*->TrafficClassPublicStorePage -
client.Web.Community.*->TrafficClassCommunityWeb -
client.Web.Market.*->TrafficClassMarketWeb
TrafficPolicy can override:
- proxy selector
- cookie jar
- rate limiter
- retry policy
- host control
- session control
- short cache
- block detection
- header profile
- Referer selector
- transport hook
Use WithRequestObserver(...) when you need lightweight request metadata for logs or metrics without adding an OpenTelemetry dependency:
client, err := steam.NewClient(
steam.WithRequestObserver(steam.RequestObserverFunc(func(event steam.RequestEvent) {
_ = event.TrafficClass
_ = event.Path
_ = event.StatusCode
_ = event.Duration
})),
)Observer events are emitted after SDK requests complete. They include the traffic class, method, host, path without raw query, status code, error kind, retry attempts, cache hit, block detection, and duration. They do not include raw query strings, headers, bodies, API keys, tokens, cookies, or proxy passwords.
Keep traffic behavior close to the SDK boundary.
Avoid pushing rate limits, cookies, proxy decisions, and browser-like headers into business code.
____ ____ ____ _ _ ____ ____ _ _ / ____ ___ ____ ____ _ _ ____ ____
| __ | | |___ | | |__/ |__/ \_/ / [__ | |___ |__| |\/| __ | __ | |
|__] |__| | |__| | \ | \ | / ___] | |___ | | | | |__] |__|
- SteamID Model
- Steam Web API Notes
- Public Store Page Access Notes
- Partner API Notes
- OpenID Notes
- A2S Notes
- Steam Keys and Access Tokens
- Steam Static Assets
- Steam VDF and addons/vdf
- Steam Web API 特性说明
- 公开商店页面访问说明
- Partner API 说明
- OpenID 说明
- A2S 说明
- Steam Key 与 Access Token
- Steam 静态资源
- Steam VDF 与 addons/vdf