You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by bc...@apache.org on 2020/07/29 15:52:41 UTC

[trafficserver] branch 9.0.x updated: Fixed CLIENT-URL to use the pristine client URL (#7050)

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

bcall pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/9.0.x by this push:
     new e13c581  Fixed CLIENT-URL to use the pristine client URL (#7050)
e13c581 is described below

commit e13c581d590364dafcd64a1f1fafd048c395b048
Author: Bryan Call <bc...@apache.org>
AuthorDate: Wed Jul 29 08:40:27 2020 -0700

    Fixed CLIENT-URL to use the pristine client URL (#7050)
    
    
    (cherry picked from commit d7e35e451ad380ba2e4f5f9926158830fa87a9a2)
---
 plugins/header_rewrite/conditions.cc               | 30 ++++++-----
 .../header_rewrite/gold/header_rewrite-client.gold | 13 +++++
 .../header_rewrite/header_rewrite_client.test.py   | 60 ++++++++++++++++++++++
 .../header_rewrite/rules/rule_client.conf          | 22 ++++++++
 4 files changed, 111 insertions(+), 14 deletions(-)

diff --git a/plugins/header_rewrite/conditions.cc b/plugins/header_rewrite/conditions.cc
index e785e26..b9df7b8 100644
--- a/plugins/header_rewrite/conditions.cc
+++ b/plugins/header_rewrite/conditions.cc
@@ -274,11 +274,17 @@ ConditionUrl::append_value(std::string &s, const Resources &res)
   TSMLoc url     = nullptr;
   TSMBuffer bufp = nullptr;
 
-  if (res._rri != nullptr) {
+  if (_type == CLIENT) {
+    // CLIENT always uses the pristine URL
+    TSDebug(PLUGIN_NAME, "   Using the pristine url");
+    if (TSHttpTxnPristineUrlGet(res.txnp, &bufp, &url) != TS_SUCCESS) {
+      TSError("[header_rewrite] Error getting the pristine URL");
+      return;
+    }
+  } else if (res._rri != nullptr) {
     // called at the remap hook
     bufp = res._rri->requestBufp;
-    if (_type == URL || _type == CLIENT) {
-      // res._rri->requestBufp and res.client_bufp are the same if it is at the remap hook
+    if (_type == URL) {
       TSDebug(PLUGIN_NAME, "   Using the request url");
       url = res._rri->requestUrl;
     } else if (_type == FROM) {
@@ -292,21 +298,17 @@ ConditionUrl::append_value(std::string &s, const Resources &res)
       return;
     }
   } else {
-    TSMLoc hdr_loc = nullptr;
-    if (_type == CLIENT) {
-      bufp    = res.client_bufp;
-      hdr_loc = res.client_hdr_loc;
-    } else if (_type == URL) {
-      bufp    = res.bufp;
-      hdr_loc = res.hdr_loc;
+    if (_type == URL) {
+      bufp           = res.bufp;
+      TSMLoc hdr_loc = res.hdr_loc;
+      if (TSHttpHdrUrlGet(bufp, hdr_loc, &url) != TS_SUCCESS) {
+        TSError("[header_rewrite] Error getting the URL");
+        return;
+      }
     } else {
       TSError("[header_rewrite] Rule not supported at this hook");
       return;
     }
-    if (TSHttpHdrUrlGet(bufp, hdr_loc, &url) != TS_SUCCESS) {
-      TSError("[header_rewrite] Error getting the URL");
-      return;
-    }
   }
 
   int i;
diff --git a/tests/gold_tests/pluginTest/header_rewrite/gold/header_rewrite-client.gold b/tests/gold_tests/pluginTest/header_rewrite/gold/header_rewrite-client.gold
new file mode 100644
index 0000000..418608b
--- /dev/null
+++ b/tests/gold_tests/pluginTest/header_rewrite/gold/header_rewrite-client.gold
@@ -0,0 +1,13 @@
+``
+> GET http://www.example.com``
+> Host: www.example.com``
+> User-Agent: curl/``
+> Accept: */*
+``
+< HTTP/1.1 304 Not Modified
+< Date: ``
+< Proxy-Connection: keep-alive
+< Server: ATS/``
+< Cache-Control: no-store
+< 
+``
diff --git a/tests/gold_tests/pluginTest/header_rewrite/header_rewrite_client.test.py b/tests/gold_tests/pluginTest/header_rewrite/header_rewrite_client.test.py
new file mode 100644
index 0000000..53aa085
--- /dev/null
+++ b/tests/gold_tests/pluginTest/header_rewrite/header_rewrite_client.test.py
@@ -0,0 +1,60 @@
+'''
+'''
+#  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 header_rewrite and CLIENT-URL
+'''
+
+Test.ContinueOnFail = True
+# Define default ATS
+ts = Test.MakeATSProcess("ts")
+server = Test.MakeOriginServer("server")
+
+Test.testName = ""
+request_header = {"headers": "GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n", "timestamp": "1469733493.993", "body": ""}
+# expected response from the origin server
+response_header = {"headers": "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n", "timestamp": "1469733493.993", "body": ""}
+
+# add response to the server dictionary
+server.addResponse("sessionfile.log", request_header, response_header)
+ts.Disk.records_config.update({
+    'proxy.config.diags.debug.enabled': 1,
+    'proxy.config.diags.debug.tags': 'header.*',
+})
+# The following rule changes the status code returned from origin server to 303
+ts.Setup.CopyAs('rules/rule_client.conf', Test.RunDirectory)
+
+ts.Disk.remap_config.AddLine(
+    'map http://www.example.com/from_path/ https://127.0.0.1:{0}/to_path/ @plugin=header_rewrite.so @pparam={1}/rule_client.conf'.format(server.Variables.Port, Test.RunDirectory)
+)
+ts.Disk.remap_config.AddLine(
+    'map http://www.example.com:8080/from_path/ https://127.0.0.1:{0}/to_path/ @plugin=header_rewrite.so @pparam={1}/rule_client.conf'.format(server.Variables.Port, Test.RunDirectory)
+)
+
+# call localhost straight
+tr = Test.AddTestRun()
+tr.Processes.Default.Command = 'curl --proxy 127.0.0.1:{0} "http://www.example.com/from_path/hello?=foo=bar" -H "Proxy-Connection: keep-alive" --verbose'.format(
+    ts.Variables.port)
+tr.Processes.Default.ReturnCode = 0
+# time delay as proxy.config.http.wait_for_cache could be broken
+tr.Processes.Default.StartBefore(server, ready=When.PortOpen(server.Variables.Port))
+tr.Processes.Default.StartBefore(Test.Processes.ts)
+tr.Processes.Default.Streams.stderr = "gold/header_rewrite-client.gold"
+tr.StillRunningAfter = server
+
+ts.Streams.All = "gold/header_rewrite-tag.gold"
diff --git a/tests/gold_tests/pluginTest/header_rewrite/rules/rule_client.conf b/tests/gold_tests/pluginTest/header_rewrite/rules/rule_client.conf
new file mode 100644
index 0000000..a481775
--- /dev/null
+++ b/tests/gold_tests/pluginTest/header_rewrite/rules/rule_client.conf
@@ -0,0 +1,22 @@
+#
+# 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.
+
+cond %{CLIENT-URL:PATH} /^from_path/
+cond %{CLIENT-URL:SCHEME} =http
+cond %{CLIENT-URL:HOST} =www.example.com
+cond %{CLIENT-URL:QUERY} /foo=bar/
+set-status 304
\ No newline at end of file