You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2018/03/06 21:19:13 UTC
[trafficserver] branch master updated: Add option to always add
Client-ip header
This is an automated email from the ASF dual-hosted git repository.
zwoop pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new adb46cd Add option to always add Client-ip header
adb46cd is described below
commit adb46cd0989dc5f352fa688226529e1ba5228ef5
Author: Shinya Kawano <sk...@yahoo-corp.jp>
AuthorDate: Wed Feb 28 12:14:05 2018 +0900
Add option to always add Client-ip header
---
doc/admin-guide/files/records.config.en.rst | 10 +++++++++-
mgmt/RecordsConfig.cc | 2 +-
proxy/http/HttpConfig.cc | 2 +-
proxy/http/HttpTransact.cc | 20 ++++++++++++++++----
4 files changed, 27 insertions(+), 7 deletions(-)
diff --git a/doc/admin-guide/files/records.config.en.rst b/doc/admin-guide/files/records.config.en.rst
index 5c71f11..4ae3d88 100644
--- a/doc/admin-guide/files/records.config.en.rst
+++ b/doc/admin-guide/files/records.config.en.rst
@@ -1654,7 +1654,15 @@ Proxy User Variables
:reloadable:
:overridable:
- When enabled (``1``), Traffic Server inserts ``Client-IP`` headers to retain the client IP address.
+ Specifies whether Traffic Server inserts ``Client-IP`` headers to retain the client IP address:
+
+ ===== ======================================================================
+ Value Description
+ ===== ======================================================================
+ ``0`` Don't insert the ``Client-ip`` header
+ ``1`` Insert the ``Client-ip`` header, but only if the UA did not send one
+ ``2`` Always insert the ``Client-ip`` header
+ ===== ======================================================================
.. ts:cv:: CONFIG proxy.config.http.anonymize_other_header_list STRING NULL
:reloadable:
diff --git a/mgmt/RecordsConfig.cc b/mgmt/RecordsConfig.cc
index 0159cc9..50815e2 100644
--- a/mgmt/RecordsConfig.cc
+++ b/mgmt/RecordsConfig.cc
@@ -522,7 +522,7 @@ static const RecordElement RecordsConfig[] =
,
{RECT_CONFIG, "proxy.config.http.anonymize_remove_client_ip", RECD_INT, "0", RECU_DYNAMIC, RR_NULL, RECC_INT, "[0-1]", RECA_NULL}
,
- {RECT_CONFIG, "proxy.config.http.insert_client_ip", RECD_INT, "1", RECU_DYNAMIC, RR_NULL, RECC_INT, "[0-1]", RECA_NULL}
+ {RECT_CONFIG, "proxy.config.http.insert_client_ip", RECD_INT, "1", RECU_DYNAMIC, RR_NULL, RECC_INT, "[0-2]", RECA_NULL}
,
{RECT_CONFIG, "proxy.config.http.anonymize_other_header_list", RECD_STRING, nullptr, RECU_DYNAMIC, RR_NULL, RECC_STR, ".*", RECA_NULL}
,
diff --git a/proxy/http/HttpConfig.cc b/proxy/http/HttpConfig.cc
index a5fce9c..6f08ead 100644
--- a/proxy/http/HttpConfig.cc
+++ b/proxy/http/HttpConfig.cc
@@ -1317,7 +1317,7 @@ HttpConfig::reconfigure()
params->oride.anonymize_remove_user_agent = INT_TO_BOOL(m_master.oride.anonymize_remove_user_agent);
params->oride.anonymize_remove_cookie = INT_TO_BOOL(m_master.oride.anonymize_remove_cookie);
params->oride.anonymize_remove_client_ip = INT_TO_BOOL(m_master.oride.anonymize_remove_client_ip);
- params->oride.anonymize_insert_client_ip = INT_TO_BOOL(m_master.oride.anonymize_insert_client_ip);
+ params->oride.anonymize_insert_client_ip = m_master.oride.anonymize_insert_client_ip;
params->anonymize_other_header_list = ats_strdup(m_master.anonymize_other_header_list);
params->oride.global_user_agent_header = ats_strdup(m_master.oride.global_user_agent_header);
diff --git a/proxy/http/HttpTransact.cc b/proxy/http/HttpTransact.cc
index 34ae415..5f16743 100644
--- a/proxy/http/HttpTransact.cc
+++ b/proxy/http/HttpTransact.cc
@@ -5019,13 +5019,25 @@ HttpTransact::add_client_ip_to_outgoing_request(State *s, HTTPHdr *request)
}
// 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);
- TxnDebug("http_trans", "client_ip_set = %d", client_ip_set);
+ if (!s->txn_conf->anonymize_remove_client_ip) {
+ switch (s->txn_conf->anonymize_insert_client_ip) {
+ case 1: { // Insert the client-ip, but only if the UA did not send one
+ bool client_ip_set = request->presence(MIME_PRESENCE_CLIENT_IP);
+ TxnDebug("http_trans", "client_ip_set = %d", client_ip_set);
- if (client_ip_set == true) {
+ if (client_ip_set == true) {
+ break;
+ }
+ }
+
+ // FALL-THROUGH
+ case 2: // Always insert the client-ip
request->value_set(MIME_FIELD_CLIENT_IP, MIME_LEN_CLIENT_IP, ip_string, ip_string_size);
TxnDebug("http_trans", "inserted request header 'Client-ip: %s'", ip_string);
+ break;
+
+ default: // don't insert client-ip
+ break;
}
}
--
To stop receiving notification emails like this one, please contact
zwoop@apache.org.