--------------------- PatchSet 8292 Date: 2006/06/25 10:39:57 Author: chtsanti Branch: icap-2_5 Tag: (none) Log: Graeme Bissot reported that when icap server responds with 204 the download canceled after some minutes becouse connection to the icap server expired This patch dissociates the request from the icap connection in case of 204 responce, immediately after the responce received from icap server. Members: src/icap_respmod.c:1.1.2.65->1.1.2.66 Index: squid/src/icap_respmod.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/Attic/icap_respmod.c,v retrieving revision 1.1.2.65 retrieving revision 1.1.2.66 diff -u -r1.1.2.65 -r1.1.2.66 --- squid/src/icap_respmod.c 25 May 2006 16:04:55 -0000 1.1.2.65 +++ squid/src/icap_respmod.c 25 Jun 2006 10:39:57 -0000 1.1.2.66 @@ -1,6 +1,6 @@ /* - * $Id: icap_respmod.c,v 1.1.2.65 2006/05/25 16:04:55 chtsanti Exp $ + * $Id: icap_respmod.c,v 1.1.2.66 2006/06/25 10:39:57 chtsanti Exp $ * * DEBUG: section 81 Internet Content Adaptation Protocol (ICAP) Client * AUTHOR: Geetha Manjunath, Hewlett Packard Company @@ -39,6 +39,7 @@ static PF icapRespModGobble; extern PF icapReadReply; static PF icapRespModReadReply; +static void icapRespModKeepAliveOrClose(IcapStateData * icap); static int icapReadReply2(IcapStateData * icap); static void icapReadReply3(IcapStateData * icap); @@ -63,9 +64,8 @@ if (service->flags.need_x_client_ip && Config.icapcfg.send_client_ip) { memBufPrintf(mb, "X-Client-IP: %s\r\n", client_addr); } - if (service->flags.need_x_server_ip && Config.icapcfg.send_server_ip) - icapAddOriginIP(mb, icap->request->host); + icapAddOriginIP(mb, icap->request->host); if ((service->flags.need_x_authenticated_user && Config.icapcfg.send_auth_user) @@ -107,7 +107,7 @@ o2 = -1; memBufDefInit(&mb_hdr); httpBuildRequestPrefix(icap->request, icap->request, - icap->respmod.entry, &mb_hdr, icap->http_flags); + icap->respmod.entry, &mb_hdr, icap->http_flags); o3 = mb_hdr.size; } else { @@ -138,9 +138,9 @@ icap->respmod.entry, &mb_hdr, icap->http_flags); o2 = mb_hdr.size; - /* Copy response header - Append to request header mbuffer */ + /* Copy response header - Append to request header mbuffer */ memBufAppend(&mb_hdr, - icap->respmod.req_hdr_copy.buf, icap->respmod.req_hdr_copy.size); + icap->respmod.req_hdr_copy.buf, icap->respmod.req_hdr_copy.size); o3 = mb_hdr.size; } @@ -257,16 +257,15 @@ #endif if (icap->sc == 0) { - // http connection has been closed without sending us anything - if(len == 0 && theEnd == 1) { + // http connection has been closed without sending us anything + if (len == 0 && theEnd == 1) { ErrorState *err; err = errorCon(ERR_INVALID_RESP, HTTP_BAD_GATEWAY); err->request = requestLink(icap->request); errorAppendEntry(icap->respmod.entry, err); comm_close(icap->icap_fd); return; - } - + } /* No data sent yet. Start with headers */ if ((icap->sc = buildRespModHeader(&mb, icap, buf, len, theEnd)) > 0) { buf += icap->sc; @@ -500,6 +499,8 @@ #if SUPPORT_ICAP_204 || ICAP_PREVIEW if (204 == status) { debug(81, 3) ("got 204 status from ICAP server\n"); + icapRespModKeepAliveOrClose(icap); + debug(81, 3) ("setting icap->flags.no_content\n"); icap->flags.no_content = 1; /* @@ -511,7 +512,8 @@ icap->respmod.resp_copy.buf, icap->respmod.resp_copy.size); icap->respmod.resp_copy.size = 0; if (icapReadReply2(icap) < 0) - comm_close(fd); + icapStateFree(-1, icap); + /* * XXX ideally want to clean icap->respmod.resp_copy here * XXX ideally want to "close" ICAP server connection here @@ -806,21 +808,21 @@ int fd = icap->icap_fd; if (fd < 0) return; - if (!icap->flags.keep_alive) { - debug(81, 3) ("%s:%d keep_alive not set, closing\n", __FILE__, - __LINE__); - comm_close(fd); - return; - } debug(81, 3) ("%s:%d FD %d looks good, keeping alive\n", __FILE__, __LINE__, fd); commSetDefer(fd, NULL, NULL); commSetTimeout(fd, -1, NULL, NULL); commSetSelect(fd, COMM_SELECT_READ, NULL, NULL, 0); comm_remove_close_handler(fd, icapStateFree, icap); - pconnPush(fd, icap->current_service->hostname, icap->current_service->port); icap->icap_fd = -1; - icapStateFree(-1, icap); + if (!icap->flags.keep_alive) { + debug(81, 3) ("%s:%d keep_alive not set, closing\n", __FILE__, + __LINE__); + comm_close(fd); + return; + } else { + pconnPush(fd, icap->current_service->hostname, icap->current_service->port); + } } @@ -1039,10 +1041,18 @@ debug(81, 3) ("icapReadReply3\n"); if (EBIT_TEST(entry->flags, ENTRY_ABORTED)) { debug(81, 3) ("icapReadReply3: Entry Aborded\n"); - comm_close(fd); + if (icap->flags.no_content) + icapStateFree(-1, icap); + else + comm_close(fd); } else if (icapPconnTransferDone(fd, icap)) { storeComplete(entry); - icapRespModKeepAliveOrClose(icap); + if (icap->flags.no_content) + icapStateFree(-1, icap); + else { + icapRespModKeepAliveOrClose(icap); + icapStateFree(-1, icap); + } } else if (!icap->flags.no_content) { /* Wait for EOF condition */ commSetSelect(fd, COMM_SELECT_READ, icapReadReply, icap, 0);