CProxyClient
HTTP client for controlling cproxy (reverse proxy cache) instances — switching origins, purging cached content, reading node config.
Talks to http://{node.Host}:{node.APIPort}/api/... on the target cproxy instance. Same shape as StreamerClient: stateless, takes the target node as a parameter, knows nothing about Fiber/Postgres/our response envelope.
Structure
pkg/CProxyClient/
├── client.go — PutOrigins, PutOriginURLs, PurgeContent, GetConfig
│ + private: doGet, doPut, doPatch, doDelete, readResponse
└── models.go — CProxyResponse{StatusCode, Body}
Who calls this
domain/distribution — owns the Cache DB record (host/port for each cproxy instance) and the handlers that trigger origin switches or cache purges. CProxyClient itself never touches the database; every function takes a service.Cache (or equivalent host/port) as a parameter.
Function reference
| Function | Purpose |
|---|---|
PutOriginURLs(node service.Cache, originURLs []string) (*CProxyResponse, error) |
PATCH /api/config — switch originUrls in-memory. Fast, but not persisted — lost on cproxy restart. |
PutOrigins(node service.Cache, config json.RawMessage) (*CProxyResponse, error) |
PUT /api/config with a full config body — for structural changes beyond just origin URLs (only available from cproxy v1.1.5.rc1+; PUT /api/config/origins 404s on earlier versions) |
PurgeContent(node service.Cache, key string) (*CProxyResponse, error) |
DELETE /api/caches/{key}/* — purge a cached path after switching origins |
GetConfig(node service.Cache) (*CProxyResponse, error) |
GET /api/config — read current running config |
Important vendor quirks (belong here, not in the domain)
balancing-policy,retry-count,health-check, andfailover-responsescannot be changed via API — they're startup-only, set in the node'scproxy.yml. Callers should not expectPutOrigins/PutOriginURLsto affect these.PATCHchanges are in-memory only. If a node restarts, anything set viaPutOriginURLsis lost unless CoreAPI re-applies it. The recommended flow, owned bydomain/distribution, is:PutOriginURLs(switch live)PurgeContent(clear stale cache for the switched path)- Persist the new origin state to Postgres, so it can be re-applied to the node on next startup
PUT /api/config/originsis version-gated (404 before v1.1.5.rc1) —GetConfigis useful for checking node version/capability before attempting the full-bodyPutOriginspath.
Example call from a domain handler
// domain/distribution/handlers/handler_cache.go
resp, err := cproxyclient.PutOriginURLs(cache, req.OriginURLs)
if err != nil {
return response.Error(c, 502, "cproxy node unreachable")
}
if _, err := cproxyclient.PurgeContent(cache, req.PurgePath); err != nil {
// log but don't fail the request — origin switch already succeeded
}
// persist so this survives a node restart
db.Model(&cache).Update("origin_urls", req.OriginURLs)
return response.OK(c, resp)
See changelog for history.