cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Problem with CONTENT-ENCODING

From: Dobromir Velev <diadomraz_at_gmail.com>
Date: Mon, 12 Dec 2005 20:50:01 +0200

Here is a small patch that fixes the problem with the missing deflate header
in the IIS response. It checks the first byte of the content and if it
doesn't look like a header it tells zlib inflate() to process the raw deflate
data without looking for headers.

--- content_encoding.c 2005-03-31 10:02:03.000000000 +0300
+++ content_encoding.new.c 2005-12-12 20:29:23.389573722 +0200
@@ -149,14 +149,21 @@
   z_stream *z = &k->z; /* zlib state structure */

   /* Initialize zlib? */
- if (k->zlib_init == ZLIB_UNINIT) {
+ if (k->zlib_init == ZLIB_UNINIT && nread) {
     z->zalloc = (alloc_func)Z_NULL;
     z->zfree = (free_func)Z_NULL;
     z->opaque = 0;
     z->next_in = NULL;
     z->avail_in = 0;
- if (inflateInit(z) != Z_OK)
- return process_zlib_error(data, z);
+ if((k->str[0] & 0xf) != Z_DEFLATED){
+ if(inflateInit2(z,-MAX_WBITS) != Z_OK)
+ return process_zlib_error(data, z);
+ }
+ else{
+ if(inflateInit(z) != Z_OK)
+ return process_zlib_error(data, z);
+ }
+
     k->zlib_init = ZLIB_INIT;
   }

While testing it I encountered one more problem with broken server encoding.
Some server when asked explicitly for deflate encoding will respond with
"Content-encoding: deflate" header but will GZIP encode the data so the
decoding will fail.

This is definitely not a curl issue but I just wanted to let you know about
it.

Regards
Dobromir Velev

On Monday 05 December 2005 17:00, Daniel Stenberg wrote:
> On Mon, 5 Dec 2005, Dobromir Velev wrote:
> > Any idea where I can find more information about the data header expected
> > by zlib. It seems that IIS is sending incorrect deflated data - probably
> > some header is missing and the browsers don't check the header or have
> > some other way to deal with such cases. May be I'll be able to write some
> > workaround.
>
> I assume all details are in RFC1951 "DEFLATE Compressed Data Format
> Specification". Available all over, but here's the one on the curl site:
>
> http://curl.haxx.se/rfc/rfc1951.txt
>
> I recall someone once making a patch that would make libcurl try with and
> without a header or something, but I couldn't find it now and I know it was
> never applied because it was done against an older incarnation of libcurl's
> deflate code... (perhaps it had nothing to do with this and I'm just
> rambling!)
Received on 2005-12-12