Repository: trafficserver
Updated Branches:
  refs/heads/master 57a48ee10 -> 10be14487


[TS-2947] Make the setting proxy.config.http.global_user_agent_header
overrideable.


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

Branch: refs/heads/master
Commit: f37b13bd65f0a8dba0e9a2e11a3f615dc7e2df43
Parents: 57a48ee
Author: Sudheer Vinukonda <[email protected]>
Authored: Tue Aug 19 12:46:41 2014 -0600
Committer: Leif Hedstrom <[email protected]>
Committed: Tue Aug 19 13:36:13 2014 -0600

----------------------------------------------------------------------
 CHANGES                           |  4 +++-
 lib/ts/apidefs.h.in               |  1 +
 plugins/conf_remap/conf_remap.cc  | 22 ++++++++++++++++------
 proxy/InkAPI.cc                   | 30 +++++++++++++++++++++++++++---
 proxy/InkAPITest.cc               |  1 +
 proxy/Prefetch.cc                 |  2 +-
 proxy/http/HttpConfig.cc          | 12 +++++++-----
 proxy/http/HttpConfig.h           | 17 ++++++++---------
 proxy/http/HttpSM.cc              |  2 +-
 proxy/http/HttpTransact.cc        |  2 +-
 proxy/http/HttpTransactHeaders.cc | 10 +++++-----
 proxy/http/HttpTransactHeaders.h  |  2 +-
 12 files changed, 72 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f37b13bd/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 2ecd621..d0281ea 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,7 +1,9 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache Traffic Server 5.1.0
 
-  *) [TS-2902] Allow POST requests without a Content-Length header
+  *) [TS-2947] Make the setting proxy.config.http.global_user_agent_header.
+
+  *) [TS-2902] Allow POST requests without a Content-Length header.
 
   *) [TS-2423] Add option for server sessions that use auth headers that can
    be placed into the shared pool

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f37b13bd/lib/ts/apidefs.h.in
----------------------------------------------------------------------
diff --git a/lib/ts/apidefs.h.in b/lib/ts/apidefs.h.in
index b9a7fdd..96896f6 100644
--- a/lib/ts/apidefs.h.in
+++ b/lib/ts/apidefs.h.in
@@ -733,6 +733,7 @@ extern "C"
     TS_CONFIG_HTTP_CACHE_MAX_OPEN_READ_RETRIES,
     TS_CONFIG_HTTP_CACHE_RANGE_WRITE,
     TS_CONFIG_HTTP_POST_CHECK_CONTENT_LENGTH_ENABLED,
