added X-Forwarded-URI

From: <noel@dont-contact.us>
Date: Wed, 15 Aug 2001 14:49:18 -0700

My CGI scripts need to recontruct the absolute URI that the client
browser used. However, that information is lost if they run under an
accelerated Apache behind squid. The HTTP_ and SERVER_ environment
vars reflect squid's connection to Apache, not the client to squid.
So, I modified the latest squid from CVS to add an X-Forwarded-URI
header. The diff is below for your patching pleasure.

--Noel

diff -ur squid/src/HttpHeader.c squid-nbk/src/HttpHeader.c
--- squid/src/HttpHeader.c Fri Apr 13 17:31:01 2001
+++ squid-nbk/src/HttpHeader.c Thu Aug 9 15:33:48 2001
@@ -123,6 +123,8 @@
     {"X-Cache-Lookup", HDR_X_CACHE_LOOKUP, ftStr},
     {"X-Forwarded-For", HDR_X_FORWARDED_FOR, ftStr},
     {"X-Request-URI", HDR_X_REQUEST_URI, ftStr},
+ /* NBK - Aug 9, 2001: record the client's URI in forwarded requests */
+ {"X-Forwarded-URI", HDR_X_FORWARDED_URI, ftStr},
     {"X-Squid-Error", HDR_X_SQUID_ERROR, ftStr},
     {"Negotiate", HDR_NEGOTIATE, ftStr},
 #if X_ACCELERATOR_VARY
@@ -161,6 +163,7 @@
 #if X_ACCELERATOR_VARY
     HDR_X_ACCELERATOR_VARY,
 #endif
+ HDR_X_FORWARDED_URI,
     HDR_X_FORWARDED_FOR
 };
 
diff -ur squid/src/client_side.c squid-nbk/src/client_side.c
--- squid/src/client_side.c Sat Jul 28 15:34:19 2001
+++ squid-nbk/src/client_side.c Thu Aug 9 15:32:59 2001
@@ -302,10 +302,22 @@
             new_request = urlParse(old_request->method, result);
     }
     if (new_request) {
+
+ httpHeaderAppend(&new_request->header, &old_request->header);
+
+ /* NBK - Aug 8, 2001: append X-Forwarded-URI */
+ if( http->forwarded_uri ) {
+ String str;
+
+ str = httpHeaderGetList(&new_request->header, HDR_X_FORWARDED_URI);
+ strListAdd(&str, http->forwarded_uri, ',');
+ httpHeaderPutStr(&new_request->header, HDR_X_FORWARDED_URI, strBuf(str));
+ stringClean(&str);
+ }
+
         safe_free(http->uri);
         http->uri = xstrdup(urlCanonical(new_request));
         new_request->http_ver = old_request->http_ver;
- httpHeaderAppend(&new_request->header, &old_request->header);
         new_request->client_addr = old_request->client_addr;
         new_request->my_addr = old_request->my_addr;
         new_request->my_port = old_request->my_port;
@@ -813,6 +825,7 @@
         checkFailureRatio(request->err_type, http->al.hier.code);
     safe_free(http->uri);
     safe_free(http->log_uri);
+ safe_free(http->forwarded_uri);
     safe_free(http->al.headers.request);
     safe_free(http->al.headers.reply);
     safe_free(http->redirect.location);
@@ -1364,6 +1377,7 @@
     httpHeaderPutStr(hdr, HDR_X_REQUEST_URI,
         http->entry->mem_obj->url ? http->entry->mem_obj->url : http->uri);
 #endif
+
     httpHdrMangleList(hdr, request);
 }
 
@@ -2671,6 +2685,28 @@
         http->log_uri = xstrndup(http->uri, MAX_URL);
     else
         http->log_uri = xstrndup(rfc1738_escape_unescaped(http->uri), MAX_URL);
+
+ /* X-Forwarded-URI */
+ {
+ const char *proto, *host;
+ int port;
+
+ proto = "http";
+ if( Config.Sockaddr.https->s.sin_port == http->conn->me.sin_port ) {
+ proto = "https";
+ }
+ port = ntohs(http->conn->me.sin_port);
+ host = mime_get_header(req_hdr, "Host");
+ if( !host ) {
+ host = getMyHostname();
+ }
+ http->forwarded_uri = xcalloc(MAX_URL+32, 1);
+ if( http->forwarded_uri ) {
+ snprintf(http->forwarded_uri, MAX_URL+32,
+ "%s://%s:%d%s", proto, host, port, url);
+ }
+ }
+
     debug(33, 5) ("parseHttpRequest: Complete request received\n");
     xfree(inbuf);
     *status = 1;
diff -ur squid/src/debug.c squid-nbk/src/debug.c
--- squid/src/debug.c Fri Jun 29 15:34:19 2001
+++ squid-nbk/src/debug.c Thu Aug 9 15:31:59 2001
@@ -55,7 +55,10 @@
 {
     const char *format = NULL;
 #endif
- LOCAL_ARRAY(char, f, BUFSIZ);
+
+ /* NBK - Aug 9, 2001: for some reason, LOCAL_ARRAY here crashes on
+ my RedHat-7.1 box */
+ char f[BUFSIZ];
     va_list args1;
 #if STDC_HEADERS
     va_list args2;
@@ -68,7 +71,7 @@
 #define args3 args1
     format = va_arg(args1, const char *);
 #endif
- snprintf(f, BUFSIZ, "%s| %s",
+ snprintf(f, sizeof(f), "%s| %s",
         debugLogTime(squid_curtime),
         format);
     _db_print_file(f, args1);
diff -ur squid/src/enums.h squid-nbk/src/enums.h
--- squid/src/enums.h Fri Apr 20 14:35:33 2001
+++ squid-nbk/src/enums.h Thu Aug 9 15:23:13 2001
@@ -238,6 +238,8 @@
 #if X_ACCELERATOR_VARY
     HDR_X_ACCELERATOR_VARY,
 #endif
+ /* NBK - Aug 9, 2001: record the client's URI in forwarded requests */
+ HDR_X_FORWARDED_URI,
     HDR_OTHER,
     HDR_ENUM_END
 } http_hdr_type;
diff -ur squid/src/structs.h squid-nbk/src/structs.h
--- squid/src/structs.h Sat Jul 28 15:34:19 2001
+++ squid-nbk/src/structs.h Thu Aug 9 15:27:21 2001
@@ -1012,6 +1012,8 @@
     store_client *old_sc; /* ... for entry to be validated */
     char *uri;
     char *log_uri;
+ /* NBK - Aug 9, 2001: record the client's URI in forwarded requests */
+ char *forwarded_uri;
     struct {
         off_t offset;
         size_t size;
Received on Wed Aug 15 2001 - 16:46:53 MDT

This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:14:12 MST