Hi,
I wrote a mail a couple of days ago asking for guidelines about adding
Content-Encoding: gzip support for squid.
I have been working, but now I'm stucked.
I modified clientSendMoreData this way (see attached patch for more
detailed info):
if (http-out.offset == 0) {
check if log mime headers
rep = clientBuildReply(http, buf, size);
if (rep) {
body too large check
if (must_compress) {
compress 'size' bytes located at 'buf', producing 'zbytes'
of compressed bytes in zipped_buff.
size = zbytes - rep-hdr_sz;
memcpy(buf + rep-hdr_sz, zipped_buff, zbytes);
}
...
} else if (!http-request-range) {
if (must_compress) {
compress 'size' bytes located at 'buf' to zipped_buf
body_size += zbytes - pbytes;
size = zbytes;
memcpy(buf, zipped_buf, zbytes);
}
http-out.offset += body_size;
comm_write(fd, buf, size, clientWriteBodyComplete, http, NULL);
/* NULL because clientWriteBodyComplete frees it */
return;
}
...
And the call sequence from cache_log is this (omitting some entries):
clientProcessRequest: GET $URL
clientProcessRequest: TCP_MISS for $URL
clientProcessMiss: 'GET URL'
storeClientCopy: $HASH_KEY, seen 0, want 0, size 4096
storeClientCopy2: $HASH_KEY
storeClientCopy3: Waiting for more
storeClientCopy2: $HASH_KEY
storeClientCopy3: Copying from memory (1368 bytes, hi=1368, lo=0)
reply got from server is 1368 bytes = 133 headers + 1335 body
clientSendMoreData: $URL, 1368 bytes
clientSendMoreData: FD 9 '$URL', out.offset=0
clientBuildReplyHeader: can't keep-alive, unknown body size
clientSendMoreData: (no data sent yet) (http-out.offset == 0)
gzip_data: Got 1235 bytes, out avail 4086 bytes
have 1235 plain bytes and 4k zipped buffer to write output
gzip_data writes 10 bytes (gzip header) to outbuffer.
clientSendMoreData: Appending 10 bytes after 133 bytes of headers
clientSendMoreData: packed reply: 207 bytes
reply sent to client has: 207 bytes header + 10 bytes content
more content may come later
clientSendMoreData: queueing mb(217 bytes) and clientWriteComplete
clientWriteComplete: FD 9, sz 217, err 0, off 143, len -1
storeClientCopy: $HASH_KEY, seen 143, want 143, size 4096, cb !NULL,
cbdata !NULL
storeClientCopy2: $HASH_KEY
storeClientCopy3: Copying from memory (1225 bytes, hi=1368, lo=0)
ok, here comes my problem:
1235 bytes have been 'eaten' by last call to clientSendMoreData-
gzip_data, but storeClientCopy3 thinks it has only 'consumed' 10
bytes.
Should I alter http-entry-mem_obj-inmem_hi??
I guess storeClientCopy3 thinks that 10 bytes has been 'consumed'
because http-out.offset has been incremented by 10, rather than 1335
(original body size so far).
How should I fix this? I mean, clientSendMoreData is called with data is
has already processed.
Thank you very much in advance,
--
Gonzalo Arana [EMAIL PROTECTED]
UOL-Sinectis S.A.
--- squid-2.5.STABLE3/src/client_side.c Sat May 24 08:08:41 2003
+++ squid-2.5.STABLE3-visolve_tcp_rtsignal-gzip/src/client_side.c Wed Aug 20
15:31:24 2003
@@ -1395,57 +1396,87 @@
getMyHostname(), ntohs(Config.Sockaddr.http-s.sin_port));
#endif
if (httpReplyBodySize(request-method, rep) 0) {
debug(33, 3) (clientBuildReplyHeader: can't keep-alive, unknown body size\n);
request-flags.proxy_keepalive = 0;
}
/* Signal keep-alive if needed */
httpHeaderPutStr(hdr,
http-flags.accel ? HDR_CONNECTION : HDR_PROXY_CONNECTION,
request-flags.proxy_keepalive ? keep-alive : close);
#if ADD_X_REQUEST_URI
/*
* Knowing the URI of the request is useful when debugging persistent
* connections in a client; we cannot guarantee the order of http headers,
* but X-Request-URI is likely to be the very last header to ease use from a
* debugger [hdr-entries.count-1].
*/
httpHeaderPutStr(hdr, HDR_X_REQUEST_URI,
http-entry-mem_obj-url ? http-entry-mem_obj-url : http-uri);
#endif
+
+#if USE_CEGZIP
+/* If no ranges involved, and
+ * client accepts gzipped data, and
+ * content isn't alreadly 'encoded' (compressed, or something else)
+ */
+if (!request-range
+(httpHeaderGetAcceptEncoding(http-request-header) ENCODING_GZIP)
+ !httpHeaderGetContentEncoding(rep-header)) {
+int cl = 9; /* //TODO: write CompressionLevel(); */
+
+/* if client accepts gzipped data
+* and acls are matched, do compress.
+*/
+httpHeaderPutStr(hdr, HDR_CONTENT_ENCODING, gzip);
+assert(http-conn);
+debug(33, 3)(Setting compression %d level on fd %d\n, cl, http-conn-fd);
+http-compress.level = cl;
+http-compress.offset = rep-hdr_sz; /* //TODO: set to header size */
+http-compress.gzdata = xmalloc(sizeof(z_stream)); /* //TODO: use mem pools
instead */
+/* //TODO: where should I free gzdata */
+ deflateInit2(http-compress.gzdata, http-compress.level,
+