Skip to content

Commit 7fdb2b1

Browse files
authored
Merge pull request kubernetes#90468 from liggitt/fix-cache-control
Restore cache-control header filter
2 parents f8297af + 5efcc9e commit 7fdb2b1

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

staging/src/k8s.io/apiserver/pkg/server/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,7 @@ func DefaultBuildHandlerChain(apiHandler http.Handler, c *Config) http.Handler {
678678
handler = genericfilters.WithProbabilisticGoaway(handler, c.GoawayChance)
679679
}
680680
handler = genericapifilters.WithAuditAnnotations(handler, c.AuditBackend, c.AuditPolicyChecker)
681+
handler = genericapifilters.WithCacheControl(handler)
681682
handler = genericfilters.WithPanicRecovery(handler)
682683
return handler
683684
}

test/integration/apiserver/apiserver_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,52 @@ func Test4xxStatusCodeInvalidPatch(t *testing.T) {
215215
}
216216
}
217217

218+
func TestCacheControl(t *testing.T) {
219+
masterConfig := framework.NewIntegrationTestMasterConfigWithOptions(&framework.MasterConfigOptions{})
220+
masterConfig.GenericConfig.OpenAPIConfig = framework.DefaultOpenAPIConfig()
221+
master, _, closeFn := framework.RunAMaster(masterConfig)
222+
defer closeFn()
223+
224+
rt, err := restclient.TransportFor(master.GenericAPIServer.LoopbackClientConfig)
225+
if err != nil {
226+
t.Fatal(err)
227+
}
228+
229+
paths := []string{
230+
// untyped
231+
"/",
232+
// health
233+
"/healthz",
234+
// openapi
235+
"/openapi/v2",
236+
// discovery
237+
"/api",
238+
"/api/v1",
239+
"/apis",
240+
"/apis/apps",
241+
"/apis/apps/v1",
242+
// apis
243+
"/api/v1/namespaces",
244+
"/apis/apps/v1/deployments",
245+
}
246+
for _, path := range paths {
247+
t.Run(path, func(t *testing.T) {
248+
req, err := http.NewRequest("GET", master.GenericAPIServer.LoopbackClientConfig.Host+path, nil)
249+
if err != nil {
250+
t.Fatal(err)
251+
}
252+
resp, err := rt.RoundTrip(req)
253+
if err != nil {
254+
t.Fatal(err)
255+
}
256+
cc := resp.Header.Get("Cache-Control")
257+
if !strings.Contains(cc, "private") {
258+
t.Errorf("expected private cache-control, got %q", cc)
259+
}
260+
})
261+
}
262+
}
263+
218264
// Tests that the apiserver returns 202 status code as expected.
219265
func Test202StatusCode(t *testing.T) {
220266
s, clientSet, closeFn := setup(t)

0 commit comments

Comments
 (0)