curl-library
Re: Working around server bugs in deflate encoding
Date: Tue, 02 Nov 2004 01:07:39 +0530
Better patch for the same issue is attached. Please ignore the previous one.
Harshal
Index: content_encoding.c
===================================================================
RCS file: /cvs/DiscoveryServer/main/newsrc/External/curl/lib/content_encoding.c,v
retrieving revision 1.2
diff -u -r1.2 content_encoding.c
--- content_encoding.c	13 Aug 2004 14:10:36 -0000	1.2
+++ content_encoding.c	1 Nov 2004 19:40:43 -0000
@@ -80,6 +80,13 @@
   char decomp[DSIZ];            /* Put the decompressed data here. */
   z_stream *z = &k->z;          /* zlib state structure */
 
+  static char dummy_head[2] = 
+  {
+    0x8 + 0x7 * 0x10,
+    (((0x8 + 0x7 * 0x10) * 0x100 + 30) / 31 * 31) & 0xFF,
+  };
+  bool retry_done = FALSE;
+
   /* Initialize zlib? */
   if (!k->zlib_init) {
     z->zalloc = (alloc_func)Z_NULL;
@@ -104,6 +111,22 @@
     z->avail_out = DSIZ;
 
     status = inflate(z, Z_SYNC_FLUSH);
+    if (status == Z_DATA_ERROR && !retry_done) {
+      /* Some servers don't generate zlib headers.
+         Insert a dummy header and try again. */
+      retry_done = TRUE;
+      inflateReset(z);
+      z->next_in = (Bytef*) dummy_head;
+      z->avail_in = sizeof(dummy_head);
+
+      status = inflate(z, Z_NO_FLUSH);
+      if (status == Z_OK) {
+        z->next_in = (Bytef *)k->str;
+        z->avail_in = (uInt)nread;
+        status = inflate(z, Z_SYNC_FLUSH);
+      }
+    }
+
     if (status == Z_OK || status == Z_STREAM_END) {
       if (DSIZ - z->avail_out) {
         result = Curl_client_write(data, CLIENTWRITE_BODY, decomp,
Received on 2004-11-01