ICAP related preview mode patch

From: eugeny gladkih <john@dont-contact.us>
Date: Thu, 09 Dec 2004 14:37:18 +0300

Hi,

sorry, I've just forgotten to attach the patch content.
it's for squid-icap-2.5-200409161544-src

diff -Nabur ./old/icap_common.c ./new/icap_common.c
--- ./old/icap_common.c 2004-04-04 01:12:55.000000000 +0400
+++ ./new/icap_common.c 2004-12-08 14:16:29.000000000 +0300
@@ -282,9 +282,13 @@
 icapReadTimeout(int fd, void *data)
 {
     IcapStateData *icap = data;
- debug(81, 3) ("icapReadTimeout: FD %d, unreachable=1\n", fd);
     assert(fd == icap->icap_fd);
+ //AI: Dmitry Adamushko mod
+ if (icap->flags.wait_for_preview_reply || icap->flags.http_server_eof) {
+ debug(81, 3) ("icapReadTimeout: FD %d, unreachable=1\n", fd);
     icapOptSetUnreachable(icap->current_service);
+ } else
+ debug(81, 3) ("icapReadTimeout: FD %d, still reachable\n", fd);
     comm_close(fd);
 }
 
diff -Nabur ./old/icap_respmod.c ./new/icap_respmod.c
--- ./old/icap_respmod.c 2004-08-04 21:20:24.000000000 +0400
+++ ./new/icap_respmod.c 2004-12-08 14:16:29.000000000 +0300
@@ -188,7 +188,7 @@
     if (theEnd) {
         if (icap->respmod.res_body_sz)
             icap->flags.send_zero_chunk = 1;
- else
+ /*else*/ /*Why this "else" here? theEnd means http_server_eof=1!!! (Tsantilas) .... */
             icap->flags.http_server_eof = 1;
     }
     /*
@@ -230,7 +230,8 @@
         return;
     }
 #if ICAP_PREVIEW
- if (preview_size < 0) /* preview feature off */
+ if (preview_size < 0|| !Config.icapcfg.preview_enable) /* preview feature off; AI add fix
+ http://sourceforge.net/mailarchive/forum.php?thread_id=5803119&forum_id=8678 */
         icap->flags.preview_done = 1;
 
     if (!icap->flags.preview_done) {
@@ -289,11 +290,13 @@
             memBufAppend(&icap->respmod.buffer, buf, len);
         /* do not send any data now while waiting for preview response */
         /* but prepare for read more data on the HTTP connection */
- if (!icap->flags.http_server_eof) {
- debug(81, 3) ("icapSendRespMod: FD %d: commSetSelect on read icapRespModReadReply waiting for preview response.\n", icap->icap_fd);
- commSetSelect(icap->icap_fd, COMM_SELECT_READ, icapRespModReadReply,
- icap, 0);
- }
+
+ /*Here is not the right position for the commSetSelect. Better called in icapRespModReadReply. (Tsantilas) */
+ /* if (!icap->flags.http_server_eof) {*/
+ /* debug(81, 3) ("icapSendRespMod: FD %d: commSetSelect on read icapRespModReadReply waiting for preview response.\n", icap->icap_fd); */
+ /* commSetSelect(icap->icap_fd, COMM_SELECT_READ, icapRespModReadReply,
+ icap, 0); */
+ /* } */
         return;
     } else
 #endif
@@ -394,11 +397,16 @@
         if (status == 100) {
             debug(81, 5) ("icapRespModReadReply: 100 Continue received\n");
             icap->flags.wait_for_preview_reply = 0;
- /*
+ /* if http_server_eof
              * call again icapSendRespMod to handle data that
- * was received while waiting fot this ICAP response
+ * was received while waiting for this ICAP response
+ * else let http to call icapSendRespMod when new data arrived
              */
+ if(icap->flags.http_server_eof)
             icapSendRespMod(icap, NULL, 0, 0);
+ /* The following maybe needed ....(Tsantilas)*/
+ /*commSetSelect(fd, COMM_SELECT_READ, icapRespModReadReply, icap, 0);*/
+
             /*
              * reset the header to send the rest of the preview
              */
@@ -409,18 +417,21 @@
         } else if (status == 204) {
             debug(81, 5) ("icapRespModReadReply: 204 No modification received\n");
             icap->flags.wait_for_preview_reply = 0;
- if (icap->flags.http_server_eof) {
+
+ /* if (icap->flags.http_server_eof) {*/ /*Comment out by Tsantilas*/
                 /* Reset is required to avoid duplicate stmemFreeDataUpto ,
                  * but will I loose all info now ? */
                 /* storeEntryReset(icap->respmod.entry); */
                 /* stmemFreeDataUpto(&(entry->mem_obj->data_hdr), -icap->sc); */
- fwdComplete(icap->httpState->fwd);
- } else {
- commSetSelect(fd, COMM_SELECT_READ, icapRespModReadReply,
- icap, 0);
- }
- comm_close(fd);
- return;
+ /* fwdComplete(icap->httpState->fwd);*/ /*Comment out by Tsantilas*/
+ /* } else {*/ /*Comment out by Tsantilas*/
+ /* commSetSelect(fd, COMM_SELECT_READ, icapRespModReadReply,*/ /*Comment out by Tsantilas*/
+ /* icap, 0); */ /*Comment out by Tsantilas*/
+ /* }*/ /*Comment out by Tsantilas*/
+ /* comm_close(fd);*/ /*Comment out by Tsantilas*/
+ /* return; */ /*Comment out by Tsantilas*/
+ /*Previous region comment out because not needed!!!
+ The following code handles better returned 204 status. (Tsantilas) */
 #endif
         }
     }
