mod_deflate.c revision 5bfaaf573bacb45c1cf290ce85ecc676587e8a64
9e36526b3e4a01ba4c0e63d263261653628eaa0fChristian Maeder/* Licensed to the Apache Software Foundation (ASF) under one or more
3aa7e4492a7e28b37d1a0b23f5bfe2109f87d4d6Christian Maeder * contributor license agreements. See the NOTICE file distributed with
3aa7e4492a7e28b37d1a0b23f5bfe2109f87d4d6Christian Maeder * this work for additional information regarding copyright ownership.
3aa7e4492a7e28b37d1a0b23f5bfe2109f87d4d6Christian Maeder * The ASF licenses this file to You under the Apache License, Version 2.0
277f12a72ee6876b9c48f01ef34d7cde65a423c8Christian Maeder * (the "License"); you may not use this file except in compliance with
277f12a72ee6876b9c48f01ef34d7cde65a423c8Christian Maeder * the License. You may obtain a copy of the License at
699511266869036921be9c7ae6ac83d1b66ba51dChristian Maeder * http://www.apache.org/licenses/LICENSE-2.0
6f91f82f723d1dd870b38d8ffb0aa9e8855c6ba8Christian Maeder * Unless required by applicable law or agreed to in writing, software
6f91f82f723d1dd870b38d8ffb0aa9e8855c6ba8Christian Maeder * distributed under the License is distributed on an "AS IS" BASIS,
5de34eba726f63d1522bf17a857309a6208ce0b5Christian Maeder * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5de34eba726f63d1522bf17a857309a6208ce0b5Christian Maeder * See the License for the specific language governing permissions and
5de34eba726f63d1522bf17a857309a6208ce0b5Christian Maeder * limitations under the License.
5de34eba726f63d1522bf17a857309a6208ce0b5Christian Maeder * mod_deflate.c: Perform deflate content-encoding on the fly
5de34eba726f63d1522bf17a857309a6208ce0b5Christian Maeder * Written by Ian Holsman, Justin Erenkrantz, and Nick Kew
5de34eba726f63d1522bf17a857309a6208ce0b5Christian Maeder * Portions of this software are based upon zlib code by Jean-loup Gailly
#include "httpd.h"
#include "http_config.h"
#include "http_log.h"
#include "apr_lib.h"
#include "apr_strings.h"
#include "apr_general.h"
#include "util_filter.h"
#include "apr_buckets.h"
#include "http_request.h"
#define APR_WANT_STRFUNC
#include "apr_want.h"
#include "zlib.h"
typedef struct deflate_filter_config_t
int windowSize;
int memlevel;
int compressionlevel;
char *note_ratio_name;
char *note_input_name;
char *note_output_name;
int found = 0;
if (!encoding) {
if (hdrs) {
char *ptr;
if (hdrs) {
if (hdrs) {
return found;
return ((unsigned long)string[0])
const char *arg)
return NULL;
const char *arg)
return NULL;
return NULL;
const char *arg)
c->memlevel = i;
return NULL;
const char *arg)
c->compressionlevel = i;
return NULL;
typedef struct deflate_ctx_t
unsigned char *buffer;
unsigned long crc;
unsigned char *validation_buffer;
int inflate_init;
int filter_init;
} deflate_ctx;
#define NO_UPDATE_CRC 0
int crc)
int done = 0;
unsigned int deflate_len;
apr_bucket *b;
if (deflate_len != 0) {
if (crc) {
if (done)
return zRC;
if (ctx)
return APR_SUCCESS;
char *d = newtag;
const char *s = etag;
s = transform;
e = d + transformlen;
apr_bucket *e;
request_rec *r = f->r;
int zRC;
const char *data;
return APR_SUCCESS;
if (!ctx) {
char *token;
const char *encoding;
if (APR_BUCKET_IS_EOS(e)) {
if (APR_BUCKET_IS_EOS(e)) {
if (APR_BUCKET_IS_METADATA(e)) {
e = APR_BUCKET_NEXT(e);
return rc;
e = APR_BUCKET_NEXT(e);
* other than text/html, so set gzip-only-text/html
"gzip-only-text/html");
if (encoding) {
const char *err_enc;
if (err_enc) {
if (r->content_encoding) {
: r->content_encoding;
if (encoding) {
if (*tmp) {
++tmp;
const char *accepts;
++accepts;
++accepts;
if (r->content_encoding) {
f->c->bucket_alloc);
apr_bucket *b;
if (APR_BUCKET_IS_EOS(e)) {
char *buf;
f->c->bucket_alloc);
if (c->note_input_name) {
if (c->note_output_name) {
if (c->note_ratio_name) {
if (APR_BUCKET_IS_FLUSH(e)) {
return APR_EGENERAL;
return rv;
if (APR_BUCKET_IS_METADATA(e)) {
return rv;
return APR_EGENERAL;
return APR_SUCCESS;
request_rec *r = f->r;
int zRC;
if (!ctx) {
if (!ap_is_initial_req(r)) {
return rv;
return rv;
return APR_EGENERAL;
return APR_EGENERAL;
return rv;
const char *data;
return APR_EGENERAL;
return APR_EGENERAL;
return APR_EGENERAL;
r->uri);
return APR_EGENERAL;
return APR_EGENERAL;
return APR_EGENERAL;
return APR_SUCCESS;
int zlib_method;
int zlib_flags;
apr_bucket *e;
request_rec *r = f->r;
int zRC;
return APR_SUCCESS;
if (!ctx) {
const char *data;
apr_bucket *b;
if (APR_BUCKET_IS_EOS(e)) {
return APR_EGENERAL;
return APR_EGENERAL;
return APR_EGENERAL;
if (APR_BUCKET_IS_FLUSH(e)) {
return APR_EGENERAL;
return rv;
if (APR_BUCKET_IS_METADATA(e)) {
return APR_EGENERAL;
return APR_EGENERAL ;
return APR_EGENERAL;
return rv;
return APR_EGENERAL;
return APR_SUCCESS;
{NULL}