--------------------- PatchSet 3876 Date: 2006/10/25 04:57:03 Author: rousskov Branch: squid3-icap Tag: (none) Log: - Supply HTTP request URL path to the ICAP service when figuring out preview size, as the new ICAPServiceRep API demands. - Do not assume that HTTP request is always available, although it probably is always available and the code can be simplified a little if the latter is the case. Members: src/ICAP/ICAPModXact.cc:1.1.2.16->1.1.2.17 src/ICAP/ICAPModXact.h:1.1.2.6->1.1.2.7 Index: squid3/src/ICAP/ICAPModXact.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/ICAP/ICAPModXact.cc,v retrieving revision 1.1.2.16 retrieving revision 1.1.2.17 diff -u -r1.1.2.16 -r1.1.2.17 --- squid3/src/ICAP/ICAPModXact.cc 24 Oct 2006 14:16:41 -0000 1.1.2.16 +++ squid3/src/ICAP/ICAPModXact.cc 25 Oct 2006 04:57:03 -0000 1.1.2.17 @@ -970,10 +970,21 @@ // build HTTP request header, if any ICAP::Method m = s.method; - if (ICAP::methodRespmod == m && virgin->data->cause) - encapsulateHead(buf, "req-hdr", httpBuf, virgin->data->cause); - else if (ICAP::methodReqmod == m) - encapsulateHead(buf, "req-hdr", httpBuf, virgin->data->header); + const HttpRequest *request = virgin->data->cause ? + virgin->data->cause : + dynamic_cast(virgin->data->header); + + // to simplify, we could we assume that request is always available + + String urlPath; + if (request) { + urlPath = request->urlpath; + if (ICAP::methodRespmod == m) + encapsulateHead(buf, "req-hdr", httpBuf, request); + else + if (ICAP::methodReqmod == m) + encapsulateHead(buf, "req-hdr", httpBuf, virgin->data->header); + } if (ICAP::methodRespmod == m) if (const MsgPipeData::Header *prime = virgin->data->header) @@ -988,7 +999,7 @@ buf.append(ICAP::crlf, 2); // terminate Encapsulated line - if (shouldPreview()) { + if (shouldPreview(urlPath)) { buf.Printf("Preview: %d\r\n", (int)preview.ad()); virginSendClaim.protectUpTo(preview.ad()); } @@ -999,16 +1010,12 @@ virginSendClaim.protectAll(); } - const HttpRequest *request = virgin->data->cause ? - virgin->data->cause : - dynamic_cast(virgin->data->header); - - if (TheICAPConfig.send_client_ip) + if (TheICAPConfig.send_client_ip && request) if (request->client_addr.s_addr != any_addr.s_addr && request->client_addr.s_addr != no_addr.s_addr) buf.Printf("X-Client-IP: %s\r\n", inet_ntoa(request->client_addr)); - if (TheICAPConfig.send_client_username) + if (TheICAPConfig.send_client_username && request) if (request->auth_user_request) if (request->auth_user_request->username()) buf.Printf("X-Client-Username: %s\r\n", request->auth_user_request->username()); @@ -1041,7 +1048,7 @@ } // decides whether to offer a preview and calculates its size -bool ICAPModXact::shouldPreview() +bool ICAPModXact::shouldPreview(const String &urlPath) { size_t wantedSize; @@ -1050,8 +1057,8 @@ return false; } - if (!service().wantsPreview(wantedSize)) { - debugs(93, 5, "ICAPModXact should not offer preview"); + if (!service().wantsPreview(urlPath, wantedSize)) { + debugs(93, 5, "ICAPModXact should not offer preview for " << urlPath); return false; } Index: squid3/src/ICAP/ICAPModXact.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/ICAP/ICAPModXact.h,v retrieving revision 1.1.2.6 retrieving revision 1.1.2.7 diff -u -r1.1.2.6 -r1.1.2.7 --- squid3/src/ICAP/ICAPModXact.h 9 Oct 2006 17:32:00 -0000 1.1.2.6 +++ squid3/src/ICAP/ICAPModXact.h 25 Oct 2006 04:57:03 -0000 1.1.2.7 @@ -1,6 +1,6 @@ /* - * $Id: ICAPModXact.h,v 1.1.2.6 2006/10/09 17:32:00 rousskov Exp $ + * $Id: ICAPModXact.h,v 1.1.2.7 2006/10/25 04:57:03 rousskov Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -178,7 +178,7 @@ void closeChunk(MemBuf &buf); void virginConsume(); - bool shouldPreview(); + bool shouldPreview(const String &urlPath); bool shouldAllow204(); void prepBackup(size_t expectedSize); void backup(const MemBuf &buf);