[prev in list] [next in list] [prev in thread] [next in thread] 

List:       squid-cvs
Subject:    s27_adri squid/src http.c,1.63.2.3.4.26,1.63.2.3.4.27 structs.h,1.158.2.5.4.10,1.158.2.5.4.11
From:       Adrian Chadd <adri () users ! sourceforge ! net>
Date:       2007-12-29 10:57:52
Message-ID: 20071229105756.34701.qmail () squid-cache ! org
[Download RAW message or body]

Update of cvs.devel.squid-cache.org:/cvsroot/squid/squid/src

Modified Files:
      Tag: s27_adri
	http.c structs.h 
Log Message:
Convert http.c to use a buf_t for its incoming buffer rather than the MemBuf.

The reply header membuf (httpState->reply_hdr) was hanging around in memory
until the reply was complete; it was used in a couple of places to check
whether the response header needed "checking" (for zero-sized replies and
for trimming whitespace.) It now uses the http parser "state" (if you can
call it that..) to determine whether the current buffer is being parsed
for headers.



Index: structs.h
===================================================================
RCS file: /cvsroot/squid/squid/src/structs.h,v
retrieving revision 1.158.2.5.4.10
retrieving revision 1.158.2.5.4.11
diff -C2 -d -r1.158.2.5.4.10 -r1.158.2.5.4.11
*** structs.h	29 Dec 2007 07:21:43 -0000	1.158.2.5.4.10
--- structs.h	29 Dec 2007 10:57:49 -0000	1.158.2.5.4.11
***************
*** 1109,1113 ****
      StoreEntry *entry;
      request_t *request;
-     MemBuf reply_hdr;
      int reply_hdr_state;
      peer *peer;			/* peer request made to */
--- 1109,1112 ----

Index: http.c
===================================================================
RCS file: /cvsroot/squid/squid/src/http.c,v
retrieving revision 1.63.2.3.4.26
retrieving revision 1.63.2.3.4.27
diff -C2 -d -r1.63.2.3.4.26 -r1.63.2.3.4.27
*** http.c	29 Dec 2007 09:08:23 -0000	1.63.2.3.4.26
--- http.c	29 Dec 2007 10:57:49 -0000	1.63.2.3.4.27
***************
*** 74,80 ****
      }
      storeUnlockObject(httpState->entry);
!     if (!memBufIsNull(&httpState->reply_hdr)) {
! 	memBufClean(&httpState->reply_hdr);
!     }
      requestUnlink(httpState->request);
      requestUnlink(httpState->orig_request);
--- 74,79 ----
      }
      storeUnlockObject(httpState->entry);
!     if (httpState->replybuf)
!         httpState->replybuf = buf_deref(httpState->replybuf);
      requestUnlink(httpState->request);
      requestUnlink(httpState->orig_request);
***************
*** 441,444 ****
--- 440,445 ----
  	storeKeyText(entry->hash.key));
  
+     debug(11, 2) ("httpProcessReplyHeaderBlock: FD %d: given %d byets to look \
at\n", httpState->fd, size); + 
      assert(httpState->reply_hdr_state == 0);
      hdr_len = size;
***************
*** 670,673 ****
--- 671,675 ----
      assert(len >= 0);
      storeBuffer(entry);
