Repository: trafficserver
Updated Branches:
  refs/heads/5.1.x d7e41a789 -> 2d4a9686c


TS-2677: Rewrite domain:port for CONNECT requests and remap rules.


Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/2d4a9686
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/2d4a9686
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/2d4a9686

Branch: refs/heads/5.1.x
Commit: 2d4a9686cfbdf8809bdbf47e2a04d008a25f3009
Parents: d7e41a7
Author: Leif Hedstrom <[email protected]>
Authored: Fri Oct 10 19:03:45 2014 -0500
Committer: Alan M. Carroll <[email protected]>
Committed: Mon Oct 13 07:15:35 2014 -0500

----------------------------------------------------------------------
 proxy/http/remap/RemapPlugins.cc |   4 +-
 proxy/http/remap/UrlRewrite.cc   | 108 ++++++++++++++++++----------------
 proxy/http/remap/UrlRewrite.h    |   2 +-
 3 files changed, 59 insertions(+), 55 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2d4a9686/proxy/http/remap/RemapPlugins.cc
----------------------------------------------------------------------
diff --git a/proxy/http/remap/RemapPlugins.cc b/proxy/http/remap/RemapPlugins.cc
index 1b5fda3..626ed1f 100644
--- a/proxy/http/remap/RemapPlugins.cc
+++ b/proxy/http/remap/RemapPlugins.cc
@@ -123,9 +123,9 @@ RemapPlugins::run_single_remap()
     //
     // XXX we could probably optimize this a bit more by keeping a flag and 
only rewriting the request URL
     // if no plugin has rewritten it already.
