trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bc...@apache.org
Subject svn commit: r911230 - in /incubator/trafficserver/traffic/trunk/proxy: InkAPI.cc api/include/InkAPI.h hdrs/HTTP.h http2/HttpConfig.cc http2/HttpConfig.h http2/HttpSM.cc http2/HttpSM.h http2/HttpTransact.cc logging/Log.cc
Date Wed, 17 Feb 2010 23:59:07 GMT
Author: bcall
Date: Wed Feb 17 23:59:06 2010
New Revision: 911230

URL: http://svn.apache.org/viewvc?rev=911230&view=rev
Log:
TS-98 API added to set and get a url traffic server will redirect
the request to
Author: Wendy Huang

Modified:
    incubator/trafficserver/traffic/trunk/proxy/InkAPI.cc
    incubator/trafficserver/traffic/trunk/proxy/api/include/InkAPI.h
    incubator/trafficserver/traffic/trunk/proxy/hdrs/HTTP.h
    incubator/trafficserver/traffic/trunk/proxy/http2/HttpConfig.cc
    incubator/trafficserver/traffic/trunk/proxy/http2/HttpConfig.h
    incubator/trafficserver/traffic/trunk/proxy/http2/HttpSM.cc
    incubator/trafficserver/traffic/trunk/proxy/http2/HttpSM.h
    incubator/trafficserver/traffic/trunk/proxy/http2/HttpTransact.cc
    incubator/trafficserver/traffic/trunk/proxy/logging/Log.cc

Modified: incubator/trafficserver/traffic/trunk/proxy/InkAPI.cc
URL: http://svn.apache.org/viewvc/incubator/trafficserver/traffic/trunk/proxy/InkAPI.cc?rev=911230&r1=911229&r2=911230&view=diff
==============================================================================
--- incubator/trafficserver/traffic/trunk/proxy/InkAPI.cc (original)
+++ incubator/trafficserver/traffic/trunk/proxy/InkAPI.cc Wed Feb 17 23:59:06 2010
@@ -5571,81 +5571,6 @@
   return INK_SUCCESS;
 }
 