+     debug(11, 2) ("httpAppendBody: FD %d: given %d bytes to look at\n", \
httpState->fd, (int) len);  while (len > 0) {
  	if (httpState->chunk_size > 0) {
***************
*** 677,680 ****
--- 679,683 ----
  	    httpState->chunk_size -= size;
  	    storeAppend(httpState->entry, buf, size);
+ 	    debug(11, 2) ("httpAppendBody: FD %d: appended %d bytes\n", httpState->fd, \
(int) size);  buf += size;
  	    len -= size;
***************
*** 682,685 ****
--- 685,689 ----
  	    /* non-chunked without content-length */
  	    storeAppend(httpState->entry, buf, len);
+ 	    debug(11, 2) ("httpAppendBody: FD %d: appended %d bytes\n", httpState->fd, \
(int) len);  len = 0;
  	} else if (httpState->flags.chunked) {
***************
*** 773,777 ****
      /* Is it a incomplete reply? */
      if (httpState->chunk_size > 0) {
! 	debug(11, 1) ("Short response from '%s' on port %d. Expecting %" PRINTF_OFF_T " \
octets more\n", storeUrl(entry), comm_local_port(fd), httpState->chunk_size);  \
comm_close(fd);  return;
--- 777,781 ----
      /* Is it a incomplete reply? */
      if (httpState->chunk_size > 0) {
! 	debug(11, 1) ("Short response from FD %d: '%s' on port %d. Expecting %" \
PRINTF_OFF_T " octets more\n", fd, storeUrl(entry), comm_local_port(fd), \
httpState->chunk_size);  comm_close(fd);
  	return;
***************
*** 874,877 ****
--- 878,882 ----
      int done = 0;
      size_t read_sz = SQUID_TCP_SO_RCVBUF;
+     int oldlen = -1;
  #if DELAY_POOLS
      delay_id delay_id;
***************
*** 897,903 ****
      /* XXX this breaks delay pools for now - need to pass in a 'max read size' \
parameter to memBufFill */  
!     if (memBufIsNull(&httpState->reply_hdr))
!        memBufDefInit(&httpState->reply_hdr);
!     len = memBufFill(&httpState->reply_hdr, fd);
  
      buffer_filled = len == read_sz;
--- 902,910 ----
      /* XXX this breaks delay pools for now - need to pass in a 'max read size' \
parameter to memBufFill */  
!     if (httpState->replybuf == NULL)
!         httpState->replybuf = buf_create_size(8192);
!     oldlen = buf_len(httpState->replybuf);
!     len = buf_fill(httpState->replybuf, fd, 1);
!     debug(11, 2) ("httpReadReply: FD %d: read %d bytes, buffer changed from %d to \
%d bytes\n", fd, (int) len, (int) oldlen, buf_len(httpState->replybuf));  
      buffer_filled = len == read_sz;
***************
*** 915,922 ****
  	IOStats.Http.read_hist[bin]++;
      }
!     if (!httpState->reply_hdr.size && len > 0 && fd_table[fd].uses > 1) {
  	/* Skip whitespace */
          /* XXX must redo this later once we're using buf's and offset pointers, not \
                MemBuf's */
! 	while (len > 0 && xisspace(*(httpState->reply_hdr.buf + buf_start))) {
  	    buf_start++;
              len--;
--- 922,929 ----
  	IOStats.Http.read_hist[bin]++;
      }
!     if (httpState->reply_hdr_state == 0 && oldlen == 0 && len > 0 && \
fd_table[fd].uses > 1) {  /* Skip whitespace */
          /* XXX must redo this later once we're using buf's and offset pointers, not \
                MemBuf's */
! 	while (len > 0 && xisspace(buf_get_chr(httpState->replybuf, buf_start))) {
  	    buf_start++;
              len--;
***************
*** 929,932 ****
--- 936,940 ----
  	}
      }
+     debug(11, 2) ("httpReadReply: FD %d: buf_start is %d, leaving %d bytes in the \
buffer\n", httpState->fd, buf_start, buf_len(httpState->replybuf) - buf_start);  if \
(len < 0) {  debug(11, 2) ("httpReadReply: FD %d: read failure: %s.\n",
***************
*** 941,945 ****
  	    comm_close(fd);
  	}
!     } else if (len == 0 && entry->mem_obj->inmem_hi == 0 && \
!httpState->reply_hdr.size) {  fwdFail(httpState->fwd, errorCon(ERR_ZERO_SIZE_OBJECT, \
HTTP_BAD_GATEWAY, httpState->fwd->request));  httpState->eof = 1;
--- 949,953 ----
  	    comm_close(fd);
  	}
!     } else if (httpState->reply_hdr_state == 0 && len == 0 && \
entry->mem_obj->inmem_hi == 0 && oldlen == 0) {  fwdFail(httpState->fwd, \
errorCon(ERR_ZERO_SIZE_OBJECT, HTTP_BAD_GATEWAY, httpState->fwd->request));  \
                httpState->eof = 1;
***************
*** 956,962 ****
  	     */
  	    /* Fake an "end-of-headers" to work around such broken servers */
!             memBufAppend(&httpState->reply_hdr, "\r\n", 2);
!             assert(buf_start < httpState->reply_hdr.size);
! 	    httpProcessReplyHeaderBlock(httpState, httpState->reply_hdr.buf, \
httpState->reply_hdr.size, buf_start);  }
  	if (entry->mem_obj->reply->sline.status == HTTP_HEADER_TOO_LARGE) {
--- 964,970 ----
  	     */
  	    /* Fake an "end-of-headers" to work around such broken servers */
!             buf_append(httpState->replybuf, "\r\n", 2, BF_NONE);
!             assert(buf_start < buf_len(httpState->replybuf));
! 	    httpProcessReplyHeaderBlock(httpState, buf_buf(httpState->replybuf), \
buf_len(httpState->replybuf), buf_start);  }
  	if (entry->mem_obj->reply->sline.status == HTTP_HEADER_TOO_LARGE) {
***************
*** 981,986 ****
  	     */
  	    storeBuffer(entry);
!             assert(buf_start < httpState->reply_hdr.size);
! 	    done = httpProcessReplyHeaderBlock(httpState, httpState->reply_hdr.buf, \
httpState->reply_hdr.size, buf_start);  if (httpState->reply_hdr_state == 2) {
  		http_status s = entry->mem_obj->reply->sline.status;
--- 989,995 ----
  	     */
  	    storeBuffer(entry);
!             assert(buf_start < buf_len(httpState->replybuf));
! 	    done = httpProcessReplyHeaderBlock(httpState, buf_buf(httpState->replybuf), \
                buf_len(httpState->replybuf), buf_start);
! 	    debug(11, 2) ("httpReadReply: FD %d: httpProcessReplyHeaderBlock consumed %d \
bytes\n", httpState->fd, done);  if (httpState->reply_hdr_state == 2) {
  		http_status s = entry->mem_obj->reply->sline.status;
***************
*** 1008,1013 ****
  		    mb = httpReplyPack(reply);
  		    storeAppend(entry, mb.buf, mb.size);
!                     assert(buf_start < httpState->reply_hdr.size);
! 		    storeAppend(entry, httpState->reply_hdr.buf + buf_start, \
httpState->reply_hdr.size - buf_start);  httpReplyReset(reply);
  		    httpReplyParse(reply, mb.buf, mb.size);
--- 1017,1022 ----
  		    mb = httpReplyPack(reply);
  		    storeAppend(entry, mb.buf, mb.size);
!                     assert(buf_start < buf_len(httpState->replybuf));
! 		    storeAppend(entry, buf_buf(httpState->replybuf) + buf_start, \
buf_len(httpState->replybuf) - buf_start);  httpReplyReset(reply);
  		    httpReplyParse(reply, mb.buf, mb.size);
***************
*** 1029,1038 ****
  	    }
  	}
!         assert(! memBufIsNull(&httpState->reply_hdr));
!         assert(buf_start - done < httpState->reply_hdr.size);
          cbdataLock(httpState);
! 	httpAppendBody(httpState, httpState->reply_hdr.buf, httpState->reply_hdr.size, \
                done + buf_start, buffer_filled);
!         if (cbdataValid(httpState) && (! memBufIsNull(&httpState->reply_hdr)))
!             memBufReset(&httpState->reply_hdr);
          cbdataUnlock(httpState);
  	return;
--- 1038,1047 ----
  	    }
  	}
!         assert(httpState->replybuf);
!         assert(buf_start - done < buf_len(httpState->replybuf));
          cbdataLock(httpState);
! 	httpAppendBody(httpState, buf_buf(httpState->replybuf), \
                buf_len(httpState->replybuf), done + buf_start, buffer_filled);
!         if (cbdataValid(httpState) && httpState->replybuf)
!             httpState->replybuf = buf_deref(httpState->replybuf);
          cbdataUnlock(httpState);
  	return;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic