MCPcopy Create free account
hub / github.com/evcc-io/evcc / dropCacheBusting

Function dropCacheBusting

plugin/http.go:154–183  ·  view source on GitHub ↗

dropCacheBusting removes response directives that defeat the cache layer (no-cache, no-store and max-age=0) so a configured cache duration takes effect.

(resp *http.Response, header string)

Source from the content-addressed store, hash-verified

152// dropCacheBusting removes response directives that defeat the cache layer
153// (no-cache, no-store and max-age=0) so a configured cache duration takes effect.
154func dropCacheBusting(resp *http.Response, header string) {
155 h := resp.Header.Get(header)
156 if h == "" {
157 return
158 }
159
160 var hh []string
161
162 for token := range strings.SplitSeq(h, ",") {
163 s := strings.TrimSpace(token)
164
165 name, value, _ := strings.Cut(s, "=")
166 switch strings.ToLower(strings.TrimSpace(name)) {
167 case "no-cache", "no-store":
168 continue
169 case "max-age":
170 if v, err := strconv.Atoi(strings.TrimSpace(value)); err == nil && v <= 0 {
171 continue
172 }
173 }
174
175 hh = append(hh, s)
176 }
177
178 if len(hh) == 0 {
179 resp.Header.Del(header)
180 } else {
181 resp.Header.Set(header, strings.Join(hh, ", "))
182 }
183}
184
185// WithBody adds request body
186func (p *HTTP) WithBody(body string) *HTTP {

Callers 1

NewHTTPFunction · 0.85

Calls 2

GetMethod · 0.65
SetMethod · 0.45

Tested by

no test coverage detected