-// YTS Team, yamsat Plugin
-// This API is to create new request to the redirected url
-// by setting API INKHttpTxnRedirectRequest
-int
-INKHttpTxnCreateRequest(INKHttpTxn txnp, const char *hostname, const char *path, int port)
-{
-  HttpSM *sm = (HttpSM *) txnp;
-  HttpTransact::State * s = &(sm->t_state);
-  if (sm->enable_redirection) {
-    INKMBuffer bufp_resp = NULL;
-    INKMLoc hdrresp_loc = NULL;
-
-    INKHttpTxnClientRespGet(txnp, &bufp_resp, &hdrresp_loc);
-    //Checking for 302 and 301 response codes
-    if (INK_HTTP_STATUS_MOVED_TEMPORARILY == (INKHttpHdrStatusGet(bufp_resp, hdrresp_loc))
||
-        INK_HTTP_STATUS_MOVED_PERMANENTLY == (INKHttpHdrStatusGet(bufp_resp, hdrresp_loc)))
{
-
-      INKMBuffer redirBuf;
-      INKMLoc redirLoc;
-      int redir_url_length;
-      int re;
-
-      redirBuf = INKMBufferCreate();
-      redirLoc = INKUrlCreate(redirBuf);
-
-      INKUrlSchemeSet(redirBuf, redirLoc, INK_URL_SCHEME_HTTPS, INK_URL_LEN_HTTPS);
-      INKUrlHostSet(redirBuf, redirLoc, hostname, strlen(hostname));
-      INKUrlPortSet(redirBuf, redirLoc, port);
-      INKUrlPathSet(redirBuf, redirLoc, path, strlen(path));
-
-      const char *url_redir_str = INKUrlStringGet(redirBuf, redirLoc, &redir_url_length);
-      INKDebug("http", "Redirect URL in createReequest = \'%s\'\n", url_redir_str);
-
-      re = INKUrlParse(redirBuf, redirLoc, &url_redir_str, (url_redir_str + strlen(url_redir_str)));
-      if (re != INK_PARSE_DONE) {
-        INKDebug("INKHttpTxnCreateRequest", "\n CreateRequest: INKParse failed ");
-        INKMBufferDestroy(&redirBuf);
-        return 0;
-      }
-
-      re = INKHttpTxnRedirectRequest(txnp, redirBuf, redirLoc);
-
-      INKMBuffer req_bufp = NULL;
-      INKMLoc req_loc = NULL;
-      INKMLoc new_field_loc;
-      std::string HOSTNAME;
-      char *temp = NULL;
-      size_t temp_size = 4 * sizeof(int);
-      temp = (char *) xmalloc(temp_size);
-
-      if (!INKHttpTxnClientReqGet(txnp, &req_bufp, &req_loc)) {
-        INKError("Error");
-      }
-
-      HOSTNAME += hostname;
-      HOSTNAME += ":";
-      snprintf(temp, temp_size, "%d", port);
-      HOSTNAME += temp;
-
-      new_field_loc = INKMimeHdrFieldFind(req_bufp, req_loc, "Host", 4);
-      INKMimeHdrFieldValueSet(req_bufp, req_loc, new_field_loc, -1, HOSTNAME.c_str(), strlen(HOSTNAME.c_str()));
-      INKHandleMLocRelease(req_bufp, req_loc, new_field_loc);
-
-      DUMP_HEADER("http_hdrs", &s->hdr_info.client_request, sm->sm_id, "Framed
Client Request..checking");
-
-      return 0;
-    } else if (200 == (INKHttpHdrStatusGet(bufp_resp, hdrresp_loc))) {
-      sm->enable_redirection = false;
-    }
-    return 0;
-  }
-  return 0;
-}
-
-
 int
 INKHttpTxnRedirectRequest(INKHttpTxn txnp, INKMBuffer bufp, INKMLoc url_loc)
 {
@@ -9027,5 +8952,48 @@
   info->object_size_set(size);
 }
 
+// this function should be called at INK_EVENT_HTTP_READ_RESPONSE_HDR
+INKReturnCode INKRedirectUrlSet(INKHttpTxn txnp, const char* url, const int url_len)
+{
+  if (url == NULL) {
+    return INK_ERROR;
+  }
+  if (sdk_sanity_check_txn(txnp)!=INK_SUCCESS) {
+    return INK_ERROR;
+  }
+  HttpSM *sm = (HttpSM*) txnp;
+
+  if (sm->redirect_url != NULL) {
+    xfree(sm->redirect_url);
+    sm->redirect_url = NULL;
+    sm->redirect_url_len = 0;
+  }
+
+  if ((sm->redirect_url = (char*)xmalloc(url_len + 1)) != NULL) {
+    ink_strncpy(sm->redirect_url, (char*)url, url_len + 1);
+    sm->redirect_url_len = url_len;
+    // have to turn redirection on for this transaction if user wants to redirect to another
URL
+    if (sm->enable_redirection == false) {
+      sm->enable_redirection = true;
+      // max-out "redirection_tries" to avoid the regular redirection being turned on in
+      // this transaction improperly. This variable doesn't affect the custom-redirection
+      sm->redirection_tries = HttpConfig::m_master.number_of_redirections;
+    }
+    return INK_SUCCESS;
+  }
+  else {
+    return INK_ERROR;
+  }
+}
+
+const char* INKRedirectUrlGet(INKHttpTxn txnp, int* url_len_ptr)
+{
+  if (sdk_sanity_check_txn(txnp)!=INK_SUCCESS) {
+    return NULL;
+  }
+  HttpSM *sm = (HttpSM*) txnp;
+  *url_len_ptr = sm->redirect_url_len;
+  return (const char*)sm->redirect_url;
+}
 
 #endif //INK_NO_API

Modified: incubator/trafficserver/traffic/trunk/proxy/api/include/InkAPI.h
URL: http://svn.apache.org/viewvc/incubator/trafficserver/traffic/trunk/proxy/api/include/InkAPI.h?rev=911230&r1=911229&r2=911230&view=diff
==============================================================================
--- incubator/trafficserver/traffic/trunk/proxy/api/include/InkAPI.h (original)
+++ incubator/trafficserver/traffic/trunk/proxy/api/include/InkAPI.h Wed Feb 17 23:59:06 2010
@@ -2659,12 +2659,6 @@
   inkapi void INKMBufferCompress(INKMBuffer bufp);
 
   // --------------------------------------------------------------------------
-  // YTS Team, yamsat Plugin
-
-  /** @deprecated */
-  inkapi int INKHttpTxnCreateRequest(INKHttpTxn txnp, const char *, const char *, int);
-
-  // --------------------------------------------------------------------------
   // Deprecated MIME field functions --- use INKMimeHdrFieldXXX instead
 
   /** @deprecated */
@@ -2815,6 +2809,9 @@
   /** @deprecated */
   inkapi int INKCacheHttpInfoVector(INKCacheHttpInfo infop, void *data, int length);
 
+  inkapi INKReturnCode INKRedirectUrlSet(INKHttpTxn txnp, const char* url, const int url_len);
+  const char* INKRedirectUrlGet(INKHttpTxn txnp, int* url_len_ptr);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */

Modified: incubator/trafficserver/traffic/trunk/proxy/hdrs/HTTP.h
URL: http://svn.apache.org/viewvc/incubator/trafficserver/traffic/trunk/proxy/hdrs/HTTP.h?rev=911230&r1=911229&r2=911230&view=diff
==============================================================================
--- incubator/trafficserver/traffic/trunk/proxy/hdrs/HTTP.h (original)
+++ incubator/trafficserver/traffic/trunk/proxy/hdrs/HTTP.h Wed Feb 17 23:59:06 2010
@@ -127,6 +127,10 @@
   SQUID_LOG_TCP_WEBFETCH_MISS = 'd',
   SQUID_LOG_TCP_SPIDER_BYPASS = 'e',
   SQUID_LOG_TCP_FUTURE_2 = 'f',
+  SQUID_LOG_TCP_HIT_REDIRECT = '[',       // standard redirect
+  SQUID_LOG_TCP_MISS_REDIRECT = ']',      // standard redirect
+  SQUID_LOG_TCP_HIT_X_REDIRECT = '<',     // extended redirect
+  SQUID_LOG_TCP_MISS_X_REDIRECT = '>',    // extended redirect
   SQUID_LOG_UDP_HIT = 'g',
   SQUID_LOG_UDP_WEAK_HIT = 'h',
   SQUID_LOG_UDP_HIT_OBJ = 'i',

Modified: incubator/trafficserver/traffic/trunk/proxy/http2/HttpConfig.cc
URL: http://svn.apache.org/viewvc/incubator/trafficserver/traffic/trunk/proxy/http2/HttpConfig.cc?rev=911230&r1=911229&r2=911230&view=diff
==============================================================================
--- incubator/trafficserver/traffic/trunk/proxy/http2/HttpConfig.cc (original)
+++ incubator/trafficserver/traffic/trunk/proxy/http2/HttpConfig.cc Wed Feb 17 23:59:06 2010
@@ -970,6 +970,11 @@
                      RECD_FLOAT, RECP_NULL,
                      (int) http_ua_msecs_counts_other_unclassified_stat, RecRawStatSyncIntMsecsToFloatSeconds);
 
+  RecRegisterRawStat(http_rsb, RECT_PROCESS,
+                     "proxy.process.http.total_x_redirect_count",
+                     RECD_COUNTER, RECP_NULL,
+                     (int) http_total_x_redirect_stat, RecRawStatSyncCount);
+
 }
 
 

Modified: incubator/trafficserver/traffic/trunk/proxy/http2/HttpConfig.h
URL: http://svn.apache.org/viewvc/incubator/trafficserver/traffic/trunk/proxy/http2/HttpConfig.h?rev=911230&r1=911229&r2=911230&view=diff
==============================================================================
--- incubator/trafficserver/traffic/trunk/proxy/http2/HttpConfig.h (original)
+++ incubator/trafficserver/traffic/trunk/proxy/http2/HttpConfig.h Wed Feb 17 23:59:06 2010
@@ -268,6 +268,8 @@
   http_ua_msecs_counts_errors_other_stat,
   http_ua_msecs_counts_other_unclassified_stat,
 
+  http_total_x_redirect_stat,
+
   // Times
   http_total_transactions_time_stat,
   http_total_transactions_think_time_stat,

Modified: incubator/trafficserver/traffic/trunk/proxy/http2/HttpSM.cc
URL: http://svn.apache.org/viewvc/incubator/trafficserver/traffic/trunk/proxy/http2/HttpSM.cc?rev=911230&r1=911229&r2=911230&view=diff
==============================================================================
--- incubator/trafficserver/traffic/trunk/proxy/http2/HttpSM.cc (original)
+++ incubator/trafficserver/traffic/trunk/proxy/http2/HttpSM.cc Wed Feb 17 23:59:06 2010
@@ -325,7 +325,7 @@
 HttpSM::HttpSM():
 Continuation(NULL), sm_id(-1), magic(HTTP_SM_MAGIC_DEAD),
   //YTS Team, yamsat Plugin
-  enable_redirection(false), api_enable_redirection(true), redirection_tries(0), transfered_bytes(0),
+  enable_redirection(false), api_enable_redirection(true), redirect_url(NULL), redirect_url_len(0),
redirection_tries(0), transfered_bytes(0),
 post_failed(false),
   //YTS Team, yamsat
   is_cache_enabled(false), request_inserted(false),
@@ -398,6 +398,8 @@
   sm_id = 0;
   enable_redirection = false;
   api_enable_redirection = true;
+  redirect_url = NULL;
+  redirect_url_len = 0;
 
   // Unique state machine identifier.
   //  changed next_sm_id from ink64 to int because
@@ -6865,6 +6867,12 @@
 
     HTTP_SM_SET_DEFAULT_HANDLER(NULL);
 
+    if (redirect_url != NULL) {
+      xfree(redirect_url);
+      redirect_url = NULL;
+      redirect_url_len = 0;
+    }
+
 #ifdef USE_HTTP_DEBUG_LISTS
     ink_mutex_acquire(&debug_sm_list_mutex);
     debug_sm_list.remove(this, this->debug_link);
@@ -7721,13 +7729,26 @@
   }
 
   HTTPStatus status = t_state.hdr_info.client_response.status_get();
-  if ((status == HTTP_STATUS_MOVED_TEMPORARILY) || (status == HTTP_STATUS_MOVED_PERMANENTLY))
{
+  // if redirect_url is set by an user's plugin, yts will redirect to this url anyway.
+  if ((redirect_url != NULL) || (status == HTTP_STATUS_MOVED_TEMPORARILY) || (status == HTTP_STATUS_MOVED_PERMANENTLY))
{
 
-    if (t_state.hdr_info.client_response.field_find(MIME_FIELD_LOCATION, MIME_LEN_LOCATION))
{
+    if (redirect_url != NULL || t_state.hdr_info.client_response.field_find(MIME_FIELD_LOCATION,
MIME_LEN_LOCATION)) {
 
       if (Log::transaction_logging_enabled() && t_state.api_info.logging_enabled)
{
         LogAccessHttp accessor(this);
-        //t_state.squid_codes.log_code = SQUID_LOG_TCP_HIT_REDIRECT;
+        if (redirect_url == NULL) {
+          if (t_state.squid_codes.log_code == SQUID_LOG_TCP_HIT)
+            t_state.squid_codes.log_code = SQUID_LOG_TCP_HIT_REDIRECT;
+          else
+            t_state.squid_codes.log_code = SQUID_LOG_TCP_MISS_REDIRECT;
+        }
+        else {
+          if (t_state.squid_codes.log_code == SQUID_LOG_TCP_HIT)
+            t_state.squid_codes.log_code = SQUID_LOG_TCP_HIT_X_REDIRECT;
+          else
+            t_state.squid_codes.log_code = SQUID_LOG_TCP_MISS_X_REDIRECT;
+        }
+
         int ret = Log::access(&accessor);
 
         if (ret & Log::FULL) {
@@ -7737,11 +7758,21 @@
           Log::error("failed to log transaction for at least one log object");
         }
       }
-      // get the location header and setup the redirect
-      int redirect_len;
-      char *redirect_url =
-        (char *) t_state.hdr_info.client_response.value_get(MIME_FIELD_LOCATION, MIME_LEN_LOCATION,
&redirect_len);
-      redirect_request(redirect_url, redirect_len);
+
+      if (redirect_url != NULL) {
+        redirect_request(redirect_url, redirect_url_len);
+        xfree(redirect_url);
+        redirect_url = NULL;
+        redirect_url_len = 0;
+        HTTP_INCREMENT_DYN_STAT(http_total_x_redirect_stat);
+      }
+      else {
+        // get the location header and setup the redirect
+        int redir_len;
+        char *redir_url =
+        (char *) t_state.hdr_info.client_response.value_get(MIME_FIELD_LOCATION, MIME_LEN_LOCATION,
&redir_len);
+        redirect_request(redir_url, redir_len);
+      }
 
     } else {
       enable_redirection = false;

Modified: incubator/trafficserver/traffic/trunk/proxy/http2/HttpSM.h
URL: http://svn.apache.org/viewvc/incubator/trafficserver/traffic/trunk/proxy/http2/HttpSM.h?rev=911230&r1=911229&r2=911230&view=diff
==============================================================================
--- incubator/trafficserver/traffic/trunk/proxy/http2/HttpSM.h (original)
+++ incubator/trafficserver/traffic/trunk/proxy/http2/HttpSM.h Wed Feb 17 23:59:06 2010
@@ -268,6 +268,8 @@
   //YTS Team, yamsat Plugin
   bool enable_redirection;      //To check if redirection is enabled
   bool api_enable_redirection;  //To check if redirection is enabled
+  char *redirect_url;           //url for force redirect (provide users a functionality to
redirect to another url when needed)
+  int redirect_url_len;
   int redirection_tries;        //To monitor number of redirections
   int transfered_bytes;         //Added to calculate POST data
   bool post_failed;             //Added to identify post failure

Modified: incubator/trafficserver/traffic/trunk/proxy/http2/HttpTransact.cc
URL: http://svn.apache.org/viewvc/incubator/trafficserver/traffic/trunk/proxy/http2/HttpTransact.cc?rev=911230&r1=911229&r2=911230&view=diff
==============================================================================
--- incubator/trafficserver/traffic/trunk/proxy/http2/HttpTransact.cc (original)
+++ incubator/trafficserver/traffic/trunk/proxy/http2/HttpTransact.cc Wed Feb 17 23:59:06
2010
@@ -5361,7 +5361,9 @@
       HTTP_DEBUG_ASSERT(s->cache_info.action == CACHE_DO_NO_ACTION);
       s->next_action = SERVER_READ;
     }
-    s->state_machine->enable_redirection = false;
+    if (s->state_machine->redirect_url == NULL) {
+      s->state_machine->enable_redirection = false;
+    }
     break;
   case HTTP_STATUS_NOT_MODIFIED:
     Debug("http_trans", "[hncoofsr] server sent back 304. IMS from client?");

Modified: incubator/trafficserver/traffic/trunk/proxy/logging/Log.cc
URL: http://svn.apache.org/viewvc/incubator/trafficserver/traffic/trunk/proxy/logging/Log.cc?rev=911230&r1=911229&r2=911230&view=diff
==============================================================================
--- incubator/trafficserver/traffic/trunk/proxy/logging/Log.cc (original)
+++ incubator/trafficserver/traffic/trunk/proxy/logging/Log.cc Wed Feb 17 23:59:06 2010
@@ -573,6 +573,10 @@
          SQUID_LOG_TCP_WEBFETCH_MISS, "TCP_WEBFETCH_MISS",
          SQUID_LOG_TCP_SPIDER_BYPASS, "TCP_SPIDER_BYPASS",
          SQUID_LOG_TCP_FUTURE_2, "TCP_FUTURE_2",
+         SQUID_LOG_TCP_HIT_REDIRECT, "TCP_HIT_REDIRECT",
+         SQUID_LOG_TCP_MISS_REDIRECT, "TCP_MISS_REDIRECT",
+         SQUID_LOG_TCP_HIT_X_REDIRECT, "TCP_HIT_X_REDIRECT",
+         SQUID_LOG_TCP_MISS_X_REDIRECT, "TCP_MISS_X_REDIRECT",
          SQUID_LOG_UDP_HIT, "UDP_HIT",
          SQUID_LOG_UDP_WEAK_HIT, "UDP_WEAK_HIT",
          SQUID_LOG_UDP_HIT_OBJ, "UDP_HIT_OBJ",



Mime
View raw message