trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bc...@apache.org
Subject [trafficserver] branch master updated: TS-1228: Support new Forwarded standard
Date Sun, 13 Nov 2016 05:53:21 GMT
This is an automated email from the ASF dual-hosted git repository.

bcall pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git

The following commit(s) were added to refs/heads/master by this push:
       new  3145e45   TS-1228: Support new Forwarded standard
3145e45 is described below

commit 3145e45905f90cd5964538d3dff35e54ce42f42d
Author: Bryan Call <bcall@apache.org>
AuthorDate: Sat Nov 12 20:10:08 2016 -0800

    TS-1228: Support new Forwarded standard
    
    Code cleanup before implementation
---
 proxy/hdrs/MIME.h          | 13 +++++++++++++
 proxy/http/HttpTransact.cc | 35 ++++++++++++-----------------------
 2 files changed, 25 insertions(+), 23 deletions(-)

diff --git a/proxy/hdrs/MIME.h b/proxy/hdrs/MIME.h
index 4c63f52..1a59498 100644
--- a/proxy/hdrs/MIME.h
+++ b/proxy/hdrs/MIME.h
@@ -979,6 +979,7 @@ public:
   // Other separators (e.g. ';' in Set-cookie/Cookie) are also possible
   void field_value_append(MIMEField *field, const char *value, int value_length, bool prepend_comma
= false,
                           const char separator = ',');
+  void value_append_or_set(const char *name, const int name_length, char *value, int value_length);
   void field_combine_dups(MIMEField *field, bool prepend_comma = false, const char separator
= ',');
   time_t get_age();
   int64_t get_content_length() const;
@@ -1391,6 +1392,18 @@ MIMEHdr::field_combine_dups(MIMEField *field, bool prepend_comma, const
char sep
   }
 }
 
+inline void
+MIMEHdr::value_append_or_set(const char *name, const int name_length, char *value, int value_length)
+{
+  MIMEField *field = nullptr;
+
+  if ((field = field_find(name, name_length)) != nullptr) {
+    field_value_append(field, value, value_length, true);
+  } else {
+    value_set(name, name_length, value, value_length);
+  }
+}
+
 /*-------------------------------------------------------------------------
   -------------------------------------------------------------------------*/
 
diff --git a/proxy/http/HttpTransact.cc b/proxy/http/HttpTransact.cc
index 25e4026..c12a334 100644
--- a/proxy/http/HttpTransact.cc
+++ b/proxy/http/HttpTransact.cc
@@ -5218,39 +5218,28 @@ HttpTransact::add_client_ip_to_outgoing_request(State *s, HTTPHdr
*request)
     ip_string[0]   = 0;
   }
 
-  ////////////////////////////////////////////////////////////////
-  // if we want client-ip headers, and there isn't one, add one //
-  ////////////////////////////////////////////////////////////////
+  // Check to see if the ip_string has been set
+  if (ip_string_size == 0) {
+    return;
+  }
+
+  // if we want client-ip headers, and there isn't one, add one
   if ((s->txn_conf->anonymize_insert_client_ip) && (!s->txn_conf->anonymize_remove_client_ip))
{
     bool client_ip_set = request->presence(MIME_PRESENCE_CLIENT_IP);
     DebugTxn("http_trans", "client_ip_set = %d", client_ip_set);
 
-    if (!client_ip_set && ip_string_size > 0) {
+    if (client_ip_set == true) {
       request->value_set(MIME_FIELD_CLIENT_IP, MIME_LEN_CLIENT_IP, ip_string, ip_string_size);
       DebugTxn("http_trans", "inserted request header 'Client-ip: %s'", ip_string);
     }
   }
 
+  // Add or append to the X-Forwarded-For header
   if (s->txn_conf->insert_squid_x_forwarded_for) {
-    if (ip_string_size > 0) {
-      MIMEField *x_for;
-
-      if ((x_for = request->field_find(MIME_FIELD_X_FORWARDED_FOR, MIME_LEN_X_FORWARDED_FOR))
!= nullptr) {
-        // http://en.wikipedia.org/wiki/X-Forwarded-For
-        // The X-Forwarded-For (XFF) HTTP header field is a de facto standard
-        // for identifying the originating IP address of a client connecting
-        // to a web server through an HTTP proxy or load balancer. This is a
-        // non-RFC-standard request field which was introduced by the Squid
-        // caching proxy server's developers.
-        //   X-Forwarded-For: client1, proxy1, proxy2
-        request->field_value_append(x_for, ip_string, ip_string_size, true); // true =>
comma must be inserted
-      } else {
-        request->value_set(MIME_FIELD_X_FORWARDED_FOR, MIME_LEN_X_FORWARDED_FOR, ip_string,
ip_string_size);
-      }
-      DebugTxn("http_trans", "[add_client_ip_to_outgoing_request] Appended connecting client's
"
-                             "(%s) to the X-Forwards header",
-               ip_string);
-    }
+    request->value_append_or_set(MIME_FIELD_X_FORWARDED_FOR, MIME_LEN_X_FORWARDED_FOR,
ip_string, ip_string_size);
+    DebugTxn("http_trans", "[add_client_ip_to_outgoing_request] Appended connecting client's
"
+                           "(%s) to the X-Forwards header",
+             ip_string);
   }
 }
 

-- 
To stop receiving notification emails like this one, please contact
['"commits@trafficserver.apache.org" <commits@trafficserver.apache.org>'].

Mime
View raw message