DOC_END
NAME: forwarded_for
-COMMENT: on|off
-TYPE: onoff
+COMMENT: on|off|transparent|truncate|delete
+TYPE: string
DEFAULT: on
LOC: opt_forwarded_for
DOC_START
- If set, Squid will include your system's IP address or name
- in the HTTP requests it forwards. By default it looks like
- this:
+ If set to "on", Squid will append your client's IP address
+ in the HTTP requests it forwards. By default it looks like:
X-Forwarded-For: 192.1.2.3
- If you disable this, it will appear as
+ If set to "off", it will appear as
X-Forwarded-For: unknown
+
+ If set to "transparent", Squid will not alter the
+ X-Forwarded-For header in any way.
+
+ If set to "delete", Squid will delete the entire
+ X-Forwarded-For header.
+
+ If set to "truncate", Squid will remove all existing
+ X-Forwarded-For entries, and place itself as the sole entry.
DOC_END
NAME: cachemgr_passwd
/* building buffer for complex strings */
#define BBUF_SZ (MAX_URL+32)
LOCAL_ARRAY(char, bbuf, BBUF_SZ);
+ LOCAL_ARRAY(char, ntoabuf, MAX_IPSTRLEN);
const HttpHeader *hdr_in = &orig_request->header;
- const HttpHeaderEntry *e;
+ const HttpHeaderEntry *e = NULL;
String strFwd;
HttpHeaderPos pos = HttpHeaderInitPos;
assert (hdr_out->owner == hoRequest);
}
#endif
- /* append X-Forwarded-For */
+#if 1 /* new code */
strFwd = hdr_in->getList(HDR_X_FORWARDED_FOR);
+ /** \pre Handle X-Forwarded-For */
+ if(strcmp(opt_forwarded_for, "delete") != 0) {
+ if(strcmp(opt_forwarded_for, "on") == 0) {
+ /** If set to ON - append client IP or 'unknown'. */
+ strFwd = hdr_in->getList(HDR_X_FORWARDED_FOR);
+ if( orig_request->client_addr.IsNoAddr() )
+ strListAdd(&strFwd, "unknown", ',');
+ else
+ strListAdd(&strFwd, orig_request->client_addr.NtoA(ntoabuf, MAX_IPSTRLEN), ',');
+ } else if(strcmp(opt_forwarded_for, "off") == 0) {
+ /** If set to OFF - append 'unknown'. */
+ strFwd = hdr_in->getList(HDR_X_FORWARDED_FOR);
+ strListAdd(&strFwd, "unknown", ',');
+ } else if(strcmp(opt_forwarded_for, "transparent") == 0) {
+ /** If set to TRANSPARENT - pass through unchanged. */
+ strFwd = hdr_in->getList(HDR_X_FORWARDED_FOR);
+ } else if(strcmp(opt_forwarded_for, "truncate") == 0) {
+ /** If set to TRUNCATE - drop existing list and replace with client IP or 'unknown'. */
+ if( orig_request->client_addr.IsNoAddr() )
+ strFwd = "unknown";
+ else
+ strFwd = orig_request->client_addr.NtoA(ntoabuf, MAX_IPSTRLEN);
+ }
+ if(strFwd.size() > 0)
+ hdr_out->putStr(HDR_X_FORWARDED_FOR, strFwd.buf());
+ }
+ /** If set to DELETE - do not copy through. */
+
+#else
+
if (opt_forwarded_for && !orig_request->client_addr.IsNoAddr()) {
orig_request->client_addr.NtoA(bbuf,MAX_IPSTRLEN);
strListAdd(&strFwd, bbuf, ',');
hdr_out->putStr(HDR_X_FORWARDED_FOR, strFwd.buf());
+#endif
strFwd.clean();
/* append Host if not there already */