diff --git a/doc/admin-guide/configuration/cache-basics.en.rst b/doc/admin-guide/configuration/cache-basics.en.rst index ffdace636e4..273005b9b8d 100644 --- a/doc/admin-guide/configuration/cache-basics.en.rst +++ b/doc/admin-guide/configuration/cache-basics.en.rst @@ -178,14 +178,14 @@ To specify an absolute freshness limit: Specifying Header Requirements ------------------------------ -To further ensure freshness of the objects in the cache, configure -Traffic Server to cache only objects with specific headers. By default, -Traffic Server caches all objects (including objects with no headers); -you should change the default setting only for specialized proxy -situations. If you configure Traffic Server to cache only HTTP objects -with ``Expires`` or ``max-age`` headers, then the cache hit rate will be -noticeably reduced (since very few objects will have explicit expiration -information). +To further ensure freshness of the objects in the cache, Traffic Server by +default caches only HTTP objects with ``Expires`` or ``max-age`` headers. It can +also be configured to cache all objects (including objects with no headers). +Different configurations of header requirements would have a noticeable effect +on cache hit rate. For instance, if Traffic Server is configured to cache only +HTTP objects with ``Expires`` or ``max-age`` headers (the default setting), then +the cache hit rate will be noticeably reduced (since very few objects will have +explicit expiration information). To configure Traffic Server to cache objects with specific headers: @@ -207,12 +207,12 @@ Traffic Server bases the servability of a cached object on ``Cache-Control`` headers that appear in both client requests and server responses. The following ``Cache-Control`` headers affect whether objects are served from cache: -- The ``no-cache`` header, sent by clients, tells Traffic Server that - it should not serve any objects directly from the cache. When present in a - client request, Traffic Server will always obtain the object from the - origin server. You can configure Traffic Server to ignore client - ``no-cache`` headers. Refer to `Configuring Traffic Server to Ignore Client no-cache Headers`_ - for more information. +- The ``no-cache`` header, sent by clients, tells Traffic Server that it should + not serve any objects directly from the cache. When present in a client + request, Traffic Server will always obtain the object from the origin server. + By default, Traffic Server ignores this header. You can configure Traffic + Server to honor client ``no-cache`` headers. Refer to `Configuring Traffic + Server to Honor Client no-cache Headers`_ for more information. - The ``max-age`` header, sent by servers, is compared to the object age. If the age is less than ``max-age``, then the object is fresh @@ -374,17 +374,17 @@ and files. Client Directives ----------------- -By default, Traffic Server does not cache objects with the following -request headers: - -- ``Authorization`` +Configurations can be set to determine whether to cache objects with the +following client directives (by default, Traffic Server caches objects with +these request headers): - ``Cache-Control: no-store`` - ``Cache-Control: no-cache`` - To configure Traffic Server to ignore this request header, refer to - `Configuring Traffic Server to Ignore Client no-cache Headers`_. + To configure Traffic Server to honor the ``Cache-Control: no-store`` and + ``Cache-Control: no-cache`` request headers, refer to `Configuring Traffic + Server to Honor Client no-cache Headers`_. - ``Cookie`` (for text objects) @@ -394,21 +394,26 @@ request headers: cache all cookied content, or cache cookied content that is of image type only. For more information, refer to `Caching Cookied Objects`_. -Configuring Traffic Server to Ignore Client no-cache Headers +Configuring Traffic Server to Honor Client no-cache Headers ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -By default, Traffic Server strictly observes client -``Cache-Control: no-cache`` directives. If a requested object contains a -``no-cache`` header, then Traffic Server forwards the request to the -origin server even if it has a fresh copy in cache. You can configure -Traffic Server to ignore client ``no-cache`` directives such that it -ignores ``no-cache`` headers from client requests and serves the object -from its cache. +By default, Traffic Server ignores client ``Cache-Control: no-cache`` +directives. Even if a requested object contains a ``no-cache`` directive, +Traffic Server serves the object from its cache. You can configure Traffic +Server to honor this header and forward the request to the origin server even +if it has a fresh copy in cache. + +Likewise, by default Traffic Server also ignores client ``Cache-Control: +no-store`` directives. Traffic Server caches response from the server regardless +of the ``no-store`` headers from client requests. + +You can configure Traffic Server to honor both of these client directives with +the following: #. Edit :ts:cv:`proxy.config.http.cache.ignore_client_no_cache` in :file:`records.config`. :: - CONFIG proxy.config.http.cache.ignore_client_no_cache INT 1 + CONFIG proxy.config.http.cache.ignore_client_no_cache INT 0 #. Run the command :option:`traffic_ctl config reload` to apply the configuration changes. @@ -420,19 +425,18 @@ headers: - ``Cache-Control: no-store`` -- ``Cache-Control: private`` - -- ``WWW-Authenticate`` +- ``Cache-Control: no-cache`` - To configure Traffic Server to ignore ``WWW-Authenticate`` headers, - refer to `Configuring Traffic Server to Ignore WWW-Authenticate Headers`_. + To configure Traffic Server to ignore ``no-cache`` and ``no-store`` headers, + refer to `Configuring Traffic Server to Ignore Server no-cache Headers`_. -- ``Set-Cookie`` +- ``Cache-Control: private`` -- ``Cache-Control: no-cache`` +- ``WWW-Authenticate`` - To configure Traffic Server to ignore ``no-cache`` headers, refer to - `Configuring Traffic Server to Ignore Server no-cache Headers`_. + To configure Traffic Server to ignore ``WWW-Authenticate`` headers and cache + the corresponding objects, refer to `Configuring Traffic Server to Ignore + WWW-Authenticate Headers`_. - ``Expires`` header with a value of 0 (zero) or a past date. @@ -547,18 +551,23 @@ Caching Cookied Objects By default, Traffic Server caches objects served in response to requests that contain cookies. This is true for all types of objects including -text. Traffic Server does not cache cookied text content because object -headers are stored along with the object, and personalized cookie header -values could be saved with the object. With non-text objects, it is -unlikely that personalized headers are delivered or used. +text. You can reconfigure Traffic Server to: - Not cache cookied content of any type. +- Cache all cookied content regardless of type. + - Cache cookied content that is of image type only. -- Cache all cookied content regardless of type. +- Cache all cookied content except text type. + + It may be appropriate to configure Traffic Server to not cache cookied text + content because object headers are stored along with the object, and + personalized cookie header values could be saved with the object. With + non-text objects, it is unlikely that personalized headers are delivered or + used. To configure how Traffic Server caches cookied content: diff --git a/doc/admin-guide/files/records.config.en.rst b/doc/admin-guide/files/records.config.en.rst index ba9cc02169d..c9fcbfedd8e 100644 --- a/doc/admin-guide/files/records.config.en.rst +++ b/doc/admin-guide/files/records.config.en.rst @@ -2173,7 +2173,7 @@ Cache Control :reloadable: :overridable: - When enabled (``1``), |TS| ignores client requests to bypass the cache. + When enabled (``1``), |TS| ignores client requests to bypass the cache. Specifically, ``Pragma: no-cache``, ``Cache-Control: no-cache`` and ``Cache-Control: no-store`` in requests are ignored. .. ts:cv:: CONFIG proxy.config.http.cache.ims_on_client_no_cache INT 1 :reloadable: @@ -2185,7 +2185,7 @@ Cache Control :reloadable: :overridable: - When enabled (``1``), |TS| ignores origin server requests to bypass the cache. + When enabled (``1``), |TS| ignores origin server requests to bypass the cache. Specifically, ``Pragma: no-cache``, ``Cache-Control: no-cache`` and ``Cache-Control: no-store`` in responses are ignored. .. ts:cv:: CONFIG proxy.config.http.cache.cache_responses_to_cookies INT 1 :reloadable: @@ -2207,8 +2207,8 @@ Cache Control .. ts:cv:: CONFIG proxy.config.http.cache.ignore_authentication INT 0 :overridable: - When enabled (``1``), |TS| ignores ``WWW-Authentication`` headers in responses ``WWW-Authentication`` headers are removed and - not cached. + When enabled (``1``), |TS| ignores ``WWW-Authentication`` headers in + responses and the responses are cached. .. ts:cv:: CONFIG proxy.config.http.cache.cache_urls_that_look_dynamic INT 1 :reloadable: diff --git a/tests/gold_tests/cache/cache-auth.test.py b/tests/gold_tests/cache/cache-auth.test.py new file mode 100644 index 00000000000..51cd94af9c1 --- /dev/null +++ b/tests/gold_tests/cache/cache-auth.test.py @@ -0,0 +1,123 @@ +''' +Test authorization-related caching behaviors +''' +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +Test.Summary = ''' +Test authorization-related caching behaviors +''' + +Test.ContinueOnFail = True + +# **testname is required** +testName = "" + + +class AuthDefaultTest: + # Verify the proper caching behavior for request/response containing + # auth-related fields when ATS is in default configuration + authDefaultReplayFile = "replay/auth-default.replay.yaml" + + def __init__(self): + self.setupOriginServer() + self.setupTS() + + def setupOriginServer(self): + self.server = Test.MakeVerifierServerProcess( + "auth-default-verifier-server", + self.authDefaultReplayFile) + + def setupTS(self): + self.ts = Test.MakeATSProcess("ts-auth-default") + self.ts.Disk.records_config.update({ + "proxy.config.diags.debug.enabled": 1, + "proxy.config.diags.debug.tags": "http", + }) + self.ts.Disk.remap_config.AddLine( + f"map / http://127.0.0.1:{self.server.Variables.http_port}/", + ) + + # Verify log for skipping the WWW-Authenticate response + self.ts.Disk.traffic_out.Content += Testers.ContainsExpression( + "response has WWW-Authenticate, response is not cacheable", + "Verify ATS doesn't store the response with WWW-Authenticate.") + + def runTraffic(self): + tr = Test.AddTestRun( + "Verify the proper caching behavior for request/response containing auth-related fields when ATS is in default configuration") + tr.AddVerifierClientProcess( + "auth-default-client", + self.authDefaultReplayFile, + http_ports=[self.ts.Variables.port], + other_args='--thread-limit 1') + tr.Processes.Default.StartBefore(self.server) + tr.Processes.Default.StartBefore(self.ts) + tr.StillRunningAfter = self.server + tr.StillRunningAfter = self.ts + + def run(self): + self.runTraffic() + + +AuthDefaultTest().run() + + +class AuthIgnoredTest: + # Verify the proper caching behavior for request/response containing + # auth-related fields when ATS is configured to bypass caching for those + authIgnoredReplayFile = "replay/auth-ignored.replay.yaml" + + def __init__(self): + self.setupOriginServer() + self.setupTS() + + def setupOriginServer(self): + self.server = Test.MakeVerifierServerProcess( + "auth-ignored-verifier-server", + self.authIgnoredReplayFile) + + def setupTS(self): + self.ts = Test.MakeATSProcess("ts-auth-ignored") + self.ts.Disk.records_config.update({ + "proxy.config.diags.debug.enabled": 1, + "proxy.config.diags.debug.tags": "http", + # Configure ATS to ignore the WWW-Authenticate header in + # response(allow caching of such response) + "proxy.config.http.cache.ignore_authentication": 1 + }) + self.ts.Disk.remap_config.AddLine( + f"map / http://127.0.0.1:{self.server.Variables.http_port}/", + ) + + def runTraffic(self): + tr = Test.AddTestRun( + "Verify the proper caching behavior for request/response containing auth-related fields when ATS is configured to bypass caching for those") + tr.AddVerifierClientProcess( + "auth-ignored-client", + self.authIgnoredReplayFile, + http_ports=[self.ts.Variables.port], + other_args='--thread-limit 1') + tr.Processes.Default.StartBefore(self.server) + tr.Processes.Default.StartBefore(self.ts) + tr.StillRunningAfter = self.server + tr.StillRunningAfter = self.ts + + def run(self): + self.runTraffic() + + +AuthIgnoredTest().run() diff --git a/tests/gold_tests/cache/cache-control.test.py b/tests/gold_tests/cache/cache-control.test.py index 2f00136af4c..ebca08640fa 100644 --- a/tests/gold_tests/cache/cache-control.test.py +++ b/tests/gold_tests/cache/cache-control.test.py @@ -75,7 +75,8 @@ tr.Processes.Default.Streams.stdout = "gold/cache_and_req_body-hit.gold" tr.StillRunningAfter = ts -# Test 3 - response with no cache control, so cache-miss every time +# Test 3 - response doesn't have cache control directive, so cache-miss every +# time tr = Test.AddTestRun() tr.Processes.Default.Command = "printf 'GET /no_cache_control HTTP/1.1\r\n''x-debug: x-cache,x-cache-key,via\r\n''Host: www.example.com\r\n''\r\n'|nc 127.0.0.1 -w 1 {port}".format( port=ts.Variables.port) @@ -83,15 +84,7 @@ tr.Processes.Default.Streams.stdout = "gold/cache_no_cc.gold" tr.StillRunningAfter = ts -# Test 4 - Cache-Control: no-cache (from client), so cache miss every time -tr = Test.AddTestRun() -tr.Processes.Default.Command = "printf 'GET /no_cache_control HTTP/1.1\r\n''Cache-Control:no-cache\r\n''x-debug: x-cache,x-cache-key,via\r\n''Host: www.example.com\r\n''\r\n'|nc 127.0.0.1 -w 1 {port}".format( - port=ts.Variables.port) -tr.Processes.Default.ReturnCode = 0 -tr.Processes.Default.Streams.stdout = "gold/cache_no_cc.gold" -tr.StillRunningAfter = ts - -# Test 5 - hit stale cache. +# Test 4 - hit stale cache. tr = Test.AddTestRun() tr.Processes.Default.Command = "sleep 15; printf 'GET /max_age_10sec HTTP/1.1\r\n''x-debug: x-cache,x-cache-key,via\r\n''Host: www.example.com\r\n''\r\n'|nc 127.0.0.1 -w 1 {port}".format( port=ts.Variables.port) @@ -99,7 +92,7 @@ tr.Processes.Default.Streams.stdout = "gold/cache_hit_stale.gold" tr.StillRunningAfter = ts -# Test 6 - only-if-cached. 504 "Not Cached" should be returned if not in cache +# Test 5 - only-if-cached. 504 "Not Cached" should be returned if not in cache tr = Test.AddTestRun() tr.Processes.Default.Command = "printf 'GET /no_cache_control HTTP/1.1\r\n''Cache-Control: only-if-cached\r\n''x-debug: x-cache,x-cache-key,via\r\n''Host: www.example.com\r\n''Cache-control: max-age=300\r\n''\r\n'|nc 127.0.0.1 -w 1 {port}".format( port=ts.Variables.port) @@ -133,8 +126,7 @@ # -# Verify correct handling of cache-control no-cache and interaction with pragma header -# +# Verify correct interaction between cache-control no-cache and pragma header # ts = Test.MakeATSProcess("ts-cache-control-pragma") ts.Disk.records_config.update({ @@ -152,3 +144,199 @@ tr.Processes.Default.StartBefore(server) tr.Processes.Default.StartBefore(ts) tr.StillRunningAfter = ts + + +class RequestCacheControlDefaultTest: + # Verify the proper handling of cache-control directives in requests in + # default configuration + requestCacheControlReplayFile = "replay/request-cache-control-default.replay.yaml" + + def __init__(self): + self.setupOriginServer() + self.setupTS() + + def setupOriginServer(self): + self.server = Test.MakeVerifierServerProcess( + "request-cache-control-default-verifier-server", + self.requestCacheControlReplayFile) + + def setupTS(self): + self.ts = Test.MakeATSProcess("ts-request-cache-control-default") + self.ts.Disk.records_config.update({ + "proxy.config.diags.debug.enabled": 1, + "proxy.config.diags.debug.tags": "http", + }) + self.ts.Disk.remap_config.AddLine( + f"map / http://127.0.0.1:{self.server.Variables.http_port}/", + ) + + def runTraffic(self): + tr = Test.AddTestRun("Verify the proper handling of cache-control directives in requests in default configuration") + tr.AddVerifierClientProcess( + "request-cache-control-default-client", + self.requestCacheControlReplayFile, + http_ports=[self.ts.Variables.port], + other_args='--thread-limit 1') + tr.Processes.Default.StartBefore(self.server) + tr.Processes.Default.StartBefore(self.ts) + tr.StillRunningAfter = self.server + tr.StillRunningAfter = self.ts + + def run(self): + self.runTraffic() + + +RequestCacheControlDefaultTest().run() + + +class RequestCacheControlHonorClientTest: + # Verify the proper handling of cache-control directives in requests when + # ATS is configured to honor client's request to bypass the cache + requestCacheControlReplayFile = "replay/request-cache-control-honor-client.replay.yaml" + + def __init__(self): + self.setupOriginServer() + self.setupTS() + + def setupOriginServer(self): + self.server = Test.MakeVerifierServerProcess( + "request-cache-control-honor-client-verifier-server", + self.requestCacheControlReplayFile) + + def setupTS(self): + self.ts = Test.MakeATSProcess("ts-request-cache-control-honor-client") + self.ts.Disk.records_config.update({ + "proxy.config.diags.debug.enabled": 1, + "proxy.config.diags.debug.tags": "http", + # Configured to honor client requests to bypass the cache + "proxy.config.http.cache.ignore_client_no_cache": 0 + }) + self.ts.Disk.remap_config.AddLine( + f"map / http://127.0.0.1:{self.server.Variables.http_port}/", + ) + + # Verify logs for the request containing no-cache + self.ts.Disk.traffic_out.Content += Testers.ContainsExpression( + "Revalidate document with server", + "Verify that ATS honors the no-cache and performs a revalidation.") + # Verify logs for the request containing no-store + self.ts.Disk.traffic_out.Content += Testers.ContainsExpression( + "client does not permit storing, and cache control does not say to ignore client no-cache", + "Verify that ATS honors the no-store.") + + def runTraffic(self): + tr = Test.AddTestRun( + "Verify the proper handling of cache-control directives in requests when ATS is configured to honor client's request to bypass the cache") + tr.AddVerifierClientProcess( + "request-cache-control-honor-client-client", + self.requestCacheControlReplayFile, + http_ports=[self.ts.Variables.port], + other_args='--thread-limit 1') + tr.Processes.Default.StartBefore(self.server) + tr.Processes.Default.StartBefore(self.ts) + tr.StillRunningAfter = self.server + tr.StillRunningAfter = self.ts + + def run(self): + self.runTraffic() + + +RequestCacheControlHonorClientTest().run() + + +class ResponseCacheControlDefaultTest: + # Verify the proper handling of cache-control directives in responses in + # default configuration + responseCacheControlReplayFile = "replay/response-cache-control-default.replay.yaml" + + def __init__(self): + self.setupOriginServer() + self.setupTS() + + def setupOriginServer(self): + self.server = Test.MakeVerifierServerProcess( + "response-cache-control-default-verifier-server", + self.responseCacheControlReplayFile) + + def setupTS(self): + self.ts = Test.MakeATSProcess("ts-response-cache-control-default") + self.ts.Disk.records_config.update({ + "proxy.config.diags.debug.enabled": 1, + "proxy.config.diags.debug.tags": "http", + }) + self.ts.Disk.remap_config.AddLine( + f"map / http://127.0.0.1:{self.server.Variables.http_port}/", + ) + + # Verify logs for the response containing no-cache or no-store + self.ts.Disk.traffic_out.Content += Testers.ContainsExpression( + "server does not permit storing and config file does not indicate that server directive should be ignored", + "Verify that ATS honors the no-cache(or no-store) in response and bypasses the cache.") + + def runTraffic(self): + tr = Test.AddTestRun("Verify the proper handling of cache-control directives in responses in default configuration") + tr.AddVerifierClientProcess( + "response-cache-control-client-default", + self.responseCacheControlReplayFile, + http_ports=[self.ts.Variables.port], + other_args='--thread-limit 1') + tr.Processes.Default.StartBefore(self.server) + tr.Processes.Default.StartBefore(self.ts) + tr.StillRunningAfter = self.server + tr.StillRunningAfter = self.ts + + def run(self): + self.runTraffic() + + +ResponseCacheControlDefaultTest().run() + + +class ResponseCacheControlIgnoredTest: + # Verify the proper handling of cache-control directives in responses when + # ATS is configured to ignore server's request to bypass the cache + responseCacheControlReplayFile = "replay/response-cache-control-ignored.replay.yaml" + + def __init__(self): + self.setupOriginServer() + self.setupTS() + + def setupOriginServer(self): + self.server = Test.MakeVerifierServerProcess( + "response-cache-control-ignored-verifier-server", + self.responseCacheControlReplayFile) + + def setupTS(self): + self.ts = Test.MakeATSProcess("ts-response-cache-control-ignored") + self.ts.Disk.records_config.update({ + "proxy.config.diags.debug.enabled": 1, + "proxy.config.diags.debug.tags": "http", + "proxy.config.http.cache.ignore_server_no_cache": 1 + }) + self.ts.Disk.remap_config.AddLine( + f"map / http://127.0.0.1:{self.server.Variables.http_port}/", + ) + + # Verify logs for the response containing no-cache or no-store + self.ts.Disk.traffic_out.Content += Testers.ExcludesExpression( + "server does not permit storing and config file does not indicate that server directive should be ignored", + "Verify that ATS ignores the no-cache(or no-store) in response and caches the responses despite their presence.") + + def runTraffic(self): + tr = Test.AddTestRun( + "Verify the proper handling of cache-control directives in responses when ATS is configured to ignore server's request to bypass the cache") + tr.AddVerifierClientProcess( + "response-cache-control-client-ignored", + self.responseCacheControlReplayFile, + http_ports=[self.ts.Variables.port], + other_args='--thread-limit 1') + tr.Processes.Default.StartBefore(self.server) + tr.Processes.Default.StartBefore(self.ts) + tr.StillRunningAfter = self.server + tr.StillRunningAfter = self.ts + + def run(self): + self.runTraffic() + +# Commenting out as this test would fail due to issue #9283 +# ResponseCacheControlIgnoredTest().run() diff --git a/tests/gold_tests/cache/cache-cookie.test.py b/tests/gold_tests/cache/cache-cookie.test.py new file mode 100644 index 00000000000..7f51c9ca3d0 --- /dev/null +++ b/tests/gold_tests/cache/cache-cookie.test.py @@ -0,0 +1,255 @@ +''' +Test cookie-related caching behaviors +''' +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +Test.Summary = ''' +Test cookie-related caching behaviors +''' + +Test.ContinueOnFail = True + +# **testname is required** +testName = "" + + +class CookieDefaultTest: + # Verify the correct caching behavior when ATS is in default configuration + cookieDefaultReplayFile = "replay/cookie-default.replay.yaml" + + def __init__(self): + self.setupOriginServer() + self.setupTS() + + def setupOriginServer(self): + self.server = Test.MakeVerifierServerProcess( + "cookie-default-verifier-server", + self.cookieDefaultReplayFile) + + def setupTS(self): + self.ts = Test.MakeATSProcess("ts-cookie-default") + self.ts.Disk.records_config.update({ + "proxy.config.diags.debug.enabled": 1, + "proxy.config.diags.debug.tags": "http", + }) + self.ts.Disk.remap_config.AddLine( + f"map / http://127.0.0.1:{self.server.Variables.http_port}/", + ) + + def runTraffic(self): + tr = Test.AddTestRun("Verify the correct caching behavior when ATS is in default configuration") + tr.AddVerifierClientProcess( + "cookie-default-client", + self.cookieDefaultReplayFile, + http_ports=[self.ts.Variables.port], + other_args='--thread-limit 1') + tr.Processes.Default.StartBefore(self.server) + tr.Processes.Default.StartBefore(self.ts) + tr.StillRunningAfter = self.server + tr.StillRunningAfter = self.ts + + def run(self): + self.runTraffic() + + +CookieDefaultTest().run() + + +class CookieBypassTest: + # Verify the correct caching behavior when ATS is configured to not cache + # response to cookie for any content type + cookieBypassReplayFile = "replay/cookie-bypass-cache.replay.yaml" + + def __init__(self): + self.setupOriginServer() + self.setupTS() + + def setupOriginServer(self): + self.server = Test.MakeVerifierServerProcess( + "cookie-bypass-verifier-server", + self.cookieBypassReplayFile) + + def setupTS(self): + self.ts = Test.MakeATSProcess("ts-cookie-bypass") + self.ts.Disk.records_config.update({ + "proxy.config.diags.debug.enabled": 1, + "proxy.config.diags.debug.tags": "http", + # Bypass cache for any responses to cookies + "proxy.config.http.cache.cache_responses_to_cookies": 0 + }) + self.ts.Disk.remap_config.AddLine( + f"map / http://127.0.0.1:{self.server.Variables.http_port}/", + ) + + def runTraffic(self): + tr = Test.AddTestRun( + "Verify the correct caching behavior when ATS is configured to not cache response to cookie for any content type") + tr.AddVerifierClientProcess( + "cookie-bypass-client", + self.cookieBypassReplayFile, + http_ports=[self.ts.Variables.port], + other_args='--thread-limit 1') + tr.Processes.Default.StartBefore(self.server) + tr.Processes.Default.StartBefore(self.ts) + tr.StillRunningAfter = self.server + tr.StillRunningAfter = self.ts + + def run(self): + self.runTraffic() + + +CookieBypassTest().run() + + +class CookieImgOnlyTest: + # Verify the correct caching behavior when ATS is configured to cache + # response to cookie only for image content type + cookieImgOnlyReplayFile = "replay/cookie-cache-img-only.replay.yaml" + + def __init__(self): + self.setupOriginServer() + self.setupTS() + + def setupOriginServer(self): + self.server = Test.MakeVerifierServerProcess( + "cookie-img-only-verifier-server", + self.cookieImgOnlyReplayFile) + + def setupTS(self): + self.ts = Test.MakeATSProcess("ts-cookie-img-only") + self.ts.Disk.records_config.update({ + "proxy.config.diags.debug.enabled": 1, + "proxy.config.diags.debug.tags": "http", + # Cache only for image types + "proxy.config.http.cache.cache_responses_to_cookies": 2 + }) + self.ts.Disk.remap_config.AddLine( + f"map / http://127.0.0.1:{self.server.Variables.http_port}/", + ) + + def runTraffic(self): + tr = Test.AddTestRun( + "Verify the correct caching behavior when ATS is configured to cache response to cookie only for image content type") + tr.AddVerifierClientProcess( + "cookie-img-only-client", + self.cookieImgOnlyReplayFile, + http_ports=[self.ts.Variables.port], + other_args='--thread-limit 1') + tr.Processes.Default.StartBefore(self.server) + tr.Processes.Default.StartBefore(self.ts) + tr.StillRunningAfter = self.server + tr.StillRunningAfter = self.ts + + def run(self): + self.runTraffic() + + +CookieImgOnlyTest().run() + + +class CookieAllButTextTest: + # Verify the correct caching behavior when ATS is configured to cache + # response to cookie for all but text types + cookieAllButTextReplayFile = "replay/cookie-all-but-text.replay.yaml" + + def __init__(self): + self.setupOriginServer() + self.setupTS() + + def setupOriginServer(self): + self.server = Test.MakeVerifierServerProcess( + "cookie-all-but-text-verifier-server", + self.cookieAllButTextReplayFile) + + def setupTS(self): + self.ts = Test.MakeATSProcess("ts-cookie-all-but-text") + self.ts.Disk.records_config.update({ + "proxy.config.diags.debug.enabled": 1, + "proxy.config.diags.debug.tags": "http", + # Cache all content type except text + "proxy.config.http.cache.cache_responses_to_cookies": 3 + }) + self.ts.Disk.remap_config.AddLine( + f"map / http://127.0.0.1:{self.server.Variables.http_port}/", + ) + + def runTraffic(self): + tr = Test.AddTestRun( + "Verify the correct caching behavior when ATS is configured to cache response to cookie for all but text types") + tr.AddVerifierClientProcess( + "cookie-all-but-text-client", + self.cookieAllButTextReplayFile, + http_ports=[self.ts.Variables.port], + other_args='--thread-limit 1') + tr.Processes.Default.StartBefore(self.server) + tr.Processes.Default.StartBefore(self.ts) + tr.StillRunningAfter = self.server + tr.StillRunningAfter = self.ts + + def run(self): + self.runTraffic() + + +CookieAllButTextTest().run() + + +class CookieAllButTextWithExcpTest: + # Verify the correct caching behavior when ATS is configured to cache all + # content types but text, but with a few exceptions for text types which + # would also be cached + cookieAllButTextReplayFile = "replay/cookie-all-but-text-with-excp.replay.yaml" + + def __init__(self): + self.setupOriginServer() + self.setupTS() + + def setupOriginServer(self): + self.server = Test.MakeVerifierServerProcess( + "cookie-all-but-text-with-excp-verifier-server", + self.cookieAllButTextReplayFile) + + def setupTS(self): + self.ts = Test.MakeATSProcess("ts-cookie-all-but-text-with-excp") + self.ts.Disk.records_config.update({ + "proxy.config.diags.debug.enabled": 1, + "proxy.config.diags.debug.tags": "http", + # Cache all content type but text. Text type also gets cached for + # server responses without Set-Cookie or with Cache-Control: public + "proxy.config.http.cache.cache_responses_to_cookies": 4 + }) + self.ts.Disk.remap_config.AddLine( + f"map / http://127.0.0.1:{self.server.Variables.http_port}/", + ) + + def runTraffic(self): + tr = Test.AddTestRun( + "Verify the correct caching behavior when ATS is configured to cache all content types but text, but with a few exceptions for text types which would also be cached") + tr.AddVerifierClientProcess( + "cookie-all-but-text-with-excp-client", + self.cookieAllButTextReplayFile, + http_ports=[self.ts.Variables.port], + other_args='--thread-limit 1') + tr.Processes.Default.StartBefore(self.server) + tr.Processes.Default.StartBefore(self.ts) + tr.StillRunningAfter = self.server + tr.StillRunningAfter = self.ts + + def run(self): + self.runTraffic() + + +CookieAllButTextWithExcpTest().run() diff --git a/tests/gold_tests/cache/replay/auth-default.replay.yaml b/tests/gold_tests/cache/replay/auth-default.replay.yaml new file mode 100644 index 00000000000..d68cdffc502 --- /dev/null +++ b/tests/gold_tests/cache/replay/auth-default.replay.yaml @@ -0,0 +1,68 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# +# This replay file assumes that caching is enabled and +# proxy.config.http.cache.ignore_authentication is set to 0(current default) +# +meta: + version: "1.0" + +sessions: + - transactions: + # Verify the response containing WWW-Authenticate is not cached + - client-request: + method: "GET" + version: "1.1" + url: /cc/auth + headers: + fields: + - [uuid, cc-www-auth-response] + - [Host, example.com] + + server-response: + status: 401 + reason: Unauthorized + headers: + fields: + - [Content-Length, 4] + - [Cache-Control, "max-age=5"] + - [WWW-Authenticate, "Basic"] + + proxy-response: + status: 401 + + # Re-request to make sure the previous response was not cached + - client-request: + # Add a delay so ATS has time to finish any caching IO for the + # previous transaction. + delay: 100ms + method: "GET" + version: "1.1" + url: /cc/auth + headers: + fields: + - [uuid, cc-www-auth-response-verify] + - [Host, example.com] + - [Authorization, "Basic ZGVtbzphdHNAc3Ryb25ncHc="] + + server-response: + status: 200 + reason: OK + + # Verify that the new 200 response is returned instead of the 401 + proxy-response: + status: 200 diff --git a/tests/gold_tests/cache/replay/auth-ignored.replay.yaml b/tests/gold_tests/cache/replay/auth-ignored.replay.yaml new file mode 100644 index 00000000000..b0361fffcc0 --- /dev/null +++ b/tests/gold_tests/cache/replay/auth-ignored.replay.yaml @@ -0,0 +1,67 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# +# This replay file assumes that caching is enabled and +# proxy.config.http.cache.ignore_authentication is set to 1 +# +meta: + version: "1.0" + +sessions: + - transactions: + # Verify that response containing WWW-Authenticate is cached + - client-request: + method: "GET" + version: "1.1" + url: /cc/auth + headers: + fields: + - [uuid, cc-www-auth-response] + - [Host, example.com] + + server-response: + status: 401 + reason: Unauthorized + headers: + fields: + - [Content-Length, 4] + - [Cache-Control, "max-age=5"] + - [WWW-Authenticate, "Basic"] + + proxy-response: + status: 401 + # Re-request to make sure the previous response was not cached + - client-request: + # Add a delay so ATS has time to finish any caching IO for the + # previous transaction. + delay: 100ms + method: "GET" + version: "1.1" + url: /cc/auth + headers: + fields: + - [uuid, cc-www-auth-response-verify] + - [Host, example.com] + - [Authorization, "Basic ZGVtbzphdHNAc3Ryb25ncHc="] + + server-response: + status: 200 + reason: OK + + # Verify that the cached 401 response is returned + proxy-response: + status: 401 diff --git a/tests/gold_tests/cache/replay/cache-control-pragma.replay.yaml b/tests/gold_tests/cache/replay/cache-control-pragma.replay.yaml index 01044254641..5cd57131789 100644 --- a/tests/gold_tests/cache/replay/cache-control-pragma.replay.yaml +++ b/tests/gold_tests/cache/replay/cache-control-pragma.replay.yaml @@ -74,105 +74,6 @@ sessions: fields: - [ Content-Length, { value: 5, as: equal}] - # Cache-Control: no-cache will not cache - - client-request: - method: "GET" - version: "1.1" - url: /cc/no-cache - headers: - fields: - - [ uuid, cc-no-cache] - - [ Host, example.com ] - - server-response: - status: 200 - reason: OK - headers: - fields: - - [ Content-Length, 4 ] - - [ Cache-Control, "no-cache" ] - - proxy-response: - status: 200 - headers: - fields: - - [ Content-Length, { value: 4, as: equal}] - # Re-request to make sure it was not cached - - client-request: - method: "GET" - version: "1.1" - url: /cc/no-cache - headers: - fields: - - [ uuid, cc-no-cache-verify] - - [ Host, example.com ] - - server-response: - status: 200 - reason: OK - headers: - fields: - # change content length to differentiate from the previous - # response to verify it was not cached. - - [ Content-Length, 5 ] - - [ Cache-Control, "no-cache" ] - - proxy-response: - status: 200 - headers: - fields: - - [ Content-Length, { value: 5, as: equal}] - - # Cache-Control: no-store also does not cache - - client-request: - method: "GET" - version: "1.1" - url: /cc/no-store - headers: - fields: - - [ uuid, cc-no-store] - - [ Host, example.com ] - - server-response: - status: 200 - reason: OK - headers: - fields: - - [ Content-Length, 4 ] - - [ Cache-Control, "no-cache" ] - - proxy-response: - status: 200 - headers: - fields: - - [ Content-Length, { value: 4, as: equal}] - # Re-request to make sure it was not cached - - client-request: - method: "GET" - version: "1.1" - url: /cc/no-cache - headers: - fields: - - [ uuid, cc-no-store-verify] - - [ Host, example.com ] - - server-response: - status: 200 - reason: OK - headers: - fields: - # change content length to differentiate from the previous - # response to verify it was not cached. - - [ Content-Length, 5 ] - - [ Cache-Control, "no-cache" ] - - proxy-response: - status: 200 - headers: - fields: - - [ Content-Length, { value: 5, as: equal}] - - # Pragma: no-cache is ignored if cache-control is specified - client-request: method: "GET" @@ -215,4 +116,3 @@ sessions: headers: fields: - [ Content-Length, { value: 4, as: equal}] - diff --git a/tests/gold_tests/cache/replay/cookie-all-but-text-with-excp.replay.yaml b/tests/gold_tests/cache/replay/cookie-all-but-text-with-excp.replay.yaml new file mode 100644 index 00000000000..77cefbc47fe --- /dev/null +++ b/tests/gold_tests/cache/replay/cookie-all-but-text-with-excp.replay.yaml @@ -0,0 +1,425 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# +# This replay file assumes that caching is enabled and +# proxy.config.http.cache.cache_responses_to_cookies is set to 4(cache cookie to +# responses for all but text types, except text type responses without +# Set-Cookie or with Cache-Control: public) +# +meta: + version: "1.0" + +sessions: + - transactions: + # Verify that response containing Set-Cookie with image content type is + # cached + - client-request: + method: "GET" + version: "1.1" + url: /cookie/set-cookie-img + headers: + fields: + - [uuid, set-cookie-img-response] + - [Host, example.com] + + server-response: + status: 200 + reason: OK + headers: + fields: + - [Content-Length, 4] + # image content type + - [Content-Type, "image/jpeg"] + - [Cache-Control, "max-age=5"] + - [Set-Cookie, "tasty_cookie=strawberry"] + + proxy-response: + status: 200 + headers: + fields: + - [Content-Length, { value: 4, as: equal }] + # Re-request to make sure the previous response was cached + - client-request: + # Add a delay so ATS has time to finish any caching IO for the + # previous transaction. + delay: 100ms + method: "GET" + version: "1.1" + url: /cookie/set-cookie-img + headers: + fields: + - [uuid, set-cookie-img-response-verify] + - [Host, example.com] + - [Cookie, "tasty_cookie=strawberry"] + + server-response: + status: 200 + reason: OK + headers: + fields: + # Use a different Content-Length to differentiate between two + # responses + - [Content-Length, 5] + + proxy-response: + status: 200 + headers: + fields: + # Verify this is cached response + - [Content-Length, { value: 4, as: equal }] + + # Verify that response containing Set-Cookie with video content type is + # cached + - client-request: + method: "GET" + version: "1.1" + url: /cookie/set-cookie-vid + headers: + fields: + - [uuid, set-cookie-vid-response] + - [Host, example.com] + + server-response: + status: 200 + reason: OK + headers: + fields: + - [Content-Length, 4] + # video content type + - [Content-Type, "video/mp4"] + - [Cache-Control, "max-age=5"] + - [Set-Cookie, "tasty_cookie=strawberry"] + + proxy-response: + status: 200 + headers: + fields: + - [Content-Length, { value: 4, as: equal }] + # Re-request to make sure the previous response was cached + - client-request: + # Add a delay so ATS has time to finish any caching IO for the + # previous transaction. + delay: 100ms + method: "GET" + version: "1.1" + url: /cookie/set-cookie-vid + headers: + fields: + - [uuid, set-cookie-vid-response-verify] + - [Host, example.com] + - [Cookie, "tasty_cookie=strawberry"] + + server-response: + status: 200 + reason: OK + headers: + fields: + # Use a different Content-Length to differentiate between two + # responses + - [Content-Length, 5] + + proxy-response: + status: 200 + headers: + fields: + # Verify this is cached response + - [Content-Length, { value: 4, as: equal }] + + # Verify that response containing Set-Cookie with text content type is not + # cached + - client-request: + method: "GET" + version: "1.1" + url: /cookie/set-cookie-text + headers: + fields: + - [uuid, set-cookie-text-response] + - [Host, example.com] + + server-response: + status: 200 + reason: OK + headers: + fields: + - [Content-Length, 4] + - [Content-Type, "text/html"] + - [Cache-Control, "max-age=5"] + - [Set-Cookie, "tasty_cookie=strawberry"] + + proxy-response: + status: 200 + headers: + fields: + - [Content-Length, { value: 4, as: equal }] + + # Re-request to make sure the previous response was not cached + - client-request: + # Add a delay so ATS has time to finish any caching IO for the + # previous transaction. + delay: 100ms + method: "GET" + version: "1.1" + url: /cookie/set-cookie-text + headers: + fields: + - [uuid, set-cookie-text-response-verify] + - [Host, example.com] + - [Cookie, "tasty_cookie=strawberry"] + + server-response: + status: 200 + reason: OK + headers: + fields: + # Use a different Content-Length to differentiate between two + # responses + - [Content-Length, 5] + + proxy-response: + status: 200 + headers: + fields: + # Verify this is new response from the server + - [Content-Length, { value: 5, as: equal }] + + # Verify response with image content type for a cookie-containing request + # is cached(since it's not text type) + - client-request: + method: "GET" + version: "1.1" + url: /cookie/img + headers: + fields: + - [uuid, cookie-img-response] + - [Host, example.com] + - [Cookie, "tasty_cookie=strawberry"] + + server-response: + status: 200 + reason: OK + headers: + fields: + - [Content-Length, 4] + # image content type + - [Content-Type, "image/jpeg"] + - [Cache-Control, "max-age=5"] + + proxy-response: + status: 200 + headers: + fields: + - [Content-Length, { value: 4, as: equal }] + # Re-request to make sure the previous response was cached + - client-request: + # Add a delay so ATS has time to finish any caching IO for the + # previous transaction. + delay: 100ms + method: "GET" + version: "1.1" + url: /cookie/img + headers: + fields: + - [uuid, cookie-img-response-verify] + - [Host, example.com] + - [Cookie, "tasty_cookie=strawberry"] + + server-response: + status: 200 + reason: OK + headers: + fields: + # Use a different Content-Length to differentiate between two + # responses + - [Content-Length, 5] + + proxy-response: + status: 200 + headers: + fields: + # Verify this is the cached response + - [Content-Length, { value: 4, as: equal }] + + # Verify response with video content type for a cookie-containing request + # is cached + - client-request: + method: "GET" + version: "1.1" + url: /cookie/vid + headers: + fields: + - [uuid, cookie-vid-response] + - [Host, example.com] + - [Cookie, "tasty_cookie=strawberry"] + + server-response: + status: 200 + reason: OK + headers: + fields: + - [Content-Length, 4] + # video content type + - [Content-Type, "video/mp4"] + - [Cache-Control, "max-age=5"] + + proxy-response: + status: 200 + headers: + fields: + - [Content-Length, { value: 4, as: equal }] + # Re-request to make sure the previous response was cached + - client-request: + # Add a delay so ATS has time to finish any caching IO for the + # previous transaction. + delay: 100ms + method: "GET" + version: "1.1" + url: /cookie/vid + headers: + fields: + - [uuid, cookie-vid-response-verify] + - [Host, example.com] + - [Cookie, "tasty_cookie=strawberry"] + + server-response: + status: 200 + reason: OK + headers: + fields: + # Use a different Content-Length to differentiate between two + # responses + - [Content-Length, 5] + + proxy-response: + status: 200 + headers: + fields: + # Verify this is the cached response + - [Content-Length, { value: 4, as: equal }] + + # Verify response with text content type for a cookie-containing request + # is also cached as the server response doesn't contain the Set-Cookie + # directive + - client-request: + method: "GET" + version: "1.1" + url: /cookie/text-response-no-set-cookie + headers: + fields: + - [uuid, cookie-response-text-no-set-cookie] + - [Host, example.com] + - [Cookie, "tasty_cookie=strawberry"] + + server-response: + status: 200 + reason: OK + headers: + fields: + # note this response doesn't contain the Set-Cookie directive + - [Content-Length, 4] + - [Content-Type, "text/html"] + - [Cache-Control, "max-age=5"] + proxy-response: + status: 200 + headers: + fields: + - [Content-Length, { value: 4, as: equal }] + # Re-request to make sure the previous response was cached + - client-request: + # Add a delay so ATS has time to finish any caching IO for the + # previous transaction. + delay: 100ms + method: "GET" + version: "1.1" + url: /cookie/text-response-no-set-cookie + headers: + fields: + - [uuid, cookie-response-text-no-set-cookie-verify] + - [Host, example.com] + - [Cookie, "tasty_cookie=strawberry"] + + server-response: + status: 200 + reason: OK + headers: + fields: + # Use a different Content-Length to differentiate between two + # responses + - [Content-Length, 5] + + proxy-response: + status: 200 + headers: + fields: + # Verify this is the cached response + - [Content-Length, { value: 4, as: equal }] + + # Verify response with text content type for a cookie-containing request + # is cached as the response contain Cache-Control: public + - client-request: + method: "GET" + version: "1.1" + url: /cookie/text-response-has-cc-public + headers: + fields: + - [uuid, cookie-response-text-has-cc-public] + - [Host, example.com] + - [Cookie, "tasty_cookie=strawberry"] + + server-response: + status: 200 + reason: OK + headers: + fields: + - [Content-Length, 4] + - [Content-Type, "text/html"] + # note this response contains the Cache-Control: public + - [Cache-Control, "max-age=5,public"] + + proxy-response: + status: 200 + headers: + fields: + - [Content-Length, { value: 4, as: equal }] + # Re-request to make sure the previous response was cached + - client-request: + # Add a delay so ATS has time to finish any caching IO for the + # previous transaction. + delay: 100ms + method: "GET" + version: "1.1" + url: /cookie/text-response-has-cc-public + headers: + fields: + - [uuid, cookie-response-text-has-cc-public-verify] + - [Host, example.com] + - [Cookie, "tasty_cookie=strawberry"] + + server-response: + status: 200 + reason: OK + headers: + fields: + # Use a different Content-Length to differentiate between two + # responses + - [Content-Length, 5] + + proxy-response: + status: 200 + headers: + fields: + # Verify this is the cached response + - [Content-Length, { value: 4, as: equal }] diff --git a/tests/gold_tests/cache/replay/cookie-all-but-text.replay.yaml b/tests/gold_tests/cache/replay/cookie-all-but-text.replay.yaml new file mode 100644 index 00000000000..aa8a6e2a56a --- /dev/null +++ b/tests/gold_tests/cache/replay/cookie-all-but-text.replay.yaml @@ -0,0 +1,366 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# +# This replay file assumes that caching is enabled and +# proxy.config.http.cache.cache_responses_to_cookies is set to 3(cache all but +# text types) +# +meta: + version: "1.0" + +sessions: + - transactions: + # Verify that response containing Set-Cookie with image content type is + # cached + - client-request: + method: "GET" + version: "1.1" + url: /cookie/set-cookie-img + headers: + fields: + - [uuid, set-cookie-img-response] + - [Host, example.com] + + server-response: + status: 200 + reason: OK + headers: + fields: + - [Content-Length, 4] + # image content type + - [Content-Type, "image/jpeg"] + - [Cache-Control, "max-age=5"] + - [Set-Cookie, "tasty_cookie=strawberry"] + + proxy-response: + status: 200 + headers: + fields: + - [Content-Length, { value: 4, as: equal }] + # Re-request to make sure the previous response was cached + - client-request: + # Add a delay so ATS has time to finish any caching IO for the + # previous transaction. + delay: 100ms + method: "GET" + version: "1.1" + url: /cookie/set-cookie-img + headers: + fields: + - [uuid, set-cookie-img-response-verify] + - [Host, example.com] + - [Cookie, "tasty_cookie=strawberry"] + + server-response: + status: 200 + reason: OK + headers: + fields: + # Use a different Content-Length to differentiate between two responses + - [Content-Length, 5] + + proxy-response: + status: 200 + headers: + fields: + # Verify this is the cached response + - [Content-Length, { value: 4, as: equal }] + + # Verify that response containing Set-Cookie with video content type is + # cached + - client-request: + method: "GET" + version: "1.1" + url: /cookie/set-cookie-vid + headers: + fields: + - [uuid, set-cookie-vid-response] + - [Host, example.com] + + server-response: + status: 200 + reason: OK + headers: + fields: + - [Content-Length, 4] + # video content type + - [Content-Type, "video/mp4"] + - [Cache-Control, "max-age=5"] + - [Set-Cookie, "tasty_cookie=strawberry"] + + proxy-response: + status: 200 + headers: + fields: + - [Content-Length, { value: 4, as: equal }] + # Re-request to make sure the previous response was cached + - client-request: + # Add a delay so ATS has time to finish any caching IO for the + # previous transaction. + delay: 100ms + method: "GET" + version: "1.1" + url: /cookie/set-cookie-vid + headers: + fields: + - [uuid, set-cookie-vid-response-verify] + - [Host, example.com] + - [Cookie, "tasty_cookie=strawberry"] + + server-response: + status: 200 + reason: OK + headers: + fields: + # Use a different Content-Length to differentiate between two + # responses + - [Content-Length, 5] + + proxy-response: + status: 200 + headers: + fields: + # Verify this is the cached response + - [Content-Length, { value: 4, as: equal }] + + # Verify that response containing Set-Cookie with text content type is not + # cached + - client-request: + method: "GET" + version: "1.1" + url: /cookie/set-cookie-text + headers: + fields: + - [uuid, set-cookie-text-response] + - [Host, example.com] + + server-response: + status: 200 + reason: OK + headers: + fields: + - [Content-Length, 4] + - [Content-Type, "text/html"] + - [Cache-Control, "max-age=5"] + - [Set-Cookie, "tasty_cookie=strawberry"] + + proxy-response: + status: 200 + headers: + fields: + - [Content-Length, { value: 4, as: equal }] + + # Re-request to make sure the previous response was not cached + - client-request: + # Add a delay so ATS has time to finish any caching IO for the + # previous transaction. + delay: 100ms + method: "GET" + version: "1.1" + url: /cookie/set-cookie-text + headers: + fields: + - [uuid, set-cookie-text-response-verify] + - [Host, example.com] + - [Cookie, "tasty_cookie=strawberry"] + + server-response: + status: 200 + reason: OK + headers: + fields: + # Use a different Content-Length to differentiate between two + # responses + - [Content-Length, 5] + + proxy-response: + status: 200 + headers: + fields: + # Verify this is new response from the server + - [Content-Length, { value: 5, as: equal }] + + # Verify response with image content type for a cookie-containing request + # is cached + - client-request: + method: "GET" + version: "1.1" + url: /cookie/cookie-img + headers: + fields: + - [uuid, cookie-img-response] + - [Host, example.com] + - [Cookie, "tasty_cookie=strawberry"] + + server-response: + status: 200 + reason: OK + headers: + fields: + - [Content-Length, 4] + # image content type + - [Content-Type, "image/jpeg"] + - [Cache-Control, "max-age=5"] + + proxy-response: + status: 200 + headers: + fields: + - [Content-Length, { value: 4, as: equal }] + # Re-request to make sure the previous response was cached + - client-request: + # Add a delay so ATS has time to finish any caching IO for the + # previous transaction. + delay: 100ms + method: "GET" + version: "1.1" + url: /cookie/cookie-img + headers: + fields: + - [uuid, cookie-img-response-verify] + - [Host, example.com] + - [Cookie, "tasty_cookie=strawberry"] + + server-response: + status: 200 + reason: OK + headers: + fields: + # Use a different Content-Length to differentiate between two + # responses + - [Content-Length, 5] + + proxy-response: + status: 200 + headers: + fields: + # Verify this is the cached response + - [Content-Length, { value: 4, as: equal }] + + # Verify response with video content type for a cookie-containing request + # is cached + - client-request: + method: "GET" + version: "1.1" + url: /cookie/cookie-vid + headers: + fields: + - [uuid, cookie-vid-response] + - [Host, example.com] + - [Cookie, "tasty_cookie=strawberry"] + + server-response: + status: 200 + reason: OK + headers: + fields: + - [Content-Length, 4] + # video content type + - [Content-Type, "video/mp4"] + - [Cache-Control, "max-age=5"] + + proxy-response: + status: 200 + headers: + fields: + - [Content-Length, { value: 4, as: equal }] + # Re-request to make sure the previous response was cached + - client-request: + # Add a delay so ATS has time to finish any caching IO for the + # previous transaction. + delay: 100ms + method: "GET" + version: "1.1" + url: /cookie/cookie-vid + headers: + fields: + - [uuid, cookie-vid-response-verify] + - [Host, example.com] + - [Cookie, "tasty_cookie=strawberry"] + + server-response: + status: 200 + reason: OK + headers: + fields: + # Use a different Content-Length to differentiate between two + # responses + - [Content-Length, 5] + + proxy-response: + status: 200 + headers: + fields: + # Verify this is the cached response + - [Content-Length, { value: 4, as: equal }] + + # Verify response with text content type for a cookie-containing request + # is not cached + - client-request: + method: "GET" + version: "1.1" + url: /cookie/cookie-text + headers: + fields: + - [uuid, cookie-response] + - [Host, example.com] + - [Cookie, "tasty_cookie=strawberry"] + + server-response: + status: 200 + reason: OK + headers: + fields: + - [Content-Length, 4] + # text content type + - [Content-Type, "text/html"] + - [Cache-Control, "max-age=5"] + + proxy-response: + status: 200 + headers: + fields: + - [Content-Length, { value: 4, as: equal }] + # Re-request to make sure the previous response was not cached + - client-request: + # Add a delay so ATS has time to finish any caching IO for the + # previous transaction. + delay: 100ms + method: "GET" + version: "1.1" + url: /cookie/cookie-text + headers: + fields: + - [uuid, cookie-response-verify] + - [Host, example.com] + - [Cookie, "tasty_cookie=strawberry"] + + server-response: + status: 200 + reason: OK + headers: + fields: + # Use a different Content-Length to differentiate between two + # responses + - [Content-Length, 5] + + proxy-response: + status: 200 + headers: + fields: + # Verify this is the new response from the server + - [Content-Length, { value: 5, as: equal }] diff --git a/tests/gold_tests/cache/replay/cookie-bypass-cache.replay.yaml b/tests/gold_tests/cache/replay/cookie-bypass-cache.replay.yaml new file mode 100644 index 00000000000..eda11285549 --- /dev/null +++ b/tests/gold_tests/cache/replay/cookie-bypass-cache.replay.yaml @@ -0,0 +1,250 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# +# This replay file assumes that caching is enabled and +# proxy.config.http.cache.cache_responses_to_cookies is set to 0(bypass cache +# for any responses to cookie) +# +meta: + version: "1.0" + +sessions: + - transactions: + # Verify that response containing Set-Cookie with text content type is not + # cached + - client-request: + method: "GET" + version: "1.1" + url: /cookie/set-cookie-text + headers: + fields: + - [uuid, set-cookie-text-response] + - [Host, example.com] + + server-response: + status: 200 + reason: OK + headers: + fields: + - [Content-Length, 4] + - [Content-Type, "text/html"] + - [Cache-Control, "max-age=5"] + - [Set-Cookie, "tasty_cookie=strawberry"] + + proxy-response: + status: 200 + headers: + fields: + - [Content-Length, { value: 4, as: equal }] + + # Re-request to make sure the previous response was not cached + - client-request: + # Add a delay so ATS has time to finish any caching IO for the + # previous transaction. + delay: 100ms + method: "GET" + version: "1.1" + url: /cookie/set-cookie-text + headers: + fields: + - [uuid, set-cookie-text-response-verify] + - [Host, example.com] + - [Cookie, "tasty_cookie=strawberry"] + + server-response: + status: 200 + reason: OK + headers: + fields: + # Use a different Content-Length to differentiate between two + # responses + - [Content-Length, 5] + + proxy-response: + status: 200 + headers: + fields: + # Verify this is new response from the server + - [Content-Length, { value: 5, as: equal }] + + # Verify that response containing Set-Cookie with image content type is + # not cached + - client-request: + method: "GET" + version: "1.1" + url: /cookie/set-cookie-img + headers: + fields: + - [uuid, set-cookie-img-response] + - [Host, example.com] + + server-response: + status: 200 + reason: OK + headers: + fields: + - [Content-Length, 4] + # image content type + - [Content-Type, "image/jpeg"] + - [Cache-Control, "max-age=5"] + - [Set-Cookie, "tasty_cookie=strawberry"] + + proxy-response: + status: 200 + headers: + fields: + - [Content-Length, { value: 4, as: equal }] + # Re-request to make sure the previous response was not cached + - client-request: + # Add a delay so ATS has time to finish any caching IO for the + # previous transaction. + delay: 100ms + method: "GET" + version: "1.1" + url: /cookie/set-cookie-img + headers: + fields: + - [uuid, set-cookie-img-response-verify] + - [Host, example.com] + - [Cookie, "tasty_cookie=strawberry"] + + server-response: + status: 200 + reason: OK + headers: + fields: + # Use a different Content-Length to differentiate between two responses + - [Content-Length, 5] + + proxy-response: + status: 200 + headers: + fields: + # Verify this is new response from the server + - [Content-Length, { value: 5, as: equal }] + + # Verify response with text content type for a cookie-containing request + # is not cached + - client-request: + method: "GET" + version: "1.1" + url: /cookie/cookie-text + headers: + fields: + - [uuid, cookie-response] + - [Host, example.com] + - [Cookie, "tasty_cookie=strawberry"] + + server-response: + status: 200 + reason: OK + headers: + fields: + - [Content-Length, 4] + - [Content-Type, "text/html"] + - [Cache-Control, "max-age=5"] + + proxy-response: + status: 200 + headers: + fields: + - [Content-Length, { value: 4, as: equal }] + # Re-request to make sure the previous response was not cached + - client-request: + # Add a delay so ATS has time to finish any caching IO for the + # previous transaction. + delay: 100ms + method: "GET" + version: "1.1" + url: /cookie/cookie-text + headers: + fields: + - [uuid, cookie-response-verify] + - [Host, example.com] + - [Cookie, "tasty_cookie=strawberry"] + + server-response: + status: 200 + reason: OK + headers: + fields: + # Use a different Content-Length to differentiate between two + # responses + - [Content-Length, 5] + + proxy-response: + status: 200 + headers: + fields: + # Verify this is the new response from the server + - [Content-Length, { value: 5, as: equal }] + + # Verify response with image content type for a cookie-containing request + # is not cached + - client-request: + method: "GET" + version: "1.1" + url: /cookie/cookie-img + headers: + fields: + - [uuid, cookie-img-response] + - [Host, example.com] + - [Cookie, "tasty_cookie=strawberry"] + + server-response: + status: 200 + reason: OK + headers: + fields: + - [Content-Length, 4] + # image content type + - [Content-Type, "image/jpeg"] + - [Cache-Control, "max-age=5"] + + proxy-response: + status: 200 + headers: + fields: + - [Content-Length, { value: 4, as: equal }] + # Re-request to make sure the previous response was not cached + - client-request: + # Add a delay so ATS has time to finish any caching IO for the + # previous transaction. + delay: 100ms + method: "GET" + version: "1.1" + url: /cookie/cookie-img + headers: + fields: + - [uuid, cookie-img-response-verify] + - [Host, example.com] + - [Cookie, "tasty_cookie=strawberry"] + + server-response: + status: 200 + reason: OK + headers: + fields: + # Use a different Content-Length to differentiate between two responses + - [Content-Length, 5] + + proxy-response: + status: 200 + headers: + fields: + # Verify this is the new response from the server + - [Content-Length, { value: 5, as: equal }] diff --git a/tests/gold_tests/cache/replay/cookie-cache-img-only.replay.yaml b/tests/gold_tests/cache/replay/cookie-cache-img-only.replay.yaml new file mode 100644 index 00000000000..2b377eb2322 --- /dev/null +++ b/tests/gold_tests/cache/replay/cookie-cache-img-only.replay.yaml @@ -0,0 +1,253 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# +# This replay file assumes that caching is enabled and +# proxy.config.http.cache.cache_responses_to_cookies is set to 2(cache only for +# image types) +# +meta: + version: "1.0" + +sessions: + - transactions: + # Verify that response containing Set-Cookie with text content type is not + # cached + - client-request: + method: "GET" + version: "1.1" + url: /cookie/set-cookie-text + headers: + fields: + - [uuid, set-cookie-text-response] + - [Host, example.com] + + server-response: + status: 200 + reason: OK + headers: + fields: + - [Content-Length, 4] + - [Content-Type, "text/html"] + - [Cache-Control, "max-age=5"] + - [Set-Cookie, "tasty_cookie=strawberry"] + + proxy-response: + status: 200 + headers: + fields: + - [Content-Length, { value: 4, as: equal }] + + # Re-request to make sure the previous response was not cached + - client-request: + # Add a delay so ATS has time to finish any caching IO for the + # previous transaction. + delay: 100ms + method: "GET" + version: "1.1" + url: /cookie/set-cookie-text + headers: + fields: + - [uuid, set-cookie-text-response-verify] + - [Host, example.com] + - [Cookie, "tasty_cookie=strawberry"] + + server-response: + status: 200 + reason: OK + headers: + fields: + # Use a different Content-Length to differentiate between two + # responses + - [Content-Length, 5] + + proxy-response: + status: 200 + headers: + fields: + # Verify this is new response from the server + - [Content-Length, { value: 5, as: equal }] + + # Verify that response containing Set-Cookie with image content type is + # cached + - client-request: + method: "GET" + version: "1.1" + url: /cookie/set-cookie-img + headers: + fields: + - [uuid, set-cookie-img-response] + - [Host, example.com] + + server-response: + status: 200 + reason: OK + headers: + fields: + - [Content-Length, 4] + # image content type + - [Content-Type, "image/jpeg"] + - [Cache-Control, "max-age=5"] + - [Set-Cookie, "tasty_cookie=strawberry"] + + proxy-response: + status: 200 + headers: + fields: + - [Content-Length, { value: 4, as: equal }] + # Re-request to make sure the previous response was cached + - client-request: + # Add a delay so ATS has time to finish any caching IO for the + # previous transaction. + delay: 100ms + method: "GET" + version: "1.1" + url: /cookie/set-cookie-img + headers: + fields: + - [uuid, set-cookie-img-response-verify] + - [Host, example.com] + - [Cookie, "tasty_cookie=strawberry"] + + server-response: + status: 200 + reason: OK + headers: + fields: + # Use a different Content-Length to differentiate between two + # responses + - [Content-Length, 5] + + proxy-response: + status: 200 + headers: + fields: + # Verify this is cached response + - [Content-Length, { value: 4, as: equal }] + + # Verify response with text content type for a cookie-containing request + # is not cached + - client-request: + method: "GET" + version: "1.1" + url: /cookie/cookie-text + headers: + fields: + - [uuid, cookie-response] + - [Host, example.com] + - [Cookie, "tasty_cookie=strawberry"] + + server-response: + status: 200 + reason: OK + headers: + fields: + - [Content-Length, 4] + # text content type + - [Content-Type, "text/html"] + - [Cache-Control, "max-age=5"] + + proxy-response: + status: 200 + headers: + fields: + - [Content-Length, { value: 4, as: equal }] + # Re-request to make sure the previous response was not cached + - client-request: + # Add a delay so ATS has time to finish any caching IO for the + # previous transaction. + delay: 100ms + method: "GET" + version: "1.1" + url: /cookie/cookie-text + headers: + fields: + - [uuid, cookie-response-verify] + - [Host, example.com] + - [Cookie, "tasty_cookie=strawberry"] + + server-response: + status: 200 + reason: OK + headers: + fields: + # Use a different Content-Length to differentiate between two + # responses + - [Content-Length, 5] + + proxy-response: + status: 200 + headers: + fields: + # Verify this is the new response from the server + - [Content-Length, { value: 5, as: equal }] + + # Verify response with image content type for a cookie-containing request + # is cached + - client-request: + method: "GET" + version: "1.1" + url: /cookie/cookie-img + headers: + fields: + - [uuid, cookie-img-response] + - [Host, example.com] + - [Cookie, "tasty_cookie=strawberry"] + + server-response: + status: 200 + reason: OK + headers: + fields: + - [Content-Length, 4] + # image content type + - [Content-Type, "image/jpeg"] + - [Cache-Control, "max-age=5"] + + proxy-response: + status: 200 + headers: + fields: + - [Content-Length, { value: 4, as: equal }] + # Re-request to make sure the previous response was cached + - client-request: + # Add a delay so ATS has time to finish any caching IO for the + # previous transaction. + delay: 100ms + method: "GET" + version: "1.1" + url: /cookie/cookie-img + headers: + fields: + - [uuid, cookie-img-response-verify] + - [Host, example.com] + - [Cookie, "tasty_cookie=strawberry"] + + server-response: + status: 200 + reason: OK + headers: + fields: + # Use a different Content-Length to differentiate between two + # responses + - [Content-Length, 5] + + proxy-response: + status: 200 + headers: + fields: + # Verify this is the cached response from the server + - [Content-Length, { value: 4, as: equal }] diff --git a/tests/gold_tests/cache/replay/cookie-default.replay.yaml b/tests/gold_tests/cache/replay/cookie-default.replay.yaml new file mode 100644 index 00000000000..c9773bc5feb --- /dev/null +++ b/tests/gold_tests/cache/replay/cookie-default.replay.yaml @@ -0,0 +1,252 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# +# This replay file assumes that caching is enabled and +# proxy.config.http.cache.cache_responses_to_cookies is set to 1(current +# default, cache for any content-type) +# +meta: + version: "1.0" + +sessions: + - transactions: + # Verify the response containing Set-Cookie with text content type is + # cached + - client-request: + method: "GET" + version: "1.1" + url: /cookie/set-cookie-text + headers: + fields: + - [uuid, set-cookie-text-response] + - [Host, example.com] + + server-response: + status: 200 + reason: OK + headers: + fields: + - [Content-Length, 4] + - [Content-Type, "text/html"] + - [Cache-Control, "max-age=5"] + - [Set-Cookie, "tasty_cookie=strawberry"] + + proxy-response: + status: 200 + headers: + fields: + - [Content-Length, { value: 4, as: equal }] + + # Re-request to make sure the previous response was cached + - client-request: + # Add a delay so ATS has time to finish any caching IO for the + # previous transaction. + delay: 100ms + method: "GET" + version: "1.1" + url: /cookie/set-cookie-text + headers: + fields: + - [uuid, set-cookie-text-response-verify] + - [Host, example.com] + - [Cookie, "tasty_cookie=strawberry"] + + server-response: + status: 200 + reason: OK + headers: + fields: + # Use a different Content-Length to differentiate between two + # responses + - [Content-Length, 5] + + proxy-response: + status: 200 + headers: + fields: + # Verify this is the cached response + - [Content-Length, { value: 4, as: equal }] + + # Verify the response containing Set-Cookie with image content type is + # cached + - client-request: + method: "GET" + version: "1.1" + url: /cookie/set-cookie-img + headers: + fields: + - [uuid, set-cookie-img-response] + - [Host, example.com] + + server-response: + status: 200 + reason: OK + headers: + fields: + - [Content-Length, 4] + # image content type + - [Content-Type, "image/jpeg"] + - [Cache-Control, "max-age=5"] + - [Set-Cookie, "tasty_cookie=strawberry"] + + proxy-response: + status: 200 + headers: + fields: + - [Content-Length, { value: 4, as: equal }] + # Re-request to make sure the previous response was cached + - client-request: + # Add a delay so ATS has time to finish any caching IO for the + # previous transaction. + delay: 100ms + method: "GET" + version: "1.1" + url: /cookie/set-cookie-img + headers: + fields: + - [uuid, set-cookie-img-response-verify] + - [Host, example.com] + - [Cookie, "tasty_cookie=strawberry"] + + server-response: + status: 200 + reason: OK + headers: + fields: + # Use a different Content-Length to differentiate between two + # responses + - [Content-Length, 5] + + proxy-response: + status: 200 + headers: + fields: + # Verify this is the cached response + - [Content-Length, { value: 4, as: equal }] + + # Verify the response with text content type for a cookie-containing + # request is cached + - client-request: + method: "GET" + version: "1.1" + url: /cookie/text + headers: + fields: + - [uuid, cookie-text-response] + - [Host, example.com] + - [Cookie, "tasty_cookie=strawberry"] + + server-response: + status: 200 + reason: OK + headers: + fields: + - [Content-Length, 4] + - [Content-Type, "text/html"] + - [Cache-Control, "max-age=5"] + + proxy-response: + status: 200 + headers: + fields: + - [Content-Length, { value: 4, as: equal }] + # Re-request to make sure the previous response was cached + - client-request: + # Add a delay so ATS has time to finish any caching IO for the + # previous transaction. + delay: 100ms + method: "GET" + version: "1.1" + url: /cookie/text + headers: + fields: + - [uuid, cookie-text-response-verify] + - [Host, example.com] + - [Cookie, "tasty_cookie=strawberry"] + + server-response: + status: 200 + reason: OK + headers: + fields: + # Use a different Content-Length to differentiate between two + # responses + - [Content-Length, 5] + + proxy-response: + status: 200 + headers: + fields: + # Verify this is the cached response + - [Content-Length, { value: 4, as: equal }] + + # Verify the response with image content type for a cookie-containing + # request is cached + - client-request: + method: "GET" + version: "1.1" + url: /cookie/img + headers: + fields: + - [uuid, cookie-img-response] + - [Host, example.com] + - [Cookie, "tasty_cookie=strawberry"] + + server-response: + status: 200 + reason: OK + headers: + fields: + - [Content-Length, 4] + # image content type + - [Content-Type, "image/jpeg"] + - [Cache-Control, "max-age=5"] + + proxy-response: + status: 200 + headers: + fields: + - [Content-Length, { value: 4, as: equal }] + # Re-request to make sure the previous response was cached + - client-request: + # Add a delay so ATS has time to finish any caching IO for the + # previous transaction. + delay: 100ms + method: "GET" + version: "1.1" + url: /cookie/img + headers: + fields: + - [uuid, cookie-img-response-verify] + - [Host, example.com] + - [Cookie, "tasty_cookie=strawberry"] + + server-response: + status: 200 + reason: OK + headers: + fields: + # Use a different Content-Length to differentiate between two + # responses + - [Content-Length, 5] + + proxy-response: + status: 200 + headers: + fields: + # Verify this is the cached response + - [Content-Length, { value: 4, as: equal }] diff --git a/tests/gold_tests/cache/replay/request-cache-control-default.replay.yaml b/tests/gold_tests/cache/replay/request-cache-control-default.replay.yaml new file mode 100644 index 00000000000..94d3bde4afe --- /dev/null +++ b/tests/gold_tests/cache/replay/request-cache-control-default.replay.yaml @@ -0,0 +1,131 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# +# This replay file assumes that caching is enabled and +# proxy.config.http.cache.ignore_client_no_cache is set to 1(current default) +# +meta: + version: "1.0" + +sessions: + - transactions: + # Populating the cache + - client-request: + method: "GET" + version: "1.1" + url: /cc/request-no-cache + headers: + fields: + - [uuid, request-cc-no-cache] + - [Host, example.com] + + server-response: + status: 200 + reason: OK + headers: + fields: + - [Content-Length, 4] + - [Cache-Control, "max-age=5"] + + proxy-response: + status: 200 + headers: + fields: + - [Content-Length, { value: 4, as: equal }] + # Re-request and verify that Cache-Control: no-cache in the request is + # ignored by making sure cached response was used + - client-request: + # Add a delay so ATS has time to finish any caching IO for the + # previous transaction. + delay: 100ms + method: "GET" + version: "1.1" + url: /cc/request-no-cache + headers: + fields: + - [uuid, request-cc-no-cache-verify] + - [Host, example.com] + - [Cache-Control, "no-cache"] + + server-response: + status: 200 + reason: OK + headers: + fields: + # change content length to differentiate from the previous + # response to verify the cached response is used + - [Content-Length, 5] + + proxy-response: + status: 200 + headers: + fields: + # Verify that this is the cached response + - [Content-Length, { value: 4, as: equal }] + + # Verify that Cache-Control: no-store in the request is ignored + - client-request: + method: "GET" + version: "1.1" + url: /cc/request-no-store + headers: + fields: + - [uuid, request-cc-no-store] + - [Host, example.com] + - [Cache-Control, "no-store"] + + server-response: + status: 200 + reason: OK + headers: + fields: + - [Content-Length, 4] + - [Cache-Control, "max-age=5"] + + proxy-response: + status: 200 + headers: + fields: + - [Content-Length, { value: 4, as: equal }] + # Re-request to make sure the previous response was cached despite the + # no-store directive in the previous request + - client-request: + # Add a delay so ATS has time to finish any caching IO for the + # previous transaction. + delay: 100ms + method: "GET" + version: "1.1" + url: /cc/request-no-store + headers: + fields: + - [uuid, request-cc-no-store-verify] + - [Host, example.com] + + server-response: + status: 200 + reason: OK + headers: + fields: + # change content length to differentiate from the previous + # response + - [Content-Length, 5] + + proxy-response: + status: 200 + headers: + fields: + - [Content-Length, { value: 4, as: equal }] diff --git a/tests/gold_tests/cache/replay/request-cache-control-honor-client.replay.yaml b/tests/gold_tests/cache/replay/request-cache-control-honor-client.replay.yaml new file mode 100644 index 00000000000..9340ed66538 --- /dev/null +++ b/tests/gold_tests/cache/replay/request-cache-control-honor-client.replay.yaml @@ -0,0 +1,133 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# +# This replay file assumes that caching is enabled and +# proxy.config.http.cache.ignore_client_no_cache is set to 0(honoring the client +# requests to bypass the cache) +# +meta: + version: "1.0" + +sessions: + - transactions: + # Populating the cache + - client-request: + method: "GET" + version: "1.1" + url: /cc/request-no-cache + headers: + fields: + - [uuid, request-cc-no-cache] + - [Host, example.com] + + server-response: + status: 200 + reason: OK + headers: + fields: + - [Content-Length, 4] + - [Cache-Control, "max-age=5"] + + proxy-response: + status: 200 + headers: + fields: + - [Content-Length, { value: 4, as: equal }] + # Re-request and verify that Cache-Control: no-cache in the request is + # honored by making sure non-cached response was used + - client-request: + # Add a delay so ATS has time to finish any caching IO for the + # previous transaction. + delay: 100ms + method: "GET" + version: "1.1" + url: /cc/request-no-cache + headers: + fields: + - [uuid, request-cc-no-cache-verify] + - [Host, example.com] + - [Cache-Control, "no-cache"] + + server-response: + status: 200 + reason: OK + headers: + fields: + # change content length to differentiate from the previous + # response to verify the non-cached response is returned + - [Content-Length, 5] + + proxy-response: + status: 200 + headers: + fields: + # Verify this is the new response from the server + - [Content-Length, { value: 5, as: equal }] + + # Verify that Cache-Control: no-store in the request is honored + - client-request: + method: "GET" + version: "1.1" + url: /cc/request-no-store + headers: + fields: + - [uuid, request-cc-no-store] + - [Host, example.com] + - [Cache-Control, "no-store"] + + server-response: + status: 200 + reason: OK + headers: + fields: + - [Content-Length, 4] + - [Cache-Control, "max-age=5"] + + proxy-response: + status: 200 + headers: + fields: + - [Content-Length, { value: 4, as: equal }] + # Re-request and verify that Cache-Control: no-store in the previous + # request is honored by making sure the previous response is not cached + - client-request: + # Add a delay so ATS has time to finish any caching IO for the + # previous transaction. + delay: 100ms + method: "GET" + version: "1.1" + url: /cc/request-no-store + headers: + fields: + - [uuid, request-cc-no-store-verify] + - [Host, example.com] + + server-response: + status: 200 + reason: OK + headers: + fields: + # change content length to differentiate from the previous + # response to verify it was not cached. + - [Content-Length, 5] + + eroxy-response: + status: 200 + headers: + fields: + # Verify this is the new response from the server + - [Content-Length, { value: 5, as: equal }] diff --git a/tests/gold_tests/cache/replay/response-cache-control-default.replay.yaml b/tests/gold_tests/cache/replay/response-cache-control-default.replay.yaml new file mode 100644 index 00000000000..b87ad86ad56 --- /dev/null +++ b/tests/gold_tests/cache/replay/response-cache-control-default.replay.yaml @@ -0,0 +1,132 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# +# This replay file assumes that caching is enabled and +# proxy.config.http.cache.ignore_server_no_cache is set to 0(current default, +# meaning the cache-control directives in responses to bypass the cache is +# honored) +meta: + version: "1.0" + +sessions: + - transactions: + # Verify Cache-Control: no-cache in response is honored + - client-request: + method: "GET" + version: "1.1" + url: /cc/response-no-cache + headers: + fields: + - [uuid, response-cc-no-cache] + - [Host, example.com] + + server-response: + status: 200 + reason: OK + headers: + fields: + - [Content-Length, 4] + - [Cache-Control, "max-age=5"] + - [Cache-Control, "no-cache"] + + proxy-response: + status: 200 + headers: + fields: + - [Content-Length, { value: 4, as: equal }] + # Re-request and make sure non-cached response is used, verifying that + # Cache-Control: no-cache in the previous response is honored + - client-request: + # Add a delay so ATS has time to finish any caching IO for the + # previous transaction. + delay: 100ms + method: "GET" + version: "1.1" + url: /cc/response-no-cache + headers: + fields: + - [uuid, response-cc-no-cache-verify] + - [Host, example.com] + + server-response: + status: 200 + reason: OK + headers: + fields: + # change content length to differentiate from the previous + # response to verify the non-cached response is returned + - [Content-Length, 5] + + proxy-response: + status: 200 + headers: + fields: + # make sure this is a non-cached response + - [Content-Length, { value: 5, as: equal }] + + # Verify that Cache-Control: no-store in the response is honored + - client-request: + method: "GET" + version: "1.1" + url: /cc/response-no-store + headers: + fields: + - [uuid, response-cc-no-store] + - [Host, example.com] + + server-response: + status: 200 + reason: OK + headers: + fields: + - [Content-Length, 4] + - [Cache-Control, "max-age=5"] + - [Cache-Control, "no-store"] + + proxy-response: + status: 200 + headers: + fields: + - [Content-Length, { value: 4, as: equal }] + # Re-request to make sure the response was not cached + - client-request: + # Add a delay so ATS has time to finish any caching IO for the + # previous transaction. + delay: 100ms + method: "GET" + version: "1.1" + url: /cc/response-no-store + headers: + fields: + - [uuid, response-cc-no-store-verify] + - [Host, example.com] + + server-response: + status: 200 + reason: OK + headers: + fields: + # change content length to differentiate from the previous + # response to verify it was not cached. + - [Content-Length, 5] + + proxy-response: + status: 200 + headers: + fields: + # Verify this is the new response from the server + - [Content-Length, { value: 5, as: equal }] diff --git a/tests/gold_tests/cache/replay/response-cache-control-ignored.replay.yaml b/tests/gold_tests/cache/replay/response-cache-control-ignored.replay.yaml new file mode 100644 index 00000000000..2380e4a34de --- /dev/null +++ b/tests/gold_tests/cache/replay/response-cache-control-ignored.replay.yaml @@ -0,0 +1,132 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# +# This replay file assumes that caching is enabled and +# proxy.config.http.cache.ignore_server_no_cache is set to 1(meaning the +# cache-control directives in responses to bypass the cache is ignored) +meta: + version: "1.0" + +sessions: + - transactions: + # Verify the no-cache in response is ignored and the response is cached + - client-request: + method: "GET" + version: "1.1" + url: /cc/response-no-cache + headers: + fields: + - [uuid, response-cc-no-cache] + - [Host, example.com] + + server-response: + status: 200 + reason: OK + headers: + fields: + - [Content-Length, 4] + - [Cache-Control, "max-age=5"] + - [Cache-Control, "no-cache"] + + proxy-response: + status: 200 + headers: + fields: + - [Content-Length, { value: 4, as: equal }] + # Re-request and make sure cached response is used, verifying that + # Cache-Control: no-cache in the response is ignored + - client-request: + # Add a delay so ATS has time to finish any caching IO for the + # previous transaction. + delay: 100ms + method: "GET" + version: "1.1" + url: /cc/response-no-cache + headers: + fields: + - [uuid, response-cc-no-cache-verify] + - [Host, example.com] + + server-response: + status: 200 + reason: OK + headers: + fields: + # change content length to differentiate from the previous + # response to verify the non-cached response is returned + - [Content-Length, 5] + + proxy-response: + status: 200 + headers: + fields: + # make sure this is a cached response + - [Content-Length, { value: 4, as: equal }] + + # Verify that Cache-Control: no-store in the response is ignored and the + # response is cached + - client-request: + method: "GET" + version: "1.1" + url: /cc/response-no-store + headers: + fields: + - [uuid, response-cc-no-store] + - [Host, example.com] + + server-response: + status: 200 + reason: OK + headers: + fields: + - [Content-Length, 4] + - [Cache-Control, "max-age=5"] + - [Cache-Control, "no-store"] + + proxy-response: + status: 200 + headers: + fields: + - [Content-Length, { value: 4, as: equal }] + # Re-request to make sure it was cached + - client-request: + # Add a delay so ATS has time to finish any caching IO for the + # previous transaction. + delay: 100ms + method: "GET" + version: "1.1" + url: /cc/response-no-store + headers: + fields: + - [uuid, response-cc-no-store-verify] + - [Host, example.com] + + server-response: + status: 200 + reason: OK + headers: + fields: + # change content length to differentiate from the previous + # response to verify it was not cached. + - [Content-Length, 5] + + proxy-response: + status: 200 + headers: + fields: + # Verify this is the cached response + - [Content-Length, { value: 4, as: equal }]