diff options
author | Daniel Stenberg <daniel@haxx.se> | 2006-04-25 20:49:40 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2006-04-25 20:49:40 +0000 |
commit | 87c5ed8beca8ae36da5c38ef3594b56d132e7dde (patch) | |
tree | 87db25221379b802b1aee0c31cec9e0711f822ed /lib/content_encoding.c | |
parent | ecc6c1f501ae835471b8844cba393835a12bb803 (diff) | |
download | curl-87c5ed8beca8ae36da5c38ef3594b56d132e7dde.tar.gz |
Paul Querna fixed libcurl to better deal with deflate content encoding when
the stream (wrongly) lacks a proper zlib header. This seems to be the case on
too many actual server implementations.
Diffstat (limited to 'lib/content_encoding.c')
-rw-r--r-- | lib/content_encoding.c | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/lib/content_encoding.c b/lib/content_encoding.c index e3e66b140..bcd5b838a 100644 --- a/lib/content_encoding.c +++ b/lib/content_encoding.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -87,7 +87,10 @@ static CURLcode inflate_stream(struct SessionHandle *data, struct Curl_transfer_keeper *k) { + int allow_restart = 1; z_stream *z = &k->z; /* zlib state structure */ + uInt nread = z->avail_in; + Bytef *orig_in = z->next_in; int status; /* zlib status */ CURLcode result = CURLE_OK; /* Curl_client_write status */ char *decomp; /* Put the decompressed data here. */ @@ -108,6 +111,7 @@ inflate_stream(struct SessionHandle *data, status = inflate(z, Z_SYNC_FLUSH); if (status == Z_OK || status == Z_STREAM_END) { + allow_restart = 0; if(DSIZ - z->avail_out) { result = Curl_client_write(data, CLIENTWRITE_BODY, decomp, DSIZ - z->avail_out); @@ -133,6 +137,19 @@ inflate_stream(struct SessionHandle *data, return result; } } + else if (allow_restart && status == Z_DATA_ERROR) { + /* some servers seem to not generate zlib headers, so this is an attempt + to fix and continue anyway */ + + inflateReset(z); + if (inflateInit2(z, -MAX_WBITS) != Z_OK) { + return process_zlib_error(data, z); + } + z->next_in = orig_in; + z->avail_in = nread; + allow_restart = 0; + continue; + } else { /* Error; exit loop, handle below */ free(decomp); return exit_zlib(z, &k->zlib_init, process_zlib_error(data, z)); |