+    TS_CONFIG_HTTP_GLOBAL_USER_AGENT_HEADER,
     TS_CONFIG_LAST_ENTRY
   } TSOverridableConfigKey;
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f37b13bd/plugins/conf_remap/conf_remap.cc
----------------------------------------------------------------------
diff --git a/plugins/conf_remap/conf_remap.cc b/plugins/conf_remap/conf_remap.cc
index 1290f12..4a260ec 100644
--- a/plugins/conf_remap/conf_remap.cc
+++ b/plugins/conf_remap/conf_remap.cc
@@ -78,7 +78,7 @@ str_to_datatype(const char* str)
 bool
 RemapConfigs::parse_inline(const char *arg)
 {
-  const char * sep;
+  const char* sep;
   std::string key;
   std::string value;
 
@@ -104,8 +104,13 @@ RemapConfigs::parse_inline(const char *arg)
       _items[_current]._data.rec_int = strtoll(value.c_str(), NULL, 10);
       break;
     case TS_RECORDDATATYPE_STRING:
-      _items[_current]._data.rec_string = TSstrdup(value.c_str());
-      _items[_current]._data_len = value.size();
+      if (strcmp(value.c_str(), "NULL") == 0) {
+        _items[_current]._data.rec_string = NULL;
+        _items[_current]._data_len = 0;
+      } else {
+        _items[_current]._data.rec_string = TSstrdup(value.c_str());
+        _items[_current]._data_len = value.size();
+      }
       break;
     default:
       TSError("%s: configuration variable '%s' is of an unsupported type", 
PLUGIN_NAME, key.c_str());
@@ -217,8 +222,13 @@ RemapConfigs::parse_file(const char* filename)
       _items[_current]._data.rec_int = strtoll(tok, NULL, 10);
       break;
     case TS_RECORDDATATYPE_STRING:
-      _items[_current]._data.rec_string = TSstrdup(tok);
-      _items[_current]._data_len = strlen(tok);
+      if (strcmp(tok, "NULL") == 0) {
+        _items[_current]._data.rec_string = NULL;
+        _items[_current]._data_len = 0;
+      } else {
+        _items[_current]._data.rec_string = TSstrdup(tok);
+        _items[_current]._data_len = strlen(tok);
+      }
       break;
     default:
       TSError("%s: file %s, line %d: type not support (unheard of)", 
PLUGIN_NAME, path.c_str(), line_num);
@@ -306,7 +316,7 @@ TSRemapDeleteInstance(void* ih)
 // Main entry point when used as a remap plugin.
 //
 TSRemapStatus
-TSRemapDoRemap(void* ih, TSHttpTxn rh, TSRemapRequestInfo * /* rri ATS_UNUSED 
*/)
+TSRemapDoRemap(void* ih, TSHttpTxn rh, TSRemapRequestInfo* /* rri ATS_UNUSED 
*/)
 {
   if (NULL != ih) {
     RemapConfigs* conf = static_cast<RemapConfigs*>(ih);

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f37b13bd/proxy/InkAPI.cc
----------------------------------------------------------------------
diff --git a/proxy/InkAPI.cc b/proxy/InkAPI.cc
index b11cece..265d3ad 100644
--- a/proxy/InkAPI.cc
+++ b/proxy/InkAPI.cc
@@ -7818,6 +7818,9 @@ _conf_to_memberp(TSOverridableConfigKey conf,
     break;
   case TS_CONFIG_HTTP_POST_CHECK_CONTENT_LENGTH_ENABLED:
     ret = &overridableHttpConfig->post_check_content_length_enabled;
+  case TS_CONFIG_HTTP_GLOBAL_USER_AGENT_HEADER:
+    typ = OVERRIDABLE_TYPE_STRING;
+    ret = &overridableHttpConfig->global_user_agent_header;
     break;
 
     // This helps avoiding compiler warnings, yet detect unhandled enum 
members.
@@ -7975,7 +7978,6 @@ TSReturnCode
 TSHttpTxnConfigStringSet(TSHttpTxn txnp, TSOverridableConfigKey conf, const 
char* value, int length)
 {
   sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS);
-  sdk_assert(sdk_sanity_check_null_ptr((void*)value) == TS_SUCCESS);
 
   if (length == -1)
     length = strlen(value);
@@ -7986,8 +7988,22 @@ TSHttpTxnConfigStringSet(TSHttpTxn txnp, 
TSOverridableConfigKey conf, const char
 
   switch (conf) {
   case TS_CONFIG_HTTP_RESPONSE_SERVER_STR:
-    s->t_state.txn_conf->proxy_response_server_string = 
const_cast<char*>(value); // The "core" likes non-const char*
-    s->t_state.txn_conf->proxy_response_server_string_len = length;
+    if (value && length > 0) {
+      s->t_state.txn_conf->proxy_response_server_string = 
const_cast<char*>(value); // The "core" likes non-const char*
+      s->t_state.txn_conf->proxy_response_server_string_len = length;
+    } else {
+      s->t_state.txn_conf->proxy_response_server_string = NULL;
+      s->t_state.txn_conf->proxy_response_server_string_len = 0;
+    }
+    break;
+  case TS_CONFIG_HTTP_GLOBAL_USER_AGENT_HEADER:
+    if (value && length > 0) {
+      s->t_state.txn_conf->global_user_agent_header = 
const_cast<char*>(value); // The "core" likes non-const char*
+      s->t_state.txn_conf->global_user_agent_header_size = length;
+    } else {
+      s->t_state.txn_conf->global_user_agent_header = NULL;
+      s->t_state.txn_conf->global_user_agent_header_size = 0;
+    }
     break;
   default:
     return TS_ERROR;
@@ -8012,6 +8028,10 @@ TSHttpTxnConfigStringGet(TSHttpTxn txnp, 
TSOverridableConfigKey conf, const char
     *value = sm->t_state.txn_conf->proxy_response_server_string;
     *length = sm->t_state.txn_conf->proxy_response_server_string_len;
     break;
+  case TS_CONFIG_HTTP_GLOBAL_USER_AGENT_HEADER:
+    *value = sm->t_state.txn_conf->global_user_agent_header;
+    *length = sm->t_state.txn_conf->global_user_agent_header_size;
+    break;
   default:
     return TS_ERROR;
     break;
@@ -8222,6 +8242,10 @@ TSHttpTxnConfigFind(const char* name, int length, 
TSOverridableConfigKey *conf,
     case 'r':
       if (!strncmp(name, "proxy.config.http.anonymize_remove_referer", length))
         cnf = TS_CONFIG_HTTP_ANONYMIZE_REMOVE_REFERER;
+      else if (!strncmp(name, "proxy.config.http.global_user_agent_header", 
length)) {
+        cnf = TS_CONFIG_HTTP_GLOBAL_USER_AGENT_HEADER;
+        typ = TS_RECORDDATATYPE_STRING;
+      }
       break;
     case 't':
       if (!strncmp(name, "proxy.config.net.sock_recv_buffer_size_out", length))

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f37b13bd/proxy/InkAPITest.cc
----------------------------------------------------------------------
diff --git a/proxy/InkAPITest.cc b/proxy/InkAPITest.cc
index a784c1b..0ef6d5a 100644
--- a/proxy/InkAPITest.cc
+++ b/proxy/InkAPITest.cc
@@ -7417,6 +7417,7 @@ const char *SDK_Overridable_Configs[TS_CONFIG_LAST_ENTRY] 
= {
   "proxy.config.http.cache.open_read_retry_time",
   "proxy.config.http.cache.max_open_read_retries",
   "proxy.config.http.cache.range.write",
+  "proxy.config.http.global_user_agent_header",
 };
 
 REGRESSION_TEST(SDK_API_OVERRIDABLE_CONFIGS) (RegressionTest * test, int /* 
atype ATS_UNUSED */, int *pstatus)

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f37b13bd/proxy/Prefetch.cc
----------------------------------------------------------------------
diff --git a/proxy/Prefetch.cc b/proxy/Prefetch.cc
index 213c200..4ab8159 100644
--- a/proxy/Prefetch.cc
+++ b/proxy/Prefetch.cc
@@ -1857,7 +1857,7 @@ PrefetchBlaster::initCacheLookupConfig()
   //The look up parameters are intialized in the same as it is done
   //in HttpSM::init(). Any changes there should come in here.
   HttpConfigParams *http_config_params = HttpConfig::acquire();
-  cache_lookup_config.cache_global_user_agent_header = 
http_config_params->global_user_agent_header ? true : false;
+  cache_lookup_config.cache_global_user_agent_header = 
http_config_params->oride.global_user_agent_header ? true : false;
   cache_lookup_config.cache_enable_default_vary_headers =
     http_config_params->cache_enable_default_vary_headers ? true : false;
   cache_lookup_config.cache_vary_default_text = 
http_config_params->cache_vary_default_text;

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f37b13bd/proxy/http/HttpConfig.cc
----------------------------------------------------------------------
diff --git a/proxy/http/HttpConfig.cc b/proxy/http/HttpConfig.cc
index dd08780..2bd57c8 100644
--- a/proxy/http/HttpConfig.cc
+++ b/proxy/http/HttpConfig.cc
@@ -1339,8 +1339,10 @@ HttpConfig::startup()
   HttpEstablishStaticConfigByte(c.oride.anonymize_remove_client_ip, 
"proxy.config.http.anonymize_remove_client_ip");
   HttpEstablishStaticConfigByte(c.oride.anonymize_insert_client_ip, 
"proxy.config.http.anonymize_insert_client_ip");
   HttpEstablishStaticConfigStringAlloc(c.anonymize_other_header_list, 
"proxy.config.http.anonymize_other_header_list");
-  HttpEstablishStaticConfigStringAlloc(c.global_user_agent_header, 
"proxy.config.http.global_user_agent_header");
-  c.global_user_agent_header_size = c.global_user_agent_header ? 
strlen(c.global_user_agent_header) : 0;
+
+  HttpEstablishStaticConfigStringAlloc(c.oride.global_user_agent_header, 
"proxy.config.http.global_user_agent_header");
+  c.oride.global_user_agent_header_size = c.oride.global_user_agent_header ?
+    strlen(c.oride.global_user_agent_header) : 0;
 
   HttpEstablishStaticConfigByte(c.oride.proxy_response_server_enabled, 
"proxy.config.http.response_server_enabled");
   HttpEstablishStaticConfigStringAlloc(c.oride.proxy_response_server_string, 
"proxy.config.http.response_server_str");
@@ -1597,9 +1599,9 @@ HttpConfig::reconfigure()
   params->oride.anonymize_insert_client_ip = 
INT_TO_BOOL(m_master.oride.anonymize_insert_client_ip);
   params->anonymize_other_header_list = 
ats_strdup(m_master.anonymize_other_header_list);
 
-  params->global_user_agent_header = 
ats_strdup(m_master.global_user_agent_header);
-  params->global_user_agent_header_size = params->global_user_agent_header ?
-    strlen(params->global_user_agent_header) : 0;
+  params->oride.global_user_agent_header = 
ats_strdup(m_master.oride.global_user_agent_header);
+  params->oride.global_user_agent_header_size = 
params->oride.global_user_agent_header ?
+    strlen(params->oride.global_user_agent_header) : 0;
 
   params->oride.proxy_response_server_string = 
ats_strdup(m_master.oride.proxy_response_server_string);
   params->oride.proxy_response_server_string_len = 
params->oride.proxy_response_server_string ?

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f37b13bd/proxy/http/HttpConfig.h
----------------------------------------------------------------------
diff --git a/proxy/http/HttpConfig.h b/proxy/http/HttpConfig.h
index 282b133..0955e15 100644
--- a/proxy/http/HttpConfig.h
+++ b/proxy/http/HttpConfig.h
@@ -425,6 +425,7 @@ struct OverridableHttpConfigParams {
 
       // Strings / floats must come last
       proxy_response_server_string(NULL), proxy_response_server_string_len(0),
+      global_user_agent_header(NULL), global_user_agent_header_size(0),
       cache_heuristic_lm_factor(0.10), freshness_fuzz_prob(0.005),
       background_fill_threshold(0.5)
   { }
@@ -602,6 +603,12 @@ struct OverridableHttpConfigParams {
   char *proxy_response_server_string; // This does not get free'd by us!
   size_t proxy_response_server_string_len; // Updated when server_string is 
set.
 
+  ///////////////////////////////////////////////////////////////////
+  // Global User Agent header                                                 
//
+  ///////////////////////////////////////////////////////////////////
+  char *global_user_agent_header; // This does not get free'd by us!
+  size_t global_user_agent_header_size; // Updated when user_agent is set.
+
   MgmtFloat cache_heuristic_lm_factor;
   MgmtFloat freshness_fuzz_prob;
   MgmtFloat background_fill_threshold;
@@ -688,12 +695,6 @@ public:
   ///////////////////////////////////////////////////////////////////
   char *anonymize_other_header_list;
 
-  ///////////////////////////////////////////////////////////////////
-  // Global User Agent                                             //
-  ///////////////////////////////////////////////////////////////////
-  char *global_user_agent_header;
-  size_t global_user_agent_header_size;
-
   MgmtByte enable_http_stats; // Can be "slow"
 
   ///////////////////
@@ -907,8 +908,6 @@ HttpConfigParams::HttpConfigParams()
     per_parent_connect_attempts(2),
     parent_connect_timeout(30),
     anonymize_other_header_list(NULL),
-    global_user_agent_header(NULL),
-    global_user_agent_header_size(0),
     enable_http_stats(1),
     icp_enabled(0),
     stale_icp_enabled(0),
@@ -951,8 +950,8 @@ HttpConfigParams::~HttpConfigParams()
   ats_free(proxy_response_via_string);
   ats_free(url_expansions_string);
   ats_free(anonymize_other_header_list);
-  ats_free(global_user_agent_header);
   ats_free(oride.proxy_response_server_string);
+  ats_free(oride.global_user_agent_header);
   ats_free(cache_vary_default_text);
   ats_free(cache_vary_default_images);
   ats_free(cache_vary_default_other);

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f37b13bd/proxy/http/HttpSM.cc
----------------------------------------------------------------------
diff --git a/proxy/http/HttpSM.cc b/proxy/http/HttpSM.cc
index 6b5ace8..79a22bc 100644
--- a/proxy/http/HttpSM.cc
+++ b/proxy/http/HttpSM.cc
@@ -399,7 +399,7 @@ HttpSM::init()
 
   // update the cache info config structure so that
   // selection from alternates happens correctly.
-  t_state.cache_info.config.cache_global_user_agent_header = 
t_state.http_config_param->global_user_agent_header ? true : false;
+  t_state.cache_info.config.cache_global_user_agent_header = 
t_state.txn_conf->global_user_agent_header ? true : false;
   t_state.cache_info.config.ignore_accept_mismatch = 
t_state.http_config_param->ignore_accept_mismatch;
   t_state.cache_info.config.ignore_accept_language_mismatch = 
t_state.http_config_param->ignore_accept_language_mismatch ;
   t_state.cache_info.config.ignore_accept_encoding_mismatch = 
t_state.http_config_param->ignore_accept_encoding_mismatch;

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f37b13bd/proxy/http/HttpTransact.cc
----------------------------------------------------------------------
diff --git a/proxy/http/HttpTransact.cc b/proxy/http/HttpTransact.cc
index 6663581..4266d5f 100644
--- a/proxy/http/HttpTransact.cc
+++ b/proxy/http/HttpTransact.cc
@@ -7658,7 +7658,7 @@ HttpTransact::build_request(State* s, HTTPHdr* 
base_request, HTTPHdr* outgoing_r
   HttpTransactHeaders::copy_header_fields(base_request, outgoing_request, 
s->txn_conf->fwd_proxy_auth_to_parent);
   add_client_ip_to_outgoing_request(s, outgoing_request);
   
HttpTransactHeaders::remove_privacy_headers_from_request(s->http_config_param, 
s->txn_conf, outgoing_request);
-  
HttpTransactHeaders::add_global_user_agent_header_to_request(s->http_config_param,
 outgoing_request);
+  HttpTransactHeaders::add_global_user_agent_header_to_request(s->txn_conf, 
outgoing_request);
   handle_request_keep_alive_headers(s, outgoing_version, outgoing_request);
 
   // handle_conditional_headers appears to be obsolete.  Nothing happens

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f37b13bd/proxy/http/HttpTransactHeaders.cc
----------------------------------------------------------------------
diff --git a/proxy/http/HttpTransactHeaders.cc 
b/proxy/http/HttpTransactHeaders.cc
index 821b36c..f539c7a 100644
--- a/proxy/http/HttpTransactHeaders.cc
+++ b/proxy/http/HttpTransactHeaders.cc
@@ -966,20 +966,20 @@ HttpTransactHeaders::remove_host_name_from_url(HTTPHdr 
*outgoing_request)
 
 
 void
-HttpTransactHeaders::add_global_user_agent_header_to_request(HttpConfigParams 
*http_config_param, HTTPHdr *header)
+HttpTransactHeaders::add_global_user_agent_header_to_request(OverridableHttpConfigParams
 *http_txn_conf, HTTPHdr *header)
 {
-  if (http_config_param->global_user_agent_header) {
+  if (http_txn_conf->global_user_agent_header) {
     MIMEField *ua_field;
 
-    Debug("http_trans", "Adding User-Agent: %s", 
http_config_param->global_user_agent_header);
+    Debug("http_trans", "Adding User-Agent: %s", 
http_txn_conf->global_user_agent_header);
     if ((ua_field = header->field_find(MIME_FIELD_USER_AGENT, 
MIME_LEN_USER_AGENT)) == NULL) {
       if (likely((ua_field = header->field_create(MIME_FIELD_USER_AGENT, 
MIME_LEN_USER_AGENT)) != NULL))
         header->field_attach(ua_field);
     }
     // This will remove any old string (free it), and set our User-Agent.
     if (likely(ua_field))
-      header->field_value_set(ua_field, 
http_config_param->global_user_agent_header,
-                              
http_config_param->global_user_agent_header_size);
+      header->field_value_set(ua_field, 
http_txn_conf->global_user_agent_header,
+                              http_txn_conf->global_user_agent_header_size);
   }
 }
 

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/f37b13bd/proxy/http/HttpTransactHeaders.h
----------------------------------------------------------------------
diff --git a/proxy/http/HttpTransactHeaders.h b/proxy/http/HttpTransactHeaders.h
index 6170a75..27abc00 100644
--- a/proxy/http/HttpTransactHeaders.h
+++ b/proxy/http/HttpTransactHeaders.h
@@ -84,7 +84,7 @@ public:
   static void remove_conditional_headers(HTTPHdr * outgoing);
   static void remove_100_continue_headers(HttpTransact::State *s, HTTPHdr * 
outgoing);
   static void remove_host_name_from_url(HTTPHdr * outgoing_request);
-  static void add_global_user_agent_header_to_request(HttpConfigParams 
*http_config_param, HTTPHdr * header);
+  static void 
add_global_user_agent_header_to_request(OverridableHttpConfigParams 
*http_txn_conf, HTTPHdr * header);
   static void add_server_header_to_response(OverridableHttpConfigParams 
*http_txn_conf, HTTPHdr * header);
   static void remove_privacy_headers_from_request(HttpConfigParams 
*http_config_param,
                                                   OverridableHttpConfigParams 
*http_txn_conf, HTTPHdr * header);

Reply via email to