Skip to content

Commit a4973d9

Browse files
authored
Merge pull request coreos#153 from thomastaylor312/fix/expires_header
fix(http): Allows 0 as an `Expires` header value
2 parents d68c0e2 + 57af5c3 commit a4973d9

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

http/http.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,12 @@ func expires(date, expires string) (time.Duration, bool, error) {
9191
return 0, false, nil
9292
}
9393

94-
te, err := time.Parse(time.RFC1123, expires)
94+
var te time.Time
95+
var err error
96+
if expires == "0" {
97+
return 0, false, nil
98+
}
99+
te, err = time.Parse(time.RFC1123, expires)
95100
if err != nil {
96101
return 0, false, err
97102
}

http/http_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,13 @@ func TestExpiresPass(t *testing.T) {
177177
wantTTL: 0,
178178
wantOK: false,
179179
},
180+
// Expires set to false
181+
{
182+
date: "Thu, 01 Dec 1983 22:00:00 GMT",
183+
exp: "0",
184+
wantTTL: 0,
185+
wantOK: false,
186+
},
180187
// Expires < Date
181188
{
182189
date: "Fri, 02 Dec 1983 01:00:00 GMT",

oidc/provider_test.go

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -473,15 +473,19 @@ func (g *fakeProviderConfigGetterSetter) Set(cfg ProviderConfig) error {
473473
}
474474

475475
type fakeProviderConfigHandler struct {
476-
cfg ProviderConfig
477-
maxAge time.Duration
476+
cfg ProviderConfig
477+
maxAge time.Duration
478+
noExpires bool
478479
}
479480

480481
func (s *fakeProviderConfigHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
481482
b, _ := json.Marshal(&s.cfg)
482483
if s.maxAge.Seconds() >= 0 {
483484
w.Header().Set("Cache-Control", fmt.Sprintf("public, max-age=%d", int(s.maxAge.Seconds())))
484485
}
486+
if s.noExpires {
487+
w.Header().Set("Expires", "0")
488+
}
485489
w.Header().Set("Content-Type", "application/json")
486490
w.Write(b)
487491
}
@@ -552,10 +556,11 @@ func TestHTTPProviderConfigGetter(t *testing.T) {
552556
now := fc.Now().UTC()
553557

554558
tests := []struct {
555-
dsc string
556-
age time.Duration
557-
cfg ProviderConfig
558-
ok bool
559+
dsc string
560+
age time.Duration
561+
cfg ProviderConfig
562+
noExpires bool
563+
ok bool
559564
}{
560565
// everything is good
561566
{
@@ -596,6 +601,17 @@ func TestHTTPProviderConfigGetter(t *testing.T) {
596601
},
597602
ok: true,
598603
},
604+
// An expires header set to 0
605+
{
606+
dsc: "https://example.com",
607+
age: time.Minute,
608+
cfg: ProviderConfig{
609+
Issuer: &url.URL{Scheme: "https", Host: "example.com"},
610+
ExpiresAt: now.Add(time.Minute),
611+
},
612+
ok: true,
613+
noExpires: true,
614+
},
599615
}
600616

601617
for i, tt := range tests {

0 commit comments

Comments
 (0)