--------------------- PatchSet 6668 Date: 2005/05/15 20:10:33 Author: chtsanti Branch: icap-2_5 Tag: (none) Log: http 0.9 support (no responce headers) resh_hdr missing in icap responce some correction in memory usage in 204/preview 204 responces outside preview are not enabled by default Some other corrections....... Members: src/icap_respmod.c:1.1.2.54->1.1.2.55 src/squid.h:1.13.6.6.2.10->1.13.6.6.2.11 Index: squid/src/icap_respmod.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/Attic/icap_respmod.c,v retrieving revision 1.1.2.54 retrieving revision 1.1.2.55 diff -u -r1.1.2.54 -r1.1.2.55 --- squid/src/icap_respmod.c 14 May 2005 07:55:58 -0000 1.1.2.54 +++ squid/src/icap_respmod.c 15 May 2005 20:10:33 -0000 1.1.2.55 @@ -1,6 +1,6 @@ /* - * $Id: icap_respmod.c,v 1.1.2.54 2005/05/14 07:55:58 chtsanti Exp $ + * $Id: icap_respmod.c,v 1.1.2.55 2005/05/15 20:10:33 chtsanti Exp $ * * DEBUG: section 81 Internet Content Adaptation Protocol (ICAP) Client * AUTHOR: Geetha Manjunath, Hewlett Packard Company @@ -83,8 +83,8 @@ { MemBuf mb_hdr; char *client_addr; - int o2; - int o3; + int o2=0; + int o3=0; int hlen; int consumed; icap_service *service; @@ -94,31 +94,46 @@ memBufDefInit(&icap->respmod.req_hdr_copy); memBufAppend(&icap->respmod.req_hdr_copy, buf, len); - hlen = headersEnd(icap->respmod.req_hdr_copy.buf, - icap->respmod.req_hdr_copy.size); - debug(81, 3) ("buildRespModHeader: headersEnd = %d\n", hlen); - if (0 == hlen) - return 0; - /* - * calc how many bytes from this 'buf' went towards the - * reply header. - */ - consumed = hlen - (icap->respmod.req_hdr_copy.size - len); - debug(81, 3) ("buildRespModHeader: consumed = %d\n", consumed); + if (icap->respmod.req_hdr_copy.size > 4 && strncmp(icap->respmod.req_hdr_copy.buf, "HTTP/", 5)) { + debug(81, 3) ("buildRespModHeader: Non-HTTP-compliant header: '%s'\n", buf); + /* + *Possible we can consider that we did not have http responce headers + *(maybe HTTP 0.9 protocol), lets returning -1... + */ + consumed=-1; + o2=-1; + memBufDefInit(&mb_hdr); + } + else{ - /* - * now, truncate our req_hdr_copy at the header end. - * this 'if' statement might be unncessary? - */ - if (hlen < icap->respmod.req_hdr_copy.size) - icap->respmod.req_hdr_copy.size = hlen; + hlen = headersEnd(icap->respmod.req_hdr_copy.buf, + icap->respmod.req_hdr_copy.size); + debug(81, 3) ("buildRespModHeader: headersEnd = %d(%s)\n", hlen,buf); + if (0 == hlen) + return 0; - /* Copy request header */ - memBufDefInit(&mb_hdr); - httpBuildRequestPrefix(icap->request, icap->request, - icap->respmod.entry, &mb_hdr, icap->http_flags); - o2 = mb_hdr.size; + /* + * calc how many bytes from this 'buf' went towards the + * reply header. + */ + consumed = hlen - (icap->respmod.req_hdr_copy.size - len); + debug(81, 3) ("buildRespModHeader: consumed = %d\n", consumed); + + + /* + * now, truncate our req_hdr_copy at the header end. + * this 'if' statement might be unncessary? + */ + if (hlen < icap->respmod.req_hdr_copy.size) + icap->respmod.req_hdr_copy.size = hlen; + + /* Copy request header */ + memBufDefInit(&mb_hdr); + httpBuildRequestPrefix(icap->request, icap->request, + icap->respmod.entry, &mb_hdr, icap->http_flags); + o2 = mb_hdr.size; + } /* Copy response header - Append to request header mbuffer */ memBufAppend(&mb_hdr, @@ -218,19 +233,46 @@ } memBufDefInit(&mb); +#if SUPPORT_ICAP_204 || ICAP_PREVIEW /* * make a copy of the response in case ICAP server gives us a 204 */ + /* + * This piece of code is problematic for 204 responces outside preview. + * The icap->respmod.resp_copy continues to filled until we had responce + * If the icap server waits to gets all data before sends its responce + * then we are puting all downloading object to the main system memory. + * My opinion is that 204 responces outside preview must be disabled ..... + * /chtsanti + */ + if (len && icap->flags.copy_response) { - if (memBufIsNull(&icap->respmod.resp_copy)) - memBufDefInit(&icap->respmod.resp_copy); - memBufAppend(&icap->respmod.resp_copy, buf, len); + if (memBufIsNull(&icap->respmod.resp_copy)) + memBufDefInit(&icap->respmod.resp_copy); + memBufAppend(&icap->respmod.resp_copy, buf, len); } + +#endif + if (icap->sc == 0) { /* No data sent yet. Start with headers */ - icap->sc = buildRespModHeader(&mb, icap, buf, len, theEnd); - buf += icap->sc; - len -= icap->sc; + if((icap->sc = buildRespModHeader(&mb, icap, buf, len, theEnd))>0){ + buf += icap->sc; + len -= icap->sc; + } + /* + * Then we do not have http responce headers. All data (previous and those in buf) + * now are exist to icap->respmod.req_hdr_copy. Lets get them back....... + */ + if(icap->sc <0){ + memBufAppend(&icap->respmod.buffer, + icap->respmod.req_hdr_copy.buf, + icap->respmod.req_hdr_copy.size); + icap->sc=icap->respmod.req_hdr_copy.size; + icap->respmod.req_hdr_copy.size=0; + buf=NULL; + len=0; + } } if (0 == icap->sc) { /* check again; bail if we're not ready to send ICAP/HTTP hdrs */ @@ -405,6 +447,11 @@ comm_close(fd); return; }; + /* OK here we have responce. Lets stop filling the + * icap->respmod.resp_copy buffer .... + */ + icap->flags.copy_response = 0; + icapSetKeepAlive(icap, icap->icap_hdr.buf); #if ICAP_PREVIEW if (icap->flags.wait_for_preview_reply) { @@ -423,6 +470,11 @@ */ if (!memBufIsNull(&icap->icap_hdr)) memBufReset(&icap->icap_hdr); + + /*We do n't need it any more .......*/ + if (!memBufIsNull(&icap->respmod.resp_copy)) + memBufClean(&icap->respmod.resp_copy); + return; } if (204 == status) { @@ -451,11 +503,13 @@ /* * XXX ideally want to clean icap->respmod.resp_copy here * XXX ideally want to "close" ICAP server connection here + * OK do it.... */ + if (!memBufIsNull(&icap->respmod.resp_copy)) + memBufClean(&icap->respmod.resp_copy); return; } #endif - icap->flags.copy_response = 0; if (200 != status) { debug(81, 1) ("Unsupported status '%d' from ICAP server\n", status); /* Did not find a proper ICAP response */ @@ -684,7 +738,17 @@ * make a copy the HTTP response that we send to the ICAP server in * case it turns out to be a 204 */ +#ifdef SUPPORT_ICAP_204 icap->flags.copy_response = 1; +#elif ICAP_PREVIEW + if(preview_size < 0 || !Config.icapcfg.preview_enable) + icap->flags.copy_response = 0; + else + icap->flags.copy_response = 1; +#else + icap->flags.copy_response = 0; +#endif + statCounter.icap.all.requests++; debug(81, 3) ("icapRespModStart: returning %p\n", icap); return icap; @@ -790,6 +854,9 @@ return (icap->enc.res_body - icap->enc.res_hdr); if (icap->enc.null_body > -1 && icap->enc.res_hdr > -1) return icap->enc.null_body - icap->enc.res_hdr; + /*The case we did not get res_hdr .....*/ + if(icap->enc.res_body > -1 ) + return icap->enc.res_body; if (icap->enc.null_body > -1) return icap->enc.null_body; return -1; @@ -897,13 +964,15 @@ */ debug(81, 1) ("WARNING: untested code at %s:%d\n", __FILE__, __LINE__); - assert(icap->respmod.req_hdr_copy.size); - storeAppend(entry, - icap->respmod.req_hdr_copy.buf, - icap->respmod.req_hdr_copy.size); + if(icap->respmod.req_hdr_copy.size){/*For HTTP 0.9 we do not have headers*/ + storeAppend(entry, + icap->respmod.req_hdr_copy.buf, + icap->respmod.req_hdr_copy.size); + } icapProcessHttpReplyHeader(icap, icap->chunk_buf.buf, - icap->chunk_buf.size); + icap->chunk_buf.size); assert(icapHttpReplyHdrState(icap) == 2); + icap->chunk_size = 0;/*we are ready to read chunks of data now....*/ } else if (needed) { icapProcessHttpReplyHeader(icap, icap->chunk_buf.buf, icap->chunk_buf.size); Index: squid/src/squid.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/squid.h,v retrieving revision 1.13.6.6.2.10 retrieving revision 1.13.6.6.2.11 diff -u -r1.13.6.6.2.10 -r1.13.6.6.2.11 --- squid/src/squid.h 28 Mar 2005 18:04:34 -0000 1.13.6.6.2.10 +++ squid/src/squid.h 15 May 2005 20:10:33 -0000 1.13.6.6.2.11 @@ -1,6 +1,6 @@ /* - * $Id: squid.h,v 1.13.6.6.2.10 2005/03/28 18:04:34 chtsanti Exp $ + * $Id: squid.h,v 1.13.6.6.2.11 2005/05/15 20:10:33 chtsanti Exp $ * * AUTHOR: Duane Wessels * @@ -42,7 +42,7 @@ */ #ifdef HS_FEAT_ICAP #define ICAP_PREVIEW 1 -#define SUPPORT_ICAP_204 1 +#define SUPPORT_ICAP_204 0 #endif /*