fix(19.3-06): site-cache purge never follows redirects (WR-02)
- the purge client's CheckRedirect returns http.ErrUseLastResponse: a 3xx is logged as a failed purge with its status and the bearer token never reaches the Location
This commit is contained in:
@@ -90,9 +90,14 @@ func NewSiteCachePurgerFor(urlKey, tokenKey, purgeURL, token string) (*SiteCache
|
||||
if len(token) < SiteCachePurgeMinTokenLength {
|
||||
return nil, fmt.Errorf("%s must hold at least %d characters", tokenKey, SiteCachePurgeMinTokenLength)
|
||||
}
|
||||
return &SiteCachePurger{url: u.String(), endpoint: u.Host + u.Path, token: token, client: &http.Client{}}, nil
|
||||
return &SiteCachePurger{url: u.String(), endpoint: u.Host + u.Path, token: token, client: &http.Client{CheckRedirect: noRedirect}}, nil
|
||||
}
|
||||
|
||||
// noRedirect keeps the purge client on the configured URL: a 3xx answer is
|
||||
// returned as is (and logged as a failed purge with its status), so the
|
||||
// bearer token never follows a Location and the POST never becomes a GET.
|
||||
func noRedirect(*http.Request, []*http.Request) error { return http.ErrUseLastResponse }
|
||||
|
||||
// Endpoint returns the purge URL's host and path, without the scheme, user
|
||||
// info or query, for log lines.
|
||||
func (p *SiteCachePurger) Endpoint() string {
|
||||
@@ -118,8 +123,9 @@ type siteCachePurgeBody struct {
|
||||
// Purge sends the purge request for one saved entity: a POST of
|
||||
// {"kind":kind,"slug":slug} with the bearer token, bounded by
|
||||
// SiteCachePurgeTimeout and detached from ctx's cancellation. It logs the
|
||||
// outcome and returns nothing: a purge never fails a save. The token is
|
||||
// never logged.
|
||||
// outcome and returns nothing: a purge never fails a save. A redirect is
|
||||
// never followed; a 3xx answer is logged as a failed purge with its status.
|
||||
// The token is never logged.
|
||||
func (p *SiteCachePurger) Purge(ctx context.Context, kind, slug string) {
|
||||
if p == nil {
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user