@@ -443,6 +454,8 @@
             icap->respmod.resp_copy.buf,
             icap->respmod.resp_copy.size);
         icap->respmod.resp_copy.size = 0;
+
+
         if (icapReadReply2(icap) < 0)
             comm_close(fd);
         /*
@@ -704,16 +717,6 @@
 {
     debug(81, 3) ("icapPconnTransferDone: FD %d\n", fd);
     /*
- * Did we request a persistent connection?
- */
- /*
- * What does the reply have to say about keep-alive?
- */
- if (!icap->flags.keep_alive) {
- debug(81, 5) ("icapPconnTransferDone: keep_alive not set, ret 0\n");
- return 0;
- }
- /*
      * Be careful with 204 responses. Normally we are done when we
      * see the zero-end chunk, but that won't happen for 204s, so we
      * use an EOF indicator on the HTTP side instead.
@@ -730,13 +733,23 @@
         debug(81, 5) ("icapPconnTransferDone: no message body, ret 1\n");
         return 1;
     }
- if (icap->chunk_size != -2) {
+ if (icap->chunk_size == -2) {//AI: was != -2 ; and change content with bottom
         /* zero end chunk reached */
- debug(81, 5) ("icapPconnTransferDone: didnt get zero end chunk yet\n");
- return 0;
- }
     debug(81, 5) ("icapPconnTransferDone: got zero end chunk\n");
     return 1;
+ }
+ /*
+ * Did we request a persistent connection?
+ */
+ /*
+ * What does the reply have to say about keep-alive?
+ */
+ if (!icap->flags.keep_alive) {//AI: move from top
+ debug(81, 5) ("icapPconnTransferDone: keep_alive not set, ret 0\n");
+ return 0;
+ }
+ debug(81, 5) ("icapPconnTransferDone: didnt get zero end chunk yet\n");//AI: change with second top condition
+ return 0;
 }
 
 static int
@@ -765,6 +778,10 @@
     const request_t *request = icap->request;
     int len;
     debug(81, 5) ("icapReadReply: FD %d: icap %p.\n", fd, data);
+ if(icap->flags.no_content && !icap->flags.http_server_eof) {//AI
+ return;
+ }
+
     if (EBIT_TEST(entry->flags, ENTRY_ABORTED)) {
         comm_close(fd);
         return;
@@ -879,12 +896,14 @@
     }
     debug(81, 3) ("%s:%d: icap->chunk_buf.size=%d\n", __FILE__, __LINE__, (int) icap->chunk_buf.size);
     debug(81, 3) ("%s:%d: flags.no_content=%d\n", __FILE__, __LINE__, icap->flags.no_content);
- if (icap->flags.no_content) {
+ if (icap->flags.no_content ) {
         /* data from http.c is not chunked */
+ if(!EBIT_TEST(entry->flags, ENTRY_ABORTED)){
         debug(81, 3) ("copying %d bytes from chunk_buf to entry\n",
             icap->chunk_buf.size);
         storeAppend(entry, icap->chunk_buf.buf, icap->chunk_buf.size);
         icap->chunk_buf.size = 0;
+ }
     } else if (2 == icapHttpReplyHdrState(icap)) {
         if (icap->chunk_buf.size)
             icapParseChunkedBody(icap, storeAppend, entry);
@@ -907,7 +926,7 @@
         commSetTimeout(fd, -1, NULL, NULL);
         commSetSelect(fd, COMM_SELECT_READ, NULL, NULL, 0);
         comm_remove_close_handler(fd, icapStateFree, icap);
- pconnPush(fd, fd_table[fd].pconn_name, fd_table[fd].remote_port);
+ //pconnPush(fd, fd_table[fd].pconn_name, fd_table[fd].remote_port);//comment by AI
         storeComplete(entry);
         icap->icap_fd = -1;
         icapStateFree(-1, icap);

-- 
Yours sincerely, Eugeny.
Doctor Web, Ltd. http://www.drweb.com
Received on Thu Dec 09 2004 - 18:05:26 MST

This archive was generated by hypermail pre-2.1.9 : Fri Dec 31 2004 - 12:00:05 MST