You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by am...@apache.org on 2010/11/11 17:54:41 UTC

svn commit: r1033997 - in /trafficserver/traffic/trunk/proxy: ControlMatcher.cc InkAPI.cc api/ts/ts.h hdrs/HTTP.cc hdrs/HTTP.h

Author: amc
Date: Thu Nov 11 16:54:41 2010
New Revision: 1033997

URL: http://svn.apache.org/viewvc?rev=1033997&view=rev
Log:
Patch for TS-526, TS-527

Modified:
    trafficserver/traffic/trunk/proxy/ControlMatcher.cc
    trafficserver/traffic/trunk/proxy/InkAPI.cc
    trafficserver/traffic/trunk/proxy/api/ts/ts.h
    trafficserver/traffic/trunk/proxy/hdrs/HTTP.cc
    trafficserver/traffic/trunk/proxy/hdrs/HTTP.h

Modified: trafficserver/traffic/trunk/proxy/ControlMatcher.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/ControlMatcher.cc?rev=1033997&r1=1033996&r2=1033997&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/ControlMatcher.cc (original)
+++ trafficserver/traffic/trunk/proxy/ControlMatcher.cc Thu Nov 11 16:54:41 2010
@@ -57,7 +57,7 @@
 char *
 HttpRequestData::get_string()
 {
-  char *str = hdr->url_get()->string_get(NULL);
+  char *str = hdr->url_string_get(NULL);
   unescapifyStr(str);
   return str;
 }

Modified: trafficserver/traffic/trunk/proxy/InkAPI.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/InkAPI.cc?rev=1033997&r1=1033996&r2=1033997&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/InkAPI.cc (original)
+++ trafficserver/traffic/trunk/proxy/InkAPI.cc Thu Nov 11 16:54:41 2010
@@ -5272,6 +5272,16 @@ INKHttpTxnPristineUrlGet (INKHttpTxn txn
     return INK_ERROR;
 }
 
+// Shortcut to just get the URL.
+char*
+INKHttpTxnEffectiveUrlStringGet (INKHttpTxn txnp, int* length) {
+  char* zret = 0;
+  if (INK_SUCCESS == sdk_sanity_check_txn(txnp)) {
+    HttpSM *sm = reinterpret_cast<HttpSM*>(txnp);
+    zret = sm->t_state.hdr_info.client_request.url_string_get(0, length);
+  }
+  return zret;
+}
 
 int
 INKHttpTxnClientRespGet(INKHttpTxn txnp, INKMBuffer *bufp, INKMLoc *obj)

Modified: trafficserver/traffic/trunk/proxy/api/ts/ts.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/api/ts/ts.h?rev=1033997&r1=1033996&r2=1033997&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/api/ts/ts.h (original)
+++ trafficserver/traffic/trunk/proxy/api/ts/ts.h Thu Nov 11 16:54:41 2010
@@ -1940,6 +1940,19 @@ extern "C"
   inkapi INKHttpSsn INKHttpTxnSsnGet(INKHttpTxn txnp);
   inkapi int INKHttpTxnClientReqGet(INKHttpTxn txnp, INKMBuffer * bufp, INKMLoc * offset);
   inkapi INKReturnCode INKHttpTxnPristineUrlGet(INKHttpTxn txnp, INKMBuffer *bufp, INKMLoc *url_loc);
+  /** Get the effective URL for the transaction.
+      The effective URL is the URL taking in to account both the explicit
+      URL in the request and the HOST field.
+
+      A possibly non-null terminated string is returned.
+
+      @note The returned string is allocated and must be freed by the caller
+      after use with @c INKfree.
+  */
+  inkapi char* INKHttpTxnEffectiveUrlStringGet(
+    INKHttpTxn txnp, ///< Transaction.
+    int* length ///< String length return, may be @c NULL.
+  );
   inkapi int INKHttpTxnClientRespGet(INKHttpTxn txnp, INKMBuffer * bufp, INKMLoc * offset);
   inkapi int INKHttpTxnServerReqGet(INKHttpTxn txnp, INKMBuffer * bufp, INKMLoc * offset);
   inkapi int INKHttpTxnServerRespGet(INKHttpTxn txnp, INKMBuffer * bufp, INKMLoc * offset);

Modified: trafficserver/traffic/trunk/proxy/hdrs/HTTP.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/hdrs/HTTP.cc?rev=1033997&r1=1033996&r2=1033997&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/hdrs/HTTP.cc (original)
+++ trafficserver/traffic/trunk/proxy/hdrs/HTTP.cc Thu Nov 11 16:54:41 2010
@@ -1516,6 +1516,53 @@ HTTPHdr::set_url_target_from_host_field(
   }
 }
 
+// Very ugly, but a proper implementation will require
+// rewriting the URL class and all of its clients so that
+// clients access the URL through the HTTP header instance
+// unless they really need low level access. The header would
+// need to either keep two versions of the URL (pristine
+// and effective) or URl would have to provide access to
+// the URL printer.
+char*
+HTTPHdr::url_string_get(Arena* arena, int* length) {
+  char *zret = 0;
+
+  if (m_url_cached.valid()) {
+    URLImpl* ui = m_url_cached.m_url_impl;
+    bool should_reset_host = false;
+    bool should_reset_port = false;
+    char port_buff[10];
+
+    this->_test_and_fill_target_cache();
+
+    /* Get dirty. We reach in to the URL implementation to
+       set the host and port if
+       1) They are not already set and
+       2) The values were in a HTTP header field.
+    */
+
+    if (!m_target_in_url && m_host_length) {
+      assert(0 == ui->m_ptr_host); // shouldn't be non-zero if not in URL.
+      ui->m_ptr_host = m_host;
+      ui->m_len_host = m_host_length;
+      should_reset_host = true;
+    }
+
+    if (0 == m_url_cached.port_get_raw() && m_port_in_header) {
+      assert(0 == ui->m_ptr_port); // shouldn't be set if not in URL.
+      ui->m_ptr_port = port_buff;
+      ui->m_len_port = sprintf(port_buff, "%.5d", m_port);
+      should_reset_port = true;
+    }
+
+    zret = m_url_cached.string_get(arena, length);
+    if (should_reset_host) { ui->m_ptr_host = 0; ui->m_len_host = 0; }
+    if (should_reset_port) { ui->m_ptr_port = 0; ui->m_len_port = 0; }
+ }
+
+  return zret;
+}
+
 /***********************************************************************
  *                                                                     *
  *                        M A R S H A L I N G                          *

Modified: trafficserver/traffic/trunk/proxy/hdrs/HTTP.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/hdrs/HTTP.h?rev=1033997&r1=1033996&r2=1033997&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/hdrs/HTTP.h (original)
+++ trafficserver/traffic/trunk/proxy/hdrs/HTTP.h Thu Nov 11 16:54:41 2010
@@ -572,6 +572,18 @@ public:
 
   URL *url_get() const;
   URL *url_get(URL * url);
+  /** Get a string with the effective URL in it.
+      If @a length is not @c NULL then the length of the string
+      is stored in the int pointed to by @a length.
+
+      Note that this can be different from getting the @c URL
+      and invoking @c URL::string_get if the host is in a header
+      field and not explicitly in the URL.
+   */
+  char* url_string_get(
+    Arena* arena = 0, ///< Arena to use, or @c malloc if NULL.
+    int* length = 0 ///< Store string length here.
+  );
 
   void url_set(URL * url);
   void url_set_as_server_url(URL * url);