Skip to content

Commit 2c86d11

Browse files
committed
refactor: Rename internal header constants for consistency
1 parent c810fde commit 2c86d11

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

internal/header.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import (
1919
)
2020

2121
const (
22-
CacheStatusHeader = "X-Httpcache-Status"
23-
CacheStatusHeaderLegacy = "X-From-Cache" // Deprecated: use [CacheStatusHeader] instead
22+
CacheStatusHeader = "X-Httpcache-Status"
23+
FromCacheHeader = "X-From-Cache" // Deprecated: use [CacheStatusHeader] instead
2424
)
2525

2626
type CacheStatus struct {
@@ -37,14 +37,19 @@ type CacheStatus struct {
3737
func (s CacheStatus) ApplyTo(header http.Header) {
3838
header.Set(CacheStatusHeader, s.Value)
3939
if s.Legacy != "" {
40-
header.Set(CacheStatusHeaderLegacy, s.Legacy)
40+
header.Set(FromCacheHeader, s.Legacy)
4141
}
4242
}
4343

44+
const (
45+
FromCache = "1"
46+
NotFromCache = ""
47+
)
48+
4449
var (
45-
CacheStatusHit = CacheStatus{"HIT", "1"} // served from cache
46-
CacheStatusMiss = CacheStatus{"MISS", ""} // served from origin
47-
CacheStatusStale = CacheStatus{"STALE", "1"} // served from cache but stale
48-
CacheStatusRevalidated = CacheStatus{"REVALIDATED", "1"} // revalidated with origin server
49-
CacheStatusBypass = CacheStatus{"BYPASS", ""} // cache bypassed
50+
CacheStatusHit = CacheStatus{"HIT", FromCache} // served from cache
51+
CacheStatusMiss = CacheStatus{"MISS", NotFromCache} // served from origin
52+
CacheStatusStale = CacheStatus{"STALE", FromCache} // served from cache but stale
53+
CacheStatusRevalidated = CacheStatus{"REVALIDATED", FromCache} // revalidated with origin server
54+
CacheStatusBypass = CacheStatus{"BYPASS", NotFromCache} // cache bypassed
5055
)

0 commit comments

Comments
 (0)