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)
| 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. |
| 154 | func 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 |
| 186 | func (p *HTTP) WithBody(body string) *HTTP { |