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 2015/03/18 18:01:49 UTC

trafficserver git commit: TS-3447 [buffer_upload plugin] set UrlPort if port number present in Host header

Repository: trafficserver
Updated Branches:
  refs/heads/master 5fcd9d74f -> 4fbde42c1


TS-3447 [buffer_upload plugin] set UrlPort if port number present in Host header


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

Branch: refs/heads/master
Commit: 4fbde42c18684081af71ee34d8fbd895381dd045
Parents: 5fcd9d7
Author: Ethan Lai <yz...@yahoo.com>
Authored: Wed Mar 18 10:00:20 2015 -0700
Committer: Bryan Call <bc...@apache.org>
Committed: Wed Mar 18 10:00:20 2015 -0700

----------------------------------------------------------------------
 .../experimental/buffer_upload/buffer_upload.cc | 26 ++++++++++++++++----
 1 file changed, 21 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/4fbde42c/plugins/experimental/buffer_upload/buffer_upload.cc
----------------------------------------------------------------------
diff --git a/plugins/experimental/buffer_upload/buffer_upload.cc b/plugins/experimental/buffer_upload/buffer_upload.cc
index 81a0093..39b288b 100644
--- a/plugins/experimental/buffer_upload/buffer_upload.cc
+++ b/plugins/experimental/buffer_upload/buffer_upload.cc
@@ -627,8 +627,8 @@ convert_url_func(TSMBuffer req_bufp, TSMLoc req_loc)
       return;
     }
     char pathTmp[len + 1];
-    memset(pathTmp, 0, sizeof pathTmp);
     memcpy(pathTmp, str, len);
+    pathTmp[len] = '\0';
     TSDebug(DEBUG_TAG, "convert_url_func working on path: %s", pathTmp);
     colon = strstr(str, ":");
     if (colon != NULL && colon < slash) {
@@ -638,8 +638,12 @@ convert_url_func(TSMBuffer req_bufp, TSMLoc req_loc)
       TSUrlPortSet(req_bufp, url_loc, atoi(port_str));
       TSfree(port_str);
     } else {
-      if (port != 80) {
-        TSUrlPortSet(req_bufp, url_loc, 80);
+      int length = 0;
+      const char *scheme = TSUrlSchemeGet(req_bufp, url_loc, &length);
+
+      if ((length == TS_URL_LEN_HTTP && strncmp(TS_URL_SCHEME_HTTP, scheme, length) == 0 && port != 80) ||
+          (length == TS_URL_LEN_HTTPS && strncmp(TS_URL_SCHEME_HTTPS, scheme, length) == 0 && port != 443)) {
+        TSUrlPortSet(req_bufp, url_loc, port);
       }
       colon = slash;
     }
@@ -749,10 +753,22 @@ attach_pvc_plugin(TSCont /* contp ATS_UNUSED */, TSEvent event, void *edata)
         }
 
         char replacement_host_str[host_hdr_str_val_len + 1];
-        memset(replacement_host_str, 0, sizeof replacement_host_str);
         memcpy(replacement_host_str, host_hdr_str_val, host_hdr_str_val_len);
+        replacement_host_str[host_hdr_str_val_len] = '\0';
         TSDebug(DEBUG_TAG, "Adding host to request url: %s", replacement_host_str);
 
+        const char *colon = strchr(replacement_host_str, ':');
+        if (colon != NULL && colon + 1 != NULL) {
+          int length = 0;
+          const char *scheme = TSUrlSchemeGet(req_bufp, url_loc, &length);
+          int port_str_val = atoi(colon + 1);
+
+          if ((length == TS_URL_LEN_HTTP && strncmp(TS_URL_SCHEME_HTTP, scheme, length) == 0 && port_str_val != 80) ||
+              (length == TS_URL_LEN_HTTPS && strncmp(TS_URL_SCHEME_HTTPS, scheme, length) == 0 && port_str_val != 443)) {
+            TSUrlPortSet(req_bufp, url_loc, port_str_val);
+          }
+          host_hdr_str_val_len = colon - replacement_host_str;
+        }
         TSUrlHostSet(req_bufp, url_loc, host_hdr_str_val, host_hdr_str_val_len);
 
         //TSHandleStringRelease(req_bufp, field_loc, str);
@@ -765,8 +781,8 @@ attach_pvc_plugin(TSCont /* contp ATS_UNUSED */, TSEvent event, void *edata)
       url = TSUrlStringGet(req_bufp, url_loc, &url_len);
       if (VALID_PTR(url)) {
         char urlStr[url_len + 1];
-        memset(urlStr, 0, sizeof urlStr);
         memcpy(urlStr, url, url_len);
+        urlStr[url_len] = '\0';
         TSDebug(DEBUG_TAG, "Request url: %s", urlStr);
 
         for (i = 0; i < uconfig->url_num; i++) {