You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by bn...@apache.org on 2022/09/16 00:06:30 UTC

[trafficserver] branch master updated: better logic for checking if a server allows storing (#9092)

This is an automated email from the ASF dual-hosted git repository.

bneradt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new 943911844 better logic for checking if a server allows storing (#9092)
943911844 is described below

commit 943911844181b268abc16e20339d38f8ba37310a
Author: Chris McFarlen <ch...@mcfarlen.us>
AuthorDate: Thu Sep 15 19:06:22 2022 -0500

    better logic for checking if a server allows storing (#9092)
    
    This tweaks our processing of Pragma and Cache-Control directives.
---
 proxy/http/HttpTransactHeaders.cc                  |   9 +-
 tests/gold_tests/cache/cache-control.test.py       |  22 +++
 .../cache/replay/cache-control-pragma.replay.yaml  | 218 +++++++++++++++++++++
 3 files changed, 247 insertions(+), 2 deletions(-)

diff --git a/proxy/http/HttpTransactHeaders.cc b/proxy/http/HttpTransactHeaders.cc
index 22796079d..91b3f0452 100644
--- a/proxy/http/HttpTransactHeaders.cc
+++ b/proxy/http/HttpTransactHeaders.cc
@@ -423,9 +423,14 @@ HttpTransactHeaders::calculate_document_age(ink_time_t request_time, ink_time_t
 bool
 HttpTransactHeaders::does_server_allow_response_to_be_stored(HTTPHdr *resp)
 {
-  uint32_t cc_mask = (MIME_COOKED_MASK_CC_NO_STORE | MIME_COOKED_MASK_CC_PRIVATE);
+  uint32_t cc_mask = (MIME_COOKED_MASK_CC_NO_CACHE | MIME_COOKED_MASK_CC_NO_STORE | MIME_COOKED_MASK_CC_PRIVATE);
 
-  if ((resp->get_cooked_cc_mask() & cc_mask) || (resp->get_cooked_pragma_no_cache())) {
+  // According to https://www.rfc-editor.org/rfc/rfc7234#section-5.4
+  // ... When the Cache-Control header field is also present and
+  // understood in a request, Pragma is ignored.
+  if (resp->get_cooked_cc_mask() == 0 && resp->get_cooked_pragma_no_cache()) {
+    return false;
+  } else if (resp->get_cooked_cc_mask() & cc_mask) {
     return false;
   } else {
     return true;
diff --git a/tests/gold_tests/cache/cache-control.test.py b/tests/gold_tests/cache/cache-control.test.py
index 581e2e52d..2f00136af 100644
--- a/tests/gold_tests/cache/cache-control.test.py
+++ b/tests/gold_tests/cache/cache-control.test.py
@@ -130,3 +130,25 @@ tr = Test.AddTestRun("Verify correct max-age cache-control behavior.")
 tr.Processes.Default.StartBefore(server)
 tr.Processes.Default.StartBefore(ts)
 tr.AddVerifierClientProcess("proxy-verifier-client", replay_file, http_ports=[ts.Variables.port])
+
+
+#
+# Verify correct handling of cache-control no-cache and interaction with pragma header
+#
+#
+ts = Test.MakeATSProcess("ts-cache-control-pragma")
+ts.Disk.records_config.update({
+    'proxy.config.diags.debug.enabled': 1,
+    'proxy.config.diags.debug.tags': 'http|cache',
+
+})
+tr = Test.AddTestRun("Verify Pragma: no-cache does not conflict with Cache-Control headers")
+replay_file = "replay/cache-control-pragma.replay.yaml"
+server = tr.AddVerifierServerProcess("pragma-server", replay_file)
+tr.AddVerifierClientProcess("pragma-client", replay_file, http_ports=[ts.Variables.port])
+ts.Disk.remap_config.AddLine(
+    'map / http://127.0.0.1:{0}'.format(server.Variables.http_port)
+)
+tr.Processes.Default.StartBefore(server)
+tr.Processes.Default.StartBefore(ts)
+tr.StillRunningAfter = ts
diff --git a/tests/gold_tests/cache/replay/cache-control-pragma.replay.yaml b/tests/gold_tests/cache/replay/cache-control-pragma.replay.yaml
new file mode 100644
index 000000000..010442546
--- /dev/null
+++ b/tests/gold_tests/cache/replay/cache-control-pragma.replay.yaml
@@ -0,0 +1,218 @@
+#  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_cc_max_age is set to 0 so that we can
+# test max-age in the client requests.
+#
+
+meta:
+  version: "1.0"
+
+sessions:
+- transactions:
+  # Pragma: no-cache will prevent caching
+  - client-request:
+      method: "GET"
+      version: "1.1"
+      url: /pragma/no-cache
+      headers:
+        fields:
+          - [ uuid, pragma-populate-cache]
+          - [ Host, example.com ]
+
+    server-response:
+      status: 200
+      reason: OK
+      headers:
+        fields:
+        - [ Content-Length, 4 ]
+        - [ Pragma, "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: /pragma/no-cache
+      headers:
+        fields:
+          - [ uuid, pragma-populate-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 ]
+        - [ Pragma, "no-cache" ]
+
+    proxy-response:
+      status: 200
+      headers:
+        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"
+      version: "1.1"
+      url: /pragma/cache-control
+      headers:
+        fields:
+          - [ uuid, ignore-pragma-cc]
+          - [ Host, example.com ]
+
+    server-response:
+      status: 200
+      reason: OK
+      headers:
+        fields:
+        - [ Content-Length, 4 ]
+        - [ Cache-Control, "max-age=5,public" ]
+        - [ Pragma, "no-cache" ]
+
+    proxy-response:
+      status: 200
+      headers:
+        fields:
+          - [ Content-Length, { value: 4, as: equal}]
+  # Re-request to make sure it cached
+  - client-request:
+      method: "GET"
+      version: "1.1"
+      url: /pragma/cache-control
+      headers:
+        fields:
+          - [ uuid, ignore-pragma-cc-verify]
+          - [ Host, example.com ]
+
+    server-response:
+      status: 404
+
+    proxy-response:
+      status: 200
+      headers:
+        fields:
+          - [ Content-Length, { value: 4, as: equal}]
+