You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was wondering if there was some functionality which allows reversing the parse process to generate a Cache-Control string value from a ResponseCacheDirectives struct?
My usecase is that I would like to act as a proxy, parse the response header coming from my downstream service, check if the max-age is set, and if the value is unset or too low I will modify it before proxying it to the user.
I ended up just doing this:
// enforce a default CacheControl max-age value if:// 1. A default value is configured for this endpoint.// 2. The existing 'Cache-Control' header is unset or 'public'.// 3. The existing 'max-age' value is unset or lower than the default.ife.DefaultAge>0 {
policy, _:=cacheobject.ParseResponseCacheControl(resp.Header.Get("Cache-Control"))
ifpolicy.Public&&int(policy.MaxAge) <e.DefaultAge {
// policy.MaxAge = cacheobject.DeltaSeconds(e.DefaultAge)resp.Header.Set("Cache-Control", fmt.Sprintf("public, max-age:%d", e.DefaultAge))
}
}
I was hoping to find something more elegant than the fmt.Sprintf("public, max-age:%d", e.DefaultAge) line because presumably it's more complex than just ignoring the other properties?
The text was updated successfully, but these errors were encountered:
I think this would generally be a good feature - two quick thoughts: we might need a new structure to properly serialize it, and we might want to emit other headers beyond cache-control.
Heya,
I was wondering if there was some functionality which allows reversing the parse process to generate a
Cache-Control
string value from aResponseCacheDirectives
struct?My usecase is that I would like to act as a proxy, parse the response header coming from my downstream service, check if the
max-age
is set, and if the value is unset or too low I will modify it before proxying it to the user.I ended up just doing this:
I was hoping to find something more elegant than the
fmt.Sprintf("public, max-age:%d", e.DefaultAge)
line because presumably it's more complex than just ignoring the other properties?The text was updated successfully, but these errors were encountered: