TS-2691 Fix how we count redirect retries

TS-2691 Also eliminate api_enable_redirection which seems superfluous


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

Branch: refs/heads/5.0.x
Commit: dfc2a8f8dba53cd0ab541753ac192eb06bba2fa4
Parents: 2ab1bb6
Author: Leif Hedstrom <[email protected]>
Authored: Wed Apr 2 10:21:57 2014 -0600
Committer: Leif Hedstrom <[email protected]>
Committed: Thu Apr 10 06:50:20 2014 -0600

----------------------------------------------------------------------
 proxy/InkAPI.cc           | 33 +++++++++++++++------------------
 proxy/http/HttpCacheSM.cc |  4 ++--
 proxy/http/HttpConfig.h   |  2 +-
 proxy/http/HttpSM.cc      | 22 +++++-----------------
 proxy/http/HttpSM.h       |  1 -
 proxy/http/HttpTunnel.cc  |  3 +--
 6 files changed, 24 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/dfc2a8f8/proxy/InkAPI.cc
----------------------------------------------------------------------
diff --git a/proxy/InkAPI.cc b/proxy/InkAPI.cc
index 241ab45..68d31d0 100644
--- a/proxy/InkAPI.cc
+++ b/proxy/InkAPI.cc
@@ -4938,17 +4938,6 @@ TSHttpTxnSecondUrlTryLock(TSHttpTxn txnp)
 }
 
 TSReturnCode
-TSHttpTxnFollowRedirect(TSHttpTxn txnp, int on)
-{
-  sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS);
-
-  HttpSM *sm = (HttpSM *) txnp;
-
-  sm->api_enable_redirection = (on ? true : false);
-  return TS_SUCCESS;
-}
-
-TSReturnCode
 TSHttpTxnRedirectRequest(TSHttpTxn txnp, TSMBuffer bufp, TSMLoc url_loc)
 {
   sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS);
@@ -7116,6 +7105,20 @@ TSCacheHttpInfoSizeSet(TSCacheHttpInfo infop, int64_t 
size)
   info->object_size_set(size);
 }
 
+// This API tells the core to follow normal (301/302) redirects using the
+// standard Location: URL. This does not need to be called if you set an
+// explicit URL using TSRedirectUrlSet().
+TSReturnCode
+TSHttpTxnFollowRedirect(TSHttpTxn txnp, int on)
+{
+  sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS);
+
+  HttpSM *sm = (HttpSM *) txnp;
+
+  sm->enable_redirection = (on ? true : false);
+  return TS_SUCCESS;
+}
+
 // this function should be called at TS_EVENT_HTTP_READ_RESPONSE_HDR
 void
 TSRedirectUrlSet(TSHttpTxn txnp, const char* url, const int url_len)
@@ -7134,13 +7137,7 @@ TSRedirectUrlSet(TSHttpTxn txnp, const char* url, const 
int url_len)
   sm->redirect_url = (char*)ats_malloc(url_len + 1);
   ink_strlcpy(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;
-  }
+  sm->enable_redirection = true;
 }
 
 const char*

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/dfc2a8f8/proxy/http/HttpCacheSM.cc
----------------------------------------------------------------------
diff --git a/proxy/http/HttpCacheSM.cc b/proxy/http/HttpCacheSM.cc
index 7f82dd5..a684f00 100644
--- a/proxy/http/HttpCacheSM.cc
+++ b/proxy/http/HttpCacheSM.cc
@@ -292,8 +292,8 @@ HttpCacheSM::open_write(URL * url, HTTPHdr * request, 
CacheHTTPInfo * old_info,
   //  a new write (could happen on a very busy document
   //  that must be revalidated every time)
   // Changed by YTS Team, yamsat Plugin
-  if (open_write_tries > master_sm->redirection_tries && open_write_tries >
-      master_sm->t_state.http_config_param->max_cache_open_write_retries) {
+  if (open_write_tries > master_sm->redirection_tries &&
+      open_write_tries > 
master_sm->t_state.http_config_param->max_cache_open_write_retries) {
     master_sm->handleEvent(CACHE_EVENT_OPEN_WRITE_FAILED, (void *) 
-ECACHE_DOC_BUSY);
     return ACTION_RESULT_DONE;
   }

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/dfc2a8f8/proxy/http/HttpConfig.h
----------------------------------------------------------------------
diff --git a/proxy/http/HttpConfig.h b/proxy/http/HttpConfig.h
index 064f4c6..343148f 100644
--- a/proxy/http/HttpConfig.h
+++ b/proxy/http/HttpConfig.h
@@ -929,7 +929,7 @@ HttpConfigParams::HttpConfigParams()
     errors_log_error_pages(1),
     enable_http_info(0),
     cluster_time_delta(0),
-    redirection_enabled(1),
+    redirection_enabled(0),
     number_of_redirections(1),
     post_copy_size(2048),
     ignore_accept_mismatch(0),

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/dfc2a8f8/proxy/http/HttpSM.cc
----------------------------------------------------------------------
diff --git a/proxy/http/HttpSM.cc b/proxy/http/HttpSM.cc
index 36135be..fc4f9bc 100644
--- a/proxy/http/HttpSM.cc
+++ b/proxy/http/HttpSM.cc
@@ -302,8 +302,8 @@ static int next_sm_id = 0;
 HttpSM::HttpSM()
   : Continuation(NULL), proto_stack(1u << TS_PROTO_HTTP), sm_id(-1), 
magic(HTTP_SM_MAGIC_DEAD),
     //YTS Team, yamsat Plugin
-    enable_redirection(false), api_enable_redirection(true), 
redirect_url(NULL), redirect_url_len(0), redirection_tries(0), 
transfered_bytes(0),
-    post_failed(false), debug_on(false),
+    enable_redirection(false), redirect_url(NULL), redirect_url_len(0), 
redirection_tries(0),
+    transfered_bytes(0), post_failed(false), debug_on(false),
     plugin_tunnel_type(HTTP_NO_PLUGIN_TUNNEL),
     plugin_tunnel(NULL), reentrancy_count(0),
     history_pos(0), tunnel(), ua_entry(NULL),
@@ -373,12 +373,7 @@ HttpSM::init()
   milestones.sm_start = ink_get_hrtime();
 
   magic = HTTP_SM_MAGIC_ALIVE;
-
   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 int64_t to int because
@@ -1837,11 +1832,9 @@ HttpSM::state_read_server_response_header(int event, 
void *data)
     t_state.transact_return_point = HttpTransact::HandleResponse;
     t_state.api_next_action = HttpTransact::SM_ACTION_API_READ_RESPONSE_HDR;
 
-    // YTS Team, yamsat Plugin
-    // Incrementing redirection_tries according to config parameter
     // if exceeded limit deallocate postdata buffers and disable redirection
-    if (enable_redirection && (redirection_tries <= 
HttpConfig::m_master.number_of_redirections)) {
-      redirection_tries++;
+    if (enable_redirection && (redirection_tries < 
HttpConfig::m_master.number_of_redirections)) {
+      ++redirection_tries;
     } else {
       tunnel.deallocate_redirect_postdata_buffers();
       enable_redirection = false;
@@ -7267,12 +7260,7 @@ void
 HttpSM::do_redirect()
 {
   DebugSM("http_redirect", "[HttpSM::do_redirect]");
-  if (enable_redirection == false || redirection_tries > 
(HttpConfig::m_master.number_of_redirections)) {
-    tunnel.deallocate_redirect_postdata_buffers();
-    return;
-  }
-
-  if (api_enable_redirection == false) {
+  if (!enable_redirection || redirection_tries >= 
HttpConfig::m_master.number_of_redirections) {
     tunnel.deallocate_redirect_postdata_buffers();
     return;
   }

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/dfc2a8f8/proxy/http/HttpSM.h
----------------------------------------------------------------------
diff --git a/proxy/http/HttpSM.h b/proxy/http/HttpSM.h
index 0a0a23e..0a7b116 100644
--- a/proxy/http/HttpSM.h
+++ b/proxy/http/HttpSM.h
@@ -270,7 +270,6 @@ public:
 
   //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

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/dfc2a8f8/proxy/http/HttpTunnel.cc
----------------------------------------------------------------------
diff --git a/proxy/http/HttpTunnel.cc b/proxy/http/HttpTunnel.cc
index 748d397..3e3baf2 100644
--- a/proxy/http/HttpTunnel.cc
+++ b/proxy/http/HttpTunnel.cc
@@ -903,8 +903,7 @@ HttpTunnel::producer_run(HttpTunnelProducer * p)
   //YTS Team, yamsat Plugin
   // Allocate and copy partial POST data to buffers. Check for the various 
parameters
   // including the maximum configured post data size
-  if (p->alive && sm->t_state.method == HTTP_WKSIDX_POST && 
sm->enable_redirection
-      && sm->redirection_tries == 0 && (p->vc_type == HT_HTTP_CLIENT)) {
+  if (p->alive && sm->t_state.method == HTTP_WKSIDX_POST && 
sm->enable_redirection && (p->vc_type == HT_HTTP_CLIENT)) {
     Debug("http_redirect", "[HttpTunnel::producer_run] client post: %" PRId64" 
max size: %" PRId64"",
           p->buffer_start->read_avail(), HttpConfig::m_master.post_copy_size);
 

Reply via email to