httpd-modules-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alexander Farber" <alexander.far...@gmail.com>
Subject Re: How to inflate a zipped content inside a module
Date Wed, 14 Feb 2007 11:34:31 GMT
Here is my Apache1-code for deflating. Maybe it helps you

static int
gzip_filter(request_rec *r, char *src, unsigned slen)
{
        char            *dst;
        z_stream        zstr;
        unsigned        dlen;

        zstr.zalloc     = gzip_alloc;
        zstr.zfree      = gzip_free;
        zstr.opaque     = r->pool;
        zstr.next_in    = src;
        zstr.avail_in   = slen;
        /* add 16 to MAX_WBITS to enforce gzip format */
        if (Z_OK != deflateInit2(&zstr, Z_DEFAULT_COMPRESSION, Z_DEFLATED,
            MAX_WBITS + 16, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY)) {
                ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
                    "deflateInit2() for gzip-format failed: %s", zstr.msg);
                return HTTP_SERVICE_UNAVAILABLE;
        }

        dlen = deflateBound(&zstr, slen);
        /* allocate 12 more bytes as workaround for zlib version <= 1.2.3 */
#if ZLIB_VERNUM <= 0x1230
        dlen += 12;
#endif

        dst = ap_palloc(r->pool, dlen);

        zstr.next_out   = dst;
        zstr.avail_out  = dlen;
        if (Z_STREAM_END != deflate(&zstr, Z_FINISH)) {
                ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
                    "deflate() failed: %s", zstr.msg);
                return HTTP_SERVICE_UNAVAILABLE;
        }

        ap_set_content_length(r, zstr.total_out);
        ap_table_setn(r->headers_out, "Content-Encoding", "gzip");
        ap_send_http_header(r);

        if (ap_rwrite(dst, zstr.total_out, r) != zstr.total_out)
                ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
                    "ap_rwrite of response data (%u bytes) failed", dlen);

        if (Z_OK != deflateEnd(&zstr))
                ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
                    "deflateEnd() failed: %s", zstr.msg);

        return OK;
}

On 2/1/07, Sai Jai Ganesh Gurubaran <sgurubar@cordys.com> wrote:
> More information:
>         Apache (2.0.59) is working as a forward proxy on Linux.
>
>             We have developed an output filter that gathers the response
> data on to a local buffer for further processing.
>
> It is working fine.
>
> The issue we have is that some time the data comes in a compressed
> format.
>
> Is there any way to inflate the content within the filter (stored in the
> local buffer only) so that our processing goes on smooth?
>
> (The original content is no way to be modified)



-- 
http://preferans.de

Mime
View raw message