]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/ICAP/ICAPModXact.cc
Add X-Client-IP and X-Client-Username extention headers to ICAP
[thirdparty/squid.git] / src / ICAP / ICAPModXact.cc
index 0a7ec96fa8cbcf24397716b8bdd8b1228cc0689a..90affe8445b02b4f9bb32481c5758144eedf57ca 100644 (file)
@@ -13,6 +13,7 @@
 #include "ICAPClient.h"
 #include "ChunkedCodingParser.h"
 #include "TextException.h"
+#include "AuthUserRequest.h"
 
 // flow and terminology:
 //     HTTP| --> receive --> encode --> write --> |network
@@ -911,6 +912,19 @@ void ICAPModXact::makeRequestHeaders(MemBuf &buf)
         virginSendClaim.protectAll();
     }
 
+    const HttpRequest *request = virgin->data->cause ?
+                                 virgin->data->cause :
+                                 dynamic_cast<const HttpRequest*>(virgin->data->header);
+
+    if (request->client_addr.s_addr != any_addr.s_addr)
+        buf.Printf("X-Client-IP: %s\r\n", inet_ntoa(request->client_addr));
+
+    if (request->auth_user_request)
+        if (request->auth_user_request->username())
+            buf.Printf("X-Client-Username: %s\r\n", request->auth_user_request->username());
+
+    fprintf(stderr, "%s\n", buf.content());
+
     buf.append(ICAP::crlf, 2); // terminate ICAP header
 
     // start ICAP request body with encapsulated HTTP headers
@@ -1049,8 +1063,8 @@ void ICAPModXact::estimateVirginBody()
     if (virgin->data->cause)
         method = virgin->data->cause->method;
     else
-        if (HttpRequest *req= dynamic_cast<HttpRequest*>(virgin->data->
-                              header))
+        if (HttpRequest *req = dynamic_cast<HttpRequest*>(virgin->data->
+                               header))
             method = req->method;
         else
             return;