returns struct with cache-control settings from user metadata.
(o ObjectInfo)
| 100 | |
| 101 | // returns struct with cache-control settings from user metadata. |
| 102 | func cacheControlOpts(o ObjectInfo) *cacheControl { |
| 103 | c := cacheControl{} |
| 104 | m := o.UserDefined |
| 105 | if !o.Expires.Equal(timeSentinel) { |
| 106 | c.expiry = o.Expires |
| 107 | } |
| 108 | |
| 109 | var headerVal string |
| 110 | for k, v := range m { |
| 111 | if strings.EqualFold(k, "cache-control") { |
| 112 | headerVal = v |
| 113 | } |
| 114 | } |
| 115 | if headerVal == "" { |
| 116 | return nil |
| 117 | } |
| 118 | headerVal = strings.ToLower(headerVal) |
| 119 | headerVal = strings.TrimSpace(headerVal) |
| 120 | |
| 121 | vals := strings.Split(headerVal, ",") |
| 122 | for _, val := range vals { |
| 123 | val = strings.TrimSpace(val) |
| 124 | |
| 125 | if val == "no-store" { |
| 126 | c.noStore = true |
| 127 | continue |
| 128 | } |
| 129 | if val == "only-if-cached" { |
| 130 | c.onlyIfCached = true |
| 131 | continue |
| 132 | } |
| 133 | if val == "no-cache" { |
| 134 | c.noCache = true |
| 135 | continue |
| 136 | } |
| 137 | p := strings.Split(val, "=") |
| 138 | |
| 139 | if len(p) != 2 { |
| 140 | continue |
| 141 | } |
| 142 | if p[0] == "max-age" || |
| 143 | p[0] == "s-maxage" || |
| 144 | p[0] == "min-fresh" || |
| 145 | p[0] == "max-stale" { |
| 146 | i, err := strconv.Atoi(p[1]) |
| 147 | if err != nil { |
| 148 | return nil |
| 149 | } |
| 150 | if p[0] == "max-age" { |
| 151 | c.maxAge = i |
| 152 | } |
| 153 | if p[0] == "s-maxage" { |
| 154 | c.sMaxAge = i |
| 155 | } |
| 156 | if p[0] == "min-fresh" { |
| 157 | c.minFresh = i |
| 158 | } |
| 159 | if p[0] == "max-stale" { |