diff options
author | Adrian Villin <avillin@cisco.com> | 2024-08-08 08:56:34 +0200 |
---|---|---|
committer | Florin Coras <florin.coras@gmail.com> | 2024-08-20 18:19:12 +0000 |
commit | 86fa943725b5f7565133fd513da8d836f5f9c049 (patch) | |
tree | 5d04d533cc95fcec5710ce39dd42465820fb9017 /extras/hs-test/http_test.go | |
parent | 3601b322a010b0c0a83aeec912b224ec97b9c898 (diff) |
http_static: make max-age configurable
Type: improvement
Change-Id: I629add6e3f4219d56610c3785013f69dbe847844
Signed-off-by: Adrian Villin <avillin@cisco.com>
Diffstat (limited to 'extras/hs-test/http_test.go')
-rw-r--r-- | extras/hs-test/http_test.go | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/extras/hs-test/http_test.go b/extras/hs-test/http_test.go index 5b2b65f4eb2..f8b0fb79615 100644 --- a/extras/hs-test/http_test.go +++ b/extras/hs-test/http_test.go @@ -28,7 +28,7 @@ func init() { HttpContentLengthTest, HttpStaticBuildInUrlGetIfListTest, HttpStaticBuildInUrlGetVersionTest, HttpStaticMacTimeTest, HttpStaticBuildInUrlGetVersionVerboseTest, HttpVersionNotSupportedTest, HttpInvalidContentLengthTest, HttpInvalidTargetSyntaxTest, HttpStaticPathTraversalTest, HttpUriDecodeTest, - HttpHeadersTest, HttpStaticFileHandlerTest, HttpClientTest, HttpClientErrRespTest, HttpClientPostFormTest, + HttpHeadersTest, HttpStaticFileHandlerTest, HttpStaticFileHandlerDefaultMaxAgeTest, HttpClientTest, HttpClientErrRespTest, HttpClientPostFormTest, HttpClientPostFileTest, HttpClientPostFilePtrTest, AuthorityFormTargetTest) RegisterNoTopoSoloTests(HttpStaticPromTest, HttpTpsTest, HttpTpsInterruptModeTest, PromConcurrentConnectionsTest, PromMemLeakTest, HttpClientPostMemLeakTest, HttpInvalidClientRequestMemLeakTest) @@ -535,7 +535,23 @@ func HttpInvalidClientRequestMemLeakTest(s *NoTopoSuite) { } +func HttpStaticFileHandlerDefaultMaxAgeTest(s *NoTopoSuite) { + HttpStaticFileHandlerTestFunction(s, "default") +} + func HttpStaticFileHandlerTest(s *NoTopoSuite) { + HttpStaticFileHandlerTestFunction(s, "123") +} + +func HttpStaticFileHandlerTestFunction(s *NoTopoSuite, max_age string) { + var max_age_formatted string + if max_age == "default" { + max_age_formatted = "" + max_age = "600" + } else { + max_age_formatted = "max-age " + max_age + } + content := "<html><body><p>Hello</p></body></html>" content2 := "<html><body><p>Page</p></body></html>" vpp := s.GetContainerByName("vpp").VppInstance @@ -545,7 +561,7 @@ func HttpStaticFileHandlerTest(s *NoTopoSuite) { err = vpp.Container.CreateFile(wwwRootPath+"/page.html", content2) s.AssertNil(err, fmt.Sprint(err)) serverAddress := s.GetInterfaceByName(TapInterfaceName).Peer.Ip4AddressString() - s.Log(vpp.Vppctl("http static server www-root " + wwwRootPath + " uri tcp://" + serverAddress + "/80 debug cache-size 2m")) + s.Log(vpp.Vppctl("http static server www-root " + wwwRootPath + " uri tcp://" + serverAddress + "/80 debug cache-size 2m " + max_age_formatted)) client := NewHttpClient() req, err := http.NewRequest("GET", "http://"+serverAddress+":80/index.html", nil) @@ -556,7 +572,7 @@ func HttpStaticFileHandlerTest(s *NoTopoSuite) { s.Log(DumpHttpResp(resp, true)) s.AssertEqual(200, resp.StatusCode) s.AssertContains(resp.Header.Get("Content-Type"), "html") - s.AssertContains(resp.Header.Get("Cache-Control"), "max-age=") + s.AssertContains(resp.Header.Get("Cache-Control"), "max-age="+max_age) s.AssertEqual(int64(len([]rune(content))), resp.ContentLength) body, err := io.ReadAll(resp.Body) s.AssertNil(err, fmt.Sprint(err)) @@ -572,7 +588,7 @@ func HttpStaticFileHandlerTest(s *NoTopoSuite) { s.Log(DumpHttpResp(resp, true)) s.AssertEqual(200, resp.StatusCode) s.AssertContains(resp.Header.Get("Content-Type"), "html") - s.AssertContains(resp.Header.Get("Cache-Control"), "max-age=") + s.AssertContains(resp.Header.Get("Cache-Control"), "max-age="+max_age) s.AssertEqual(int64(len([]rune(content))), resp.ContentLength) body, err = io.ReadAll(resp.Body) s.AssertNil(err, fmt.Sprint(err)) @@ -586,7 +602,7 @@ func HttpStaticFileHandlerTest(s *NoTopoSuite) { s.Log(DumpHttpResp(resp, true)) s.AssertEqual(200, resp.StatusCode) s.AssertContains(resp.Header.Get("Content-Type"), "html") - s.AssertContains(resp.Header.Get("Cache-Control"), "max-age=") + s.AssertContains(resp.Header.Get("Cache-Control"), "max-age="+max_age) s.AssertEqual(int64(len([]rune(content2))), resp.ContentLength) body, err = io.ReadAll(resp.Body) s.AssertNil(err, fmt.Sprint(err)) |