mod_deflate.c revision 2fc50921b88defeb7127985dfe4b4130175e069e
74b23191c8f49798f7513f324bbdbbe32f8a1db2Razvan Pascanu/* ====================================================================
74b23191c8f49798f7513f324bbdbbe32f8a1db2Razvan Pascanu * The Apache Software License, Version 1.1
74b23191c8f49798f7513f324bbdbbe32f8a1db2Razvan Pascanu * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
74b23191c8f49798f7513f324bbdbbe32f8a1db2Razvan Pascanu * Redistribution and use in source and binary forms, with or without
74b23191c8f49798f7513f324bbdbbe32f8a1db2Razvan Pascanu * modification, are permitted provided that the following conditions
74b23191c8f49798f7513f324bbdbbe32f8a1db2Razvan Pascanu * 1. Redistributions of source code must retain the above copyright
74b23191c8f49798f7513f324bbdbbe32f8a1db2Razvan Pascanu * notice, this list of conditions and the following disclaimer.
74b23191c8f49798f7513f324bbdbbe32f8a1db2Razvan Pascanu * 2. Redistributions in binary form must reproduce the above copyright
74b23191c8f49798f7513f324bbdbbe32f8a1db2Razvan Pascanu * notice, this list of conditions and the following disclaimer in
74b23191c8f49798f7513f324bbdbbe32f8a1db2Razvan Pascanu * the documentation and/or other materials provided with the
74b23191c8f49798f7513f324bbdbbe32f8a1db2Razvan Pascanu * distribution.
74b23191c8f49798f7513f324bbdbbe32f8a1db2Razvan Pascanu * 3. The end-user documentation included with the redistribution,
74b23191c8f49798f7513f324bbdbbe32f8a1db2Razvan Pascanu * if any, must include the following acknowledgment:
74b23191c8f49798f7513f324bbdbbe32f8a1db2Razvan Pascanu * "This product includes software developed by the
74b23191c8f49798f7513f324bbdbbe32f8a1db2Razvan Pascanu * Apache Software Foundation (http://www.apache.org/)."
74b23191c8f49798f7513f324bbdbbe32f8a1db2Razvan Pascanu * Alternately, this acknowledgment may appear in the software itself,
74b23191c8f49798f7513f324bbdbbe32f8a1db2Razvan Pascanu * if and wherever such third-party acknowledgments normally appear.
74b23191c8f49798f7513f324bbdbbe32f8a1db2Razvan Pascanu * 4. The names "Apache" and "Apache Software Foundation" must
3cbe795704877174d29dd463b98fd60daf0853bdGeorgel Calin * not be used to endorse or promote products derived from this
74b23191c8f49798f7513f324bbdbbe32f8a1db2Razvan Pascanu * software without prior written permission. For written
3cbe795704877174d29dd463b98fd60daf0853bdGeorgel Calin * permission, please contact apache@apache.org.
3cbe795704877174d29dd463b98fd60daf0853bdGeorgel Calin * 5. Products derived from this software may not be called "Apache",
74b23191c8f49798f7513f324bbdbbe32f8a1db2Razvan Pascanu * nor may "Apache" appear in their name, without prior written
74b23191c8f49798f7513f324bbdbbe32f8a1db2Razvan Pascanu * permission of the Apache Software Foundation.
74b23191c8f49798f7513f324bbdbbe32f8a1db2Razvan Pascanu * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
74b23191c8f49798f7513f324bbdbbe32f8a1db2Razvan Pascanu * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
74b23191c8f49798f7513f324bbdbbe32f8a1db2Razvan Pascanu * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
74b23191c8f49798f7513f324bbdbbe32f8a1db2Razvan Pascanu * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
74b23191c8f49798f7513f324bbdbbe32f8a1db2Razvan Pascanu * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
74b23191c8f49798f7513f324bbdbbe32f8a1db2Razvan Pascanu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
74b23191c8f49798f7513f324bbdbbe32f8a1db2Razvan Pascanu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
74b23191c8f49798f7513f324bbdbbe32f8a1db2Razvan Pascanu * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
74b23191c8f49798f7513f324bbdbbe32f8a1db2Razvan Pascanu * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
74b23191c8f49798f7513f324bbdbbe32f8a1db2Razvan Pascanu * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
74b23191c8f49798f7513f324bbdbbe32f8a1db2Razvan Pascanu * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
74b23191c8f49798f7513f324bbdbbe32f8a1db2Razvan Pascanu * SUCH DAMAGE.
74b23191c8f49798f7513f324bbdbbe32f8a1db2Razvan Pascanu * ====================================================================
74b23191c8f49798f7513f324bbdbbe32f8a1db2Razvan Pascanu * This software consists of voluntary contributions made by many
74b23191c8f49798f7513f324bbdbbe32f8a1db2Razvan Pascanu * individuals on behalf of the Apache Software Foundation. For more
74b23191c8f49798f7513f324bbdbbe32f8a1db2Razvan Pascanu * information on the Apache Software Foundation, please see
* mod_deflate.c: Perform deflate transfer-encoding on the fly
#include "httpd.h"
#include "http_config.h"
#include "http_log.h"
#include "apr_strings.h"
#include "apr_general.h"
#include "util_filter.h"
#include "apr_buckets.h"
#include "http_request.h"
#include "zlib.h"
#ifdef HAVE_ZUTIL_H
#include "zutil.h"
* zutil.h is not always included with zlib distributions (it is a private
* header), so this is straight from zlib 1.1.3's zutil.h.
#ifdef OS2
#ifdef AMIGA
#ifdef TOPS20
#ifndef OS_CODE
typedef struct deflate_filter_config_t
int windowSize;
int memlevel;
char *noteName;
const char *arg)
return NULL;
const char *arg)
return NULL;
const char *arg)
c->memlevel = i;
return NULL;
typedef struct deflate_ctx_t
unsigned long crc;
} deflate_ctx;
apr_bucket *e;
const char *accepts;
request_rec *r = f->r;
int zRC;
if (!ctx) {
char *buf;
if (r->main) {
* other than text/html, so set gzip-only-text/html
accepts++;
const char *data;
apr_bucket *b;
int done = 0;
if (APR_BUCKET_IS_EOS(e)) {
char *buf, *p;
unsigned int deflate_len;
if (deflate_len != 0) {
f->c->bucket_alloc);
if (done) {
*p++ = crc_array[0];
*p++ = len_array[0];
if (c->noteName) {
int total;
if (APR_BUCKET_IS_FLUSH(e)) {
return APR_EGENERAL;
return APR_SUCCESS;
{NULL}