@@ -78,6 +78,30 @@ func TestRegisterFrontendRoutesServesIndexWithRevalidateHeaders(t *testing.T) {
7878 if conditionalRec .Code != http .StatusNotModified {
7979 t .Fatalf ("expected 304 for matching etag, got %d" , conditionalRec .Code )
8080 }
81+
82+ weakReq := httptest .NewRequest (http .MethodGet , "/" , nil )
83+ weakReq .Header .Set ("If-None-Match" , "W/" + etag )
84+ weakRec := httptest .NewRecorder ()
85+ r .ServeHTTP (weakRec , weakReq )
86+ if weakRec .Code != http .StatusNotModified {
87+ t .Fatalf ("expected 304 for weak etag match, got %d" , weakRec .Code )
88+ }
89+
90+ multiReq := httptest .NewRequest (http .MethodGet , "/" , nil )
91+ multiReq .Header .Set ("If-None-Match" , `"other-tag", W/` + etag )
92+ multiRec := httptest .NewRecorder ()
93+ r .ServeHTTP (multiRec , multiReq )
94+ if multiRec .Code != http .StatusNotModified {
95+ t .Fatalf ("expected 304 for multi-etag match, got %d" , multiRec .Code )
96+ }
97+
98+ starReq := httptest .NewRequest (http .MethodGet , "/" , nil )
99+ starReq .Header .Set ("If-None-Match" , "*" )
100+ starRec := httptest .NewRecorder ()
101+ r .ServeHTTP (starRec , starReq )
102+ if starRec .Code != http .StatusNotModified {
103+ t .Fatalf ("expected 304 for wildcard if-none-match, got %d" , starRec .Code )
104+ }
81105}
82106
83107func TestRegisterFrontendRoutesServesAssetsWithImmutableCache (t * testing.T ) {
@@ -289,3 +313,68 @@ func TestRegisterFrontendRoutesFallsBackToEmbeddedAssets(t *testing.T) {
289313 t .Fatalf ("embedded index.html seems invalid" )
290314 }
291315}
316+
317+ func TestIfNoneMatchMatchesCurrentETag (t * testing.T ) {
318+ currentETag := `"sbpm-1234"`
319+ cases := []struct {
320+ name string
321+ ifNoneMatch string
322+ want bool
323+ }{
324+ {
325+ name : "exact" ,
326+ ifNoneMatch : `"sbpm-1234"` ,
327+ want : true ,
328+ },
329+ {
330+ name : "weak" ,
331+ ifNoneMatch : `W/"sbpm-1234"` ,
332+ want : true ,
333+ },
334+ {
335+ name : "list" ,
336+ ifNoneMatch : `"other", W/"sbpm-1234"` ,
337+ want : true ,
338+ },
339+ {
340+ name : "wildcard" ,
341+ ifNoneMatch : `*` ,
342+ want : true ,
343+ },
344+ {
345+ name : "wildcard with spaces and list" ,
346+ ifNoneMatch : `* , "other"` ,
347+ want : true ,
348+ },
349+ {
350+ name : "invalid wildcard token" ,
351+ ifNoneMatch : `*foo` ,
352+ want : false ,
353+ },
354+ {
355+ name : "invalid" ,
356+ ifNoneMatch : `not-an-etag` ,
357+ want : false ,
358+ },
359+ {
360+ name : "invalid then valid" ,
361+ ifNoneMatch : `not-an-etag, W/"sbpm-1234"` ,
362+ want : true ,
363+ },
364+ {
365+ name : "no-match" ,
366+ ifNoneMatch : `"other"` ,
367+ want : false ,
368+ },
369+ }
370+
371+ for _ , tc := range cases {
372+ tc := tc
373+ t .Run (tc .name , func (t * testing.T ) {
374+ got := ifNoneMatchMatchesCurrentETag (tc .ifNoneMatch , currentETag )
375+ if got != tc .want {
376+ t .Fatalf ("unexpected result for %q: got %v want %v" , tc .ifNoneMatch , got , tc .want )
377+ }
378+ })
379+ }
380+ }
0 commit comments