-    if ((_cur == 1) && (HTTP_WKSIDX_CONNECT != 
_s->hdr_info.client_request.method_get_wksidx())) {
+    if (_cur == 1) {
       Debug("url_rewrite", "plugin did not change host, port or path, copying 
from mapping rule");
-      url_rewrite_remap_request(_s->url_map, _request_url);
+      url_rewrite_remap_request(_s->url_map, _request_url, 
_s->hdr_info.client_request.method_get_wksidx());
     }
   }
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2d4a9686/proxy/http/remap/UrlRewrite.cc
----------------------------------------------------------------------
diff --git a/proxy/http/remap/UrlRewrite.cc b/proxy/http/remap/UrlRewrite.cc
index a9897e9..b80630c 100644
--- a/proxy/http/remap/UrlRewrite.cc
+++ b/proxy/http/remap/UrlRewrite.cc
@@ -284,79 +284,83 @@ UrlRewrite::_tableLookup(InkHashTable *h_table, URL 
*request_url,
 // This is only used for redirects and reverse rules, and the homepageredirect 
flag
 // can never be set. The end result is that request_url is modified per remap 
container.
 void
-url_rewrite_remap_request(const UrlMappingContainer& mapping_container, URL 
*request_url)
+url_rewrite_remap_request(const UrlMappingContainer& mapping_container, URL 
*request_url, int method)
 {
-  const char *requestPath;
-  int requestPathLen = 0;
-  int fromPathLen = 0;
-
   URL *map_to = mapping_container.getToURL();
   URL *map_from = mapping_container.getFromURL();
   const char *toHost;
-  const char *toPath;
-  const char *toScheme;
-  int toPathLen;
   int toHostLen;
-  int toSchemeLen;
-
-  map_from->path_get(&fromPathLen);
 
   toHost = map_to->host_get(&toHostLen);
-  toPath = map_to->path_get(&toPathLen);
-  toScheme = map_to->scheme_get(&toSchemeLen);
 
   Debug("url_rewrite", "%s: Remapping rule id: %d matched", __func__, 
mapping_container.getMapping()->map_id);
 
   request_url->host_set(toHost, toHostLen);
   request_url->port_set(map_to->port_get_raw());
-  request_url->scheme_set(toScheme, toSchemeLen);
-
-  requestPath = request_url->path_get(&requestPathLen);
 
-  // Should be +3, little extra padding won't hurt. Use the stack allocation
-  // for better performance (bummer that arrays of variable length is not 
supported
-  // on Solaris CC.
-  char *newPath = static_cast<char*>(alloca(sizeof(char*)*((requestPathLen - 
fromPathLen) + toPathLen + 8)));
-  int newPathLen = 0;
-
-  *newPath = 0;
-  if (toPath) {
-    memcpy(newPath, toPath, toPathLen);
-    newPathLen += toPathLen;
-  }
+  // With the CONNECT method, we have to avoid messing with the scheme and 
path, because it's not part of
+  // the CONNECT request (only host and port is).
+  if (HTTP_WKSIDX_CONNECT != method) {
+    const char *toScheme;
+    int toSchemeLen;
+    const char *requestPath;
+    int requestPathLen = 0;
+    int fromPathLen = 0;
+    const char *toPath;
+    int toPathLen;
+
+    toScheme = map_to->scheme_get(&toSchemeLen);
+    request_url->scheme_set(toScheme, toSchemeLen);
+
+    map_from->path_get(&fromPathLen);
+    toPath = map_to->path_get(&toPathLen);
+    requestPath = request_url->path_get(&requestPathLen);
+
+    // Should be +3, little extra padding won't hurt. Use the stack allocation
+    // for better performance (bummer that arrays of variable length is not 
supported
+    // on Solaris CC.
+    char *newPath = static_cast<char*>(alloca(sizeof(char*)*((requestPathLen - 
fromPathLen) + toPathLen + 8)));
+    int newPathLen = 0;
+
+    *newPath = 0;
+    if (toPath) {
+      memcpy(newPath, toPath, toPathLen);
+      newPathLen += toPathLen;
+    }
 
-  // We might need to insert a trailing slash in the new portion of the path
-  // if more will be added and none is present and one will be needed.
-  if (!fromPathLen && requestPathLen && newPathLen && toPathLen && *(newPath + 
newPathLen - 1) != '/') {
-    *(newPath + newPathLen) = '/';
-    newPathLen++;
-  }
+    // We might need to insert a trailing slash in the new portion of the path
+    // if more will be added and none is present and one will be needed.
+    if (!fromPathLen && requestPathLen && newPathLen && toPathLen && *(newPath 
+ newPathLen - 1) != '/') {
+      *(newPath + newPathLen) = '/';
+      newPathLen++;
+    }
 
-  if (requestPath) {
-    //avoid adding another trailing slash if the requestPath already had one 
and so does the toPath
-    if (requestPathLen < fromPathLen) {
-      if (toPathLen && requestPath[requestPathLen - 1] == '/' && 
toPath[toPathLen - 1] == '/') {
-        fromPathLen++;
+    if (requestPath) {
+      //avoid adding another trailing slash if the requestPath already had one 
and so does the toPath
+      if (requestPathLen < fromPathLen) {
+        if (toPathLen && requestPath[requestPathLen - 1] == '/' && 
toPath[toPathLen - 1] == '/') {
+          fromPathLen++;
+        }
+      } else {
+        if (toPathLen && requestPath[fromPathLen] == '/' && toPath[toPathLen - 
1] == '/') {
+          fromPathLen++;
+        }
       }
-    } else {
-      if (toPathLen && requestPath[fromPathLen] == '/' && toPath[toPathLen - 
1] == '/') {
-        fromPathLen++;
+
+      // copy the end of the path past what has been mapped
+      if ((requestPathLen - fromPathLen) > 0) {
+        memcpy(newPath + newPathLen, requestPath + fromPathLen, requestPathLen 
- fromPathLen);
+        newPathLen += (requestPathLen - fromPathLen);
       }
     }
 
-    // copy the end of the path past what has been mapped
-    if ((requestPathLen - fromPathLen) > 0) {
-      memcpy(newPath + newPathLen, requestPath + fromPathLen, requestPathLen - 
fromPathLen);
-      newPathLen += (requestPathLen - fromPathLen);
+    // Skip any leading / in the path when setting the new URL path
+    if (*newPath == '/') {
+      request_url->path_set(newPath + 1, newPathLen - 1);
+    } else {
+      request_url->path_set(newPath, newPathLen);
     }
   }
-
-  // Skip any leading / in the path when setting the new URL path
-  if (*newPath == '/') {
-    request_url->path_set(newPath + 1, newPathLen - 1);
-  } else {
-    request_url->path_set(newPath, newPathLen);
-  }
 }
 
 /** Used to do the backwards lookups. */

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/2d4a9686/proxy/http/remap/UrlRewrite.h
----------------------------------------------------------------------
diff --git a/proxy/http/remap/UrlRewrite.h b/proxy/http/remap/UrlRewrite.h
index 92a20cf..8f1e32d 100644
--- a/proxy/http/remap/UrlRewrite.h
+++ b/proxy/http/remap/UrlRewrite.h
@@ -189,6 +189,6 @@ private:
                           bool is_cur_mapping_regex, int &count);
 };
 
-void url_rewrite_remap_request(const UrlMappingContainer& mapping_container, 
URL * request_url);
+void url_rewrite_remap_request(const UrlMappingContainer& mapping_container, 
URL* request_url, int scheme = -1);
 
 #endif

Reply via email to