From: Christos Tsantilas Date: Thu, 28 Jan 2010 20:37:10 +0000 (+0200) Subject: Add the http::>ha format code and make http::>h log virgin request headers X-Git-Tag: SQUID_3_2_0_1~446 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6fca33e0ab6af8cd01d1570923961ea56b2fc9b0;p=thirdparty%2Fsquid.git Add the http::>ha format code and make http::>h log virgin request headers This patch: - Modify the existin "http::>h format code to log HTTP request headers before any adaptation and redirection - Add the new format code "http::>ha" which allow the user to log HTTP request header or header fields after adaptation and redirection. This is a Measurement Factory project. --- diff --git a/src/AccessLogEntry.h b/src/AccessLogEntry.h index 18d78c66c4..5f2ee2225f 100644 --- a/src/AccessLogEntry.h +++ b/src/AccessLogEntry.h @@ -47,7 +47,9 @@ class AccessLogEntry { public: - AccessLogEntry() : url(NULL) , reply(NULL), request(NULL) {} + AccessLogEntry() : url(NULL) , reply(NULL), request(NULL), + adapted_request(NULL) + {} const char *url; @@ -134,12 +136,17 @@ public: public: Headers() : request(NULL), + adapted_request(NULL), + #if ICAP_CLIENT icap(NULL), #endif reply(NULL) {} - char *request; + char *request; //< virgin HTTP request headers + + char *adapted_request; //< HTTP request headers after adaptation and redirection + #if ICAP_CLIENT char * icap; ///< last matching ICAP response header. @@ -159,7 +166,9 @@ public: } _private; HierarchyLogEntry hier; HttpReply *reply; - HttpRequest *request; + HttpRequest *request; //< virgin HTTP request + HttpRequest *adapted_request; //< HTTP request after adaptation and redirection + #if ICAP_CLIENT /** \brief This subclass holds log info for ICAP part of request diff --git a/src/cf.data.pre b/src/cf.data.pre index bb14b69f11..335c511a91 100644 --- a/src/cf.data.pre +++ b/src/cf.data.pre @@ -2495,8 +2495,10 @@ DOC_START HTTP cache related format codes: - [http::]>h Request header. Optional header name argument + [http::]>h Virgin request header. Optional header name argument on the format header[:[separator]element] + [http::]>ha The HTTP request headers after adaptation and redirection. + Optional header name argument as for >h [http::]h [http::]un User name diff --git a/src/client_side.cc b/src/client_side.cc index 61f1a76083..7f362cf848 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -461,7 +461,17 @@ prepareLogWithRequestDetails(HttpRequest * request, AccessLogEntry * aLogEntry) mb.init(); packerToMemInit(&p, &mb); request->header.packInto(&p); - aLogEntry->headers.request = xstrdup(mb.buf); + //This is the request after adaptation or redirection + aLogEntry->headers.adapted_request = xstrdup(mb.buf); + + // the virgin request is saved to aLogEntry->request + if (aLogEntry->request) { + packerClean(&p); + mb.reset(); + packerToMemInit(&p, &mb); + aLogEntry->request->header.packInto(&p); + aLogEntry->headers.request = xstrdup(mb.buf); + } #if ICAP_CLIENT packerClean(&p); @@ -559,7 +569,7 @@ ClientHttpRequest::logRequest() if (!Config.accessList.log || checklist->fastCheck()) { if (request) - al.request = HTTPMSGLOCK(request); + al.adapted_request = HTTPMSGLOCK(request); accessLogLog(&al, checklist); updateCounters(); diff --git a/src/client_side_request.cc b/src/client_side_request.cc index ad090efcae..540ee82c59 100644 --- a/src/client_side_request.cc +++ b/src/client_side_request.cc @@ -1256,6 +1256,10 @@ ClientHttpRequest::doCallouts() { assert(calloutContext); + /*Save the original request for logging purposes*/ + if (!calloutContext->http->al.request) + calloutContext->http->al.request = HTTPMSGLOCK(request); + if (!calloutContext->http_access_done) { debugs(83, 3, HERE << "Doing calloutContext->clientAccessCheck()"); calloutContext->http_access_done = true; diff --git a/src/log/access_log.cc b/src/log/access_log.cc index ad42287af7..4c84d3de28 100644 --- a/src/log/access_log.cc +++ b/src/log/access_log.cc @@ -359,6 +359,10 @@ typedef enum { LFT_REQUEST_HEADER_ELEM, LFT_REQUEST_ALL_HEADERS, + LFT_ADAPTED_REQUEST_HEADER, + LFT_ADAPTED_REQUEST_HEADER_ELEM, + LFT_ADAPTED_REQUEST_ALL_HEADERS, + LFT_REPLY_HEADER, LFT_REPLY_HEADER_ELEM, LFT_REPLY_ALL_HEADERS, @@ -512,6 +516,8 @@ struct logformat_token_table_entry logformat_token_table[] = { {"ha", LFT_ADAPTED_REQUEST_HEADER}, + {">ha", LFT_ADAPTED_REQUEST_ALL_HEADERS}, {">h", LFT_REQUEST_HEADER}, {">h", LFT_REQUEST_ALL_HEADERS}, {"request) + sb = al->adapted_request->header.getByName(fmt->data.header.header); + + out = sb.termedBuf(); + + quote = 1; + + break; + case LFT_REPLY_HEADER: if (al->reply) sb = al->reply->header.getByName(fmt->data.header.header); @@ -954,6 +971,16 @@ accessLogCustom(AccessLogEntry * al, customlog * log) break; + case LFT_ADAPTED_REQUEST_HEADER_ELEM: + if (al->adapted_request) + sb = al->adapted_request->header.getByNameListMember(fmt->data.header.header, fmt->data.header.element, fmt->data.header.separator); + + out = sb.termedBuf(); + + quote = 1; + + break; + case LFT_REPLY_HEADER_ELEM: if (al->reply) sb = al->reply->header.getByNameListMember(fmt->data.header.header, fmt->data.header.element, fmt->data.header.separator); @@ -971,6 +998,13 @@ accessLogCustom(AccessLogEntry * al, customlog * log) break; + case LFT_ADAPTED_REQUEST_ALL_HEADERS: + out = al->headers.adapted_request; + + quote = 1; + + break; + case LFT_REPLY_ALL_HEADERS: out = al->headers.reply; @@ -1393,6 +1427,8 @@ done: case LFT_ICAP_REP_HEADER: #endif + case LFT_ADAPTED_REQUEST_HEADER: + case LFT_REQUEST_HEADER: case LFT_REPLY_HEADER: @@ -1415,6 +1451,11 @@ done: case LFT_REQUEST_HEADER: lt->type = LFT_REQUEST_HEADER_ELEM; break; + + case LFT_ADAPTED_REQUEST_HEADER: + lt->type = LFT_ADAPTED_REQUEST_HEADER_ELEM; + break; + case LFT_REPLY_HEADER: lt->type = LFT_REPLY_HEADER_ELEM; break; @@ -1440,6 +1481,11 @@ done: case LFT_REQUEST_HEADER: lt->type = LFT_REQUEST_ALL_HEADERS; break; + + case LFT_ADAPTED_REQUEST_HEADER: + lt->type = LFT_ADAPTED_REQUEST_ALL_HEADERS; + break; + case LFT_REPLY_HEADER: lt->type = LFT_REPLY_ALL_HEADERS; break; @@ -1553,7 +1599,7 @@ accessLogDumpLogFormat(StoreEntry * entry, const char *name, logformat * definit case LFT_ICAP_REP_HEADER_ELEM: #endif case LFT_REQUEST_HEADER_ELEM: - + case LFT_ADAPTED_REQUEST_HEADER_ELEM: case LFT_REPLY_HEADER_ELEM: if (t->data.header.separator != ',') @@ -1567,6 +1613,9 @@ accessLogDumpLogFormat(StoreEntry * entry, const char *name, logformat * definit case LFT_REQUEST_HEADER_ELEM: type = LFT_REQUEST_HEADER_ELEM; break; + case LFT_ADAPTED_REQUEST_HEADER_ELEM: + type = LFT_ADAPTED_REQUEST_HEADER_ELEM; + break; case LFT_REPLY_HEADER_ELEM: type = LFT_REPLY_HEADER_ELEM; break; @@ -1588,7 +1637,7 @@ accessLogDumpLogFormat(StoreEntry * entry, const char *name, logformat * definit break; case LFT_REQUEST_ALL_HEADERS: - + case LFT_ADAPTED_REQUEST_ALL_HEADERS: case LFT_REPLY_ALL_HEADERS: #if ICAP_CLIENT @@ -1601,6 +1650,9 @@ accessLogDumpLogFormat(StoreEntry * entry, const char *name, logformat * definit case LFT_REQUEST_ALL_HEADERS: type = LFT_REQUEST_HEADER; break; + case LFT_ADAPTED_REQUEST_ALL_HEADERS: + type = LFT_ADAPTED_REQUEST_HEADER; + break; case LFT_REPLY_ALL_HEADERS: type = LFT_REPLY_HEADER; break; @@ -2377,6 +2429,9 @@ accessLogFreeMemory(AccessLogEntry * aLogEntry) safe_free(aLogEntry->headers.reply); safe_free(aLogEntry->cache.authuser); + safe_free(aLogEntry->headers.adapted_request); + HTTPMSGUNLOCK(aLogEntry->adapted_request); + HTTPMSGUNLOCK(aLogEntry->reply); HTTPMSGUNLOCK(aLogEntry->request); #if ICAP_CLIENT