1 /* ====================================================================
2 * The Apache Software License, Version 1.1
4 * Copyright (c) 2000-2003 The Apache Software Foundation. All rights
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
19 * 3. The end-user documentation included with the redistribution,
20 * if any, must include the following acknowledgment:
21 * "This product includes software developed by the
22 * Apache Software Foundation (http://www.apache.org/)."
23 * Alternately, this acknowledgment may appear in the software itself,
24 * if and wherever such third-party acknowledgments normally appear.
26 * 4. The names "Apache" and "Apache Software Foundation" must
27 * not be used to endorse or promote products derived from this
28 * software without prior written permission. For written
29 * permission, please contact apache@apache.org.
31 * 5. Products derived from this software may not be called "Apache",
32 * nor may "Apache" appear in their name, without prior written
33 * permission of the Apache Software Foundation.
35 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47 * ====================================================================
49 * This software consists of voluntary contributions made by many
50 * individuals on behalf of the Apache Software Foundation. For more
51 * information on the Apache Software Foundation, please see
52 * <http://www.apache.org/>.
54 * Portions of this software are based upon public domain software
55 * (zlib functions gz_open and gzwrite)
59 * mod_deflate.c: Perform deflate transfer-encoding on the fly
61 * Written by Ian Holsman (IanH@apache.org)
66 #include "http_config.h"
68 #include "apr_strings.h"
69 #include "apr_general.h"
70 #include "util_filter.h"
71 #include "apr_buckets.h"
72 #include "http_request.h"
73 #define APR_WANT_STRFUNC
81 /* As part of the encoding process, we must send what our OS_CODE is
82 * (or so it seems based on what I can tell of how gzip encoding works).
84 * zutil.h is not always included with zlib distributions (it is a private
85 * header), so this is straight from zlib 1.1.3's zutil.h.
91 #ifdef WIN32 /* Window 95 & Windows NT */
95 #if defined(VAXC) || defined(VMS)
103 #if defined(ATARI) || defined(atarist)
107 #if defined(MACOS) || defined(TARGET_OS_MAC)
111 #ifdef __50SERIES /* Prime/PRIMOS */
120 #define OS_CODE 0x03 /* assume Unix */
124 static const char deflateFilterName[] = "DEFLATE";
125 module AP_MODULE_DECLARE_DATA deflate_module;
127 typedef struct deflate_filter_config_t
131 int compressionlevel;
132 apr_size_t bufferSize;
133 char *note_ratio_name;
134 char *note_input_name;
135 char *note_output_name;
136 } deflate_filter_config;
138 /* windowsize is negative to suppress Zlib header */
139 #define DEFAULT_COMPRESSION Z_DEFAULT_COMPRESSION
140 #define DEFAULT_WINDOWSIZE -15
141 #define DEFAULT_MEMLEVEL 9
142 #define DEFAULT_BUFFERSIZE 8096
144 /* Outputs a long in LSB order to the given file
145 * only the bottom 4 bits are required for the deflate file format.
147 static void putLong(unsigned char *string, unsigned long x)
149 string[0] = (unsigned char)(x & 0xff);
150 string[1] = (unsigned char)((x & 0xff00) >> 8);
151 string[2] = (unsigned char)((x & 0xff0000) >> 16);
152 string[3] = (unsigned char)((x & 0xff000000) >> 24);
155 /* Inputs a string and returns a long.
157 static unsigned long getLong(unsigned char *string)
159 return ((unsigned long)string[0])
160 | (((unsigned long)string[1]) << 8)
161 | (((unsigned long)string[2]) << 16)
162 | (((unsigned long)string[3]) << 24);
165 static void *create_deflate_server_config(apr_pool_t *p, server_rec *s)
167 deflate_filter_config *c = apr_pcalloc(p, sizeof *c);
169 c->memlevel = DEFAULT_MEMLEVEL;
170 c->windowSize = DEFAULT_WINDOWSIZE;
171 c->bufferSize = DEFAULT_BUFFERSIZE;
172 c->compressionlevel = DEFAULT_COMPRESSION;
177 static const char *deflate_set_window_size(cmd_parms *cmd, void *dummy,
180 deflate_filter_config *c = ap_get_module_config(cmd->server->module_config,
187 return "DeflateWindowSize must be between 1 and 15";
189 c->windowSize = i * -1;
194 static const char *deflate_set_buffer_size(cmd_parms *cmd, void *dummy,
197 deflate_filter_config *c = ap_get_module_config(cmd->server->module_config,
202 return "DeflateBufferSize should be positive";
205 c->bufferSize = (apr_size_t)n;
209 static const char *deflate_set_note(cmd_parms *cmd, void *dummy,
210 const char *arg1, const char *arg2)
212 deflate_filter_config *c = ap_get_module_config(cmd->server->module_config,
216 c->note_ratio_name = apr_pstrdup(cmd->pool, arg1);
218 else if (!strcasecmp(arg1, "ratio")) {
219 c->note_ratio_name = apr_pstrdup(cmd->pool, arg2);
221 else if (!strcasecmp(arg1, "input")) {
222 c->note_input_name = apr_pstrdup(cmd->pool, arg2);
224 else if (!strcasecmp(arg1, "output")) {
225 c->note_output_name = apr_pstrdup(cmd->pool, arg2);
228 return apr_psprintf(cmd->pool, "Unknown note type %s", arg1);
234 static const char *deflate_set_memlevel(cmd_parms *cmd, void *dummy,
237 deflate_filter_config *c = ap_get_module_config(cmd->server->module_config,
244 return "DeflateMemLevel must be between 1 and 9";
251 static const char *deflate_set_compressionlevel(cmd_parms *cmd, void *dummy,
254 deflate_filter_config *c = ap_get_module_config(cmd->server->module_config,
261 return "Compression Level must be between 1 and 9";
263 c->compressionlevel = i;
269 static char deflate_magic[2] = { '\037', '\213' };
271 typedef struct deflate_ctx_t
274 unsigned char *buffer;
276 apr_bucket_brigade *bb, *proc_bb;
279 static apr_status_t deflate_out_filter(ap_filter_t *f,
280 apr_bucket_brigade *bb)
283 request_rec *r = f->r;
284 deflate_ctx *ctx = f->ctx;
286 deflate_filter_config *c = ap_get_module_config(r->server->module_config,
289 /* If we don't have a context, we need to ensure that it is okay to send
290 * the deflated content. If we have a context, that means we've done
291 * this before and we liked it.
292 * This could be not so nice if we always fail. But, if we succeed,
293 * we're in better shape.
297 const char *encoding, *accepts;
299 /* only work on main request/no subrequests */
301 ap_remove_output_filter(f);
302 return ap_pass_brigade(f->next, bb);
305 /* some browsers might have problems, so set no-gzip
306 * (with browsermatch) for them
308 if (apr_table_get(r->subprocess_env, "no-gzip")) {
309 ap_remove_output_filter(f);
310 return ap_pass_brigade(f->next, bb);
313 /* Some browsers might have problems with content types
314 * other than text/html, so set gzip-only-text/html
315 * (with browsermatch) for them
317 if (r->content_type == NULL
318 || strncmp(r->content_type, "text/html", 9)) {
319 const char *env_value = apr_table_get(r->subprocess_env,
320 "gzip-only-text/html");
321 if ( env_value && (strcmp(env_value,"1") == 0) ) {
322 ap_remove_output_filter(f);
323 return ap_pass_brigade(f->next, bb);
327 /* Let's see what our current Content-Encoding is.
328 * If gzip is present, don't gzip again. (We could, but let's not.)
330 encoding = apr_table_get(r->headers_out, "Content-Encoding");
334 err_enc = apr_table_get(r->err_headers_out, "Content-Encoding");
336 encoding = apr_pstrcat(r->pool, encoding, ",", err_enc, NULL);
340 encoding = apr_table_get(r->err_headers_out, "Content-Encoding");
344 const char *tmp = encoding;
346 token = ap_get_token(r->pool, &tmp, 0);
347 while (token && token[0]) {
348 if (!strcasecmp(token, "gzip")) {
349 ap_remove_output_filter(f);
350 return ap_pass_brigade(f->next, bb);
352 /* Otherwise, skip token */
354 token = ap_get_token(r->pool, &tmp, 0);
358 /* Even if we don't accept this request based on it not having
359 * the Accept-Encoding, we need to note that we were looking
360 * for this header and downstream proxies should be aware of that.
362 apr_table_setn(r->headers_out, "Vary", "Accept-Encoding");
364 /* if they don't have the line, then they can't play */
365 accepts = apr_table_get(r->headers_in, "Accept-Encoding");
366 if (accepts == NULL) {
367 ap_remove_output_filter(f);
368 return ap_pass_brigade(f->next, bb);
371 token = ap_get_token(r->pool, &accepts, 0);
372 while (token && token[0] && strcasecmp(token, "gzip")) {
375 token = ap_get_token(r->pool, &accepts, 0);
378 /* No acceptable token found. */
379 if (token == NULL || token[0] == '\0') {
380 ap_remove_output_filter(f);
381 return ap_pass_brigade(f->next, bb);
384 /* We're cool with filtering this. */
385 ctx = f->ctx = apr_pcalloc(r->pool, sizeof(*ctx));
386 ctx->bb = apr_brigade_create(r->pool, f->c->bucket_alloc);
387 ctx->buffer = apr_palloc(r->pool, c->bufferSize);
389 zRC = deflateInit2(&ctx->stream, c->compressionlevel, Z_DEFLATED,
390 c->windowSize, c->memlevel,
395 ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
396 "unable to init Zlib: "
397 "deflateInit2 returned %d: URL %s",
399 return ap_pass_brigade(f->next, bb);
402 /* RFC 1952 Section 2.3 dictates the gzip header:
404 * +---+---+---+---+---+---+---+---+---+---+
405 * |ID1|ID2|CM |FLG| MTIME |XFL|OS |
406 * +---+---+---+---+---+---+---+---+---+---+
408 * If we wish to populate in MTIME (as hinted in RFC 1952), do:
409 * putLong(date_array, apr_time_now() / APR_USEC_PER_SEC);
410 * where date_array is a char[4] and then print date_array in the
411 * MTIME position. WARNING: ENDIANNESS ISSUE HERE.
413 buf = apr_psprintf(r->pool, "%c%c%c%c%c%c%c%c%c%c", deflate_magic[0],
414 deflate_magic[1], Z_DEFLATED, 0 /* flags */,
415 0, 0, 0, 0 /* 4 chars for mtime */,
416 0 /* xflags */, OS_CODE);
417 e = apr_bucket_pool_create(buf, 10, r->pool, f->c->bucket_alloc);
418 APR_BRIGADE_INSERT_TAIL(ctx->bb, e);
420 /* If the entire Content-Encoding is "identity", we can replace it. */
421 if (!encoding || !strcasecmp(encoding, "identity")) {
422 apr_table_setn(r->headers_out, "Content-Encoding", "gzip");
425 apr_table_mergen(r->headers_out, "Content-Encoding", "gzip");
427 apr_table_unset(r->headers_out, "Content-Length");
429 /* initialize deflate output buffer */
430 ctx->stream.next_out = ctx->buffer;
431 ctx->stream.avail_out = c->bufferSize;
434 APR_BRIGADE_FOREACH(e, bb) {
441 if (APR_BUCKET_IS_EOS(e)) {
443 unsigned int deflate_len;
445 ctx->stream.avail_in = 0; /* should be zero already anyway */
447 deflate_len = c->bufferSize - ctx->stream.avail_out;
449 if (deflate_len != 0) {
450 b = apr_bucket_heap_create((char *)ctx->buffer,
453 APR_BRIGADE_INSERT_TAIL(ctx->bb, b);
454 ctx->stream.next_out = ctx->buffer;
455 ctx->stream.avail_out = c->bufferSize;
462 zRC = deflate(&ctx->stream, Z_FINISH);
464 if (deflate_len == 0 && zRC == Z_BUF_ERROR) {
468 done = (ctx->stream.avail_out != 0 || zRC == Z_STREAM_END);
470 if (zRC != Z_OK && zRC != Z_STREAM_END) {
475 buf = apr_palloc(r->pool, 8);
476 putLong((unsigned char *)&buf[0], ctx->crc);
477 putLong((unsigned char *)&buf[4], ctx->stream.total_in);
479 b = apr_bucket_pool_create(buf, 8, r->pool, f->c->bucket_alloc);
480 APR_BRIGADE_INSERT_TAIL(ctx->bb, b);
481 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
482 "Zlib: Compressed %ld to %ld : URL %s",
483 ctx->stream.total_in, ctx->stream.total_out, r->uri);
485 /* leave notes for logging */
486 if (c->note_input_name) {
487 apr_table_setn(r->notes, c->note_input_name,
488 (ctx->stream.total_in > 0)
489 ? apr_off_t_toa(r->pool,
490 ctx->stream.total_in)
494 if (c->note_output_name) {
495 apr_table_setn(r->notes, c->note_output_name,
496 (ctx->stream.total_in > 0)
497 ? apr_off_t_toa(r->pool,
498 ctx->stream.total_out)
502 if (c->note_ratio_name) {
503 apr_table_setn(r->notes, c->note_ratio_name,
504 (ctx->stream.total_in > 0)
506 (int)(ctx->stream.total_out
508 / ctx->stream.total_in))
512 deflateEnd(&ctx->stream);
514 /* Remove EOS from the old list, and insert into the new. */
515 APR_BUCKET_REMOVE(e);
516 APR_BRIGADE_INSERT_TAIL(ctx->bb, e);
518 /* Okay, we've seen the EOS.
519 * Time to pass it along down the chain.
521 return ap_pass_brigade(f->next, ctx->bb);
524 if (APR_BUCKET_IS_FLUSH(e)) {
526 zRC = deflate(&(ctx->stream), Z_SYNC_FLUSH);
531 ctx->stream.next_out = ctx->buffer;
532 len = c->bufferSize - ctx->stream.avail_out;
534 b = apr_bucket_heap_create((char *)ctx->buffer, len,
535 NULL, f->c->bucket_alloc);
536 APR_BRIGADE_INSERT_TAIL(ctx->bb, b);
537 ctx->stream.avail_out = c->bufferSize;
539 bkt = apr_bucket_flush_create(f->c->bucket_alloc);
540 APR_BRIGADE_INSERT_TAIL(ctx->bb, bkt);
541 ap_pass_brigade(f->next, ctx->bb);
546 apr_bucket_read(e, &data, &len, APR_BLOCK_READ);
548 /* This crc32 function is from zlib. */
549 ctx->crc = crc32(ctx->crc, (const Bytef *)data, len);
552 ctx->stream.next_in = (unsigned char *)data; /* We just lost const-ness,
553 * but we'll just have to
555 ctx->stream.avail_in = len;
557 while (ctx->stream.avail_in != 0) {
558 if (ctx->stream.avail_out == 0) {
559 ctx->stream.next_out = ctx->buffer;
560 len = c->bufferSize - ctx->stream.avail_out;
562 b = apr_bucket_heap_create((char *)ctx->buffer, len,
563 NULL, f->c->bucket_alloc);
564 APR_BRIGADE_INSERT_TAIL(ctx->bb, b);
565 ctx->stream.avail_out = c->bufferSize;
568 zRC = deflate(&(ctx->stream), Z_NO_FLUSH);
575 apr_brigade_cleanup(bb);
579 /* This is the deflate input filter (inflates). */
580 static apr_status_t deflate_in_filter(ap_filter_t *f,
581 apr_bucket_brigade *bb,
582 ap_input_mode_t mode,
583 apr_read_type_e block,
587 request_rec *r = f->r;
588 deflate_ctx *ctx = f->ctx;
591 deflate_filter_config *c;
593 /* just get out of the way of things we don't want. */
594 if (mode != AP_MODE_READBYTES) {
595 return ap_get_brigade(f->next, bb, mode, block, readbytes);
598 c = ap_get_module_config(r->server->module_config, &deflate_module);
602 char *token, deflate_hdr[10];
603 const char *encoding;
606 /* only work on main request/no subrequests */
608 ap_remove_input_filter(f);
609 return ap_get_brigade(f->next, bb, mode, block, readbytes);
612 /* Let's see what our current Content-Encoding is.
613 * If gzip is present, don't gzip again. (We could, but let's not.)
615 encoding = apr_table_get(r->headers_in, "Content-Encoding");
617 const char *tmp = encoding;
619 token = ap_get_token(r->pool, &tmp, 0);
620 while (token && token[0]) {
621 if (!strcasecmp(token, "gzip")) {
625 /* Otherwise, skip token */
627 token = ap_get_token(r->pool, &tmp, 0);
632 ap_remove_input_filter(f);
633 return ap_get_brigade(f->next, bb, mode, block, readbytes);
636 f->ctx = ctx = apr_pcalloc(f->r->pool, sizeof(*ctx));
637 ctx->bb = apr_brigade_create(r->pool, f->c->bucket_alloc);
638 ctx->proc_bb = apr_brigade_create(r->pool, f->c->bucket_alloc);
639 ctx->buffer = apr_palloc(r->pool, c->bufferSize);
641 rv = ap_get_brigade(f->next, ctx->bb, AP_MODE_READBYTES, block, 10);
642 if (rv != APR_SUCCESS) {
647 rv = apr_brigade_flatten(ctx->bb, deflate_hdr, &len);
648 if (rv != APR_SUCCESS) {
652 /* We didn't get the magic bytes. */
654 deflate_hdr[0] != deflate_magic[0] ||
655 deflate_hdr[1] != deflate_magic[1]) {
659 /* We can't handle flags for now. */
660 if (deflate_hdr[3] != 0) {
664 zRC = inflateInit2(&ctx->stream, c->windowSize);
668 inflateEnd(&ctx->stream);
669 ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
670 "unable to init Zlib: "
671 "inflateInit2 returned %d: URL %s",
673 ap_remove_input_filter(f);
674 return ap_get_brigade(f->next, bb, mode, block, readbytes);
677 /* initialize deflate output buffer */
678 ctx->stream.next_out = ctx->buffer;
679 ctx->stream.avail_out = c->bufferSize;
681 apr_brigade_cleanup(ctx->bb);
684 if (APR_BRIGADE_EMPTY(ctx->proc_bb)) {
685 rv = ap_get_brigade(f->next, ctx->bb, mode, block, readbytes);
687 if (rv != APR_SUCCESS) {
688 /* What about APR_EAGAIN errors? */
689 inflateEnd(&ctx->stream);
693 APR_BRIGADE_FOREACH(bkt, ctx->bb) {
697 /* If we actually see the EOS, that means we screwed up! */
698 if (APR_BUCKET_IS_EOS(bkt)) {
699 inflateEnd(&ctx->stream);
703 if (APR_BUCKET_IS_FLUSH(bkt)) {
704 apr_bucket *tmp_heap;
705 zRC = inflate(&(ctx->stream), Z_SYNC_FLUSH);
707 inflateEnd(&ctx->stream);
711 ctx->stream.next_out = ctx->buffer;
712 len = c->bufferSize - ctx->stream.avail_out;
714 ctx->crc = crc32(ctx->crc, (const Bytef *)ctx->buffer, len);
715 tmp_heap = apr_bucket_heap_create((char *)ctx->buffer, len,
716 NULL, f->c->bucket_alloc);
717 APR_BRIGADE_INSERT_TAIL(ctx->proc_bb, tmp_heap);
718 ctx->stream.avail_out = c->bufferSize;
720 /* Move everything to the returning brigade. */
721 APR_BUCKET_REMOVE(bkt);
722 APR_BRIGADE_CONCAT(bb, ctx->bb);
727 apr_bucket_read(bkt, &data, &len, APR_BLOCK_READ);
729 /* pass through zlib inflate. */
730 ctx->stream.next_in = (unsigned char *)data;
731 ctx->stream.avail_in = len;
735 while (ctx->stream.avail_in != 0) {
736 if (ctx->stream.avail_out == 0) {
737 apr_bucket *tmp_heap;
738 ctx->stream.next_out = ctx->buffer;
739 len = c->bufferSize - ctx->stream.avail_out;
741 ctx->crc = crc32(ctx->crc, (const Bytef *)ctx->buffer, len);
742 tmp_heap = apr_bucket_heap_create((char *)ctx->buffer, len,
743 NULL, f->c->bucket_alloc);
744 APR_BRIGADE_INSERT_TAIL(ctx->proc_bb, tmp_heap);
745 ctx->stream.avail_out = c->bufferSize;
748 zRC = inflate(&ctx->stream, Z_NO_FLUSH);
750 if (zRC == Z_STREAM_END) {
755 inflateEnd(&ctx->stream);
759 if (zRC == Z_STREAM_END) {
760 apr_bucket *tmp_heap, *eos;
762 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
763 "Zlib: Inflated %ld to %ld : URL %s",
764 ctx->stream.total_in, ctx->stream.total_out,
767 len = c->bufferSize - ctx->stream.avail_out;
769 ctx->crc = crc32(ctx->crc, (const Bytef *)ctx->buffer, len);
770 tmp_heap = apr_bucket_heap_create((char *)ctx->buffer, len,
771 NULL, f->c->bucket_alloc);
772 APR_BRIGADE_INSERT_TAIL(ctx->proc_bb, tmp_heap);
773 ctx->stream.avail_out = c->bufferSize;
775 /* Is the remaining 8 bytes already in the avail stream? */
776 if (ctx->stream.avail_in >= 8) {
777 unsigned long compCRC, compLen;
778 compCRC = getLong(ctx->stream.next_in);
779 if (ctx->crc != compCRC) {
780 inflateEnd(&ctx->stream);
783 ctx->stream.next_in += 4;
784 compLen = getLong(ctx->stream.next_in);
785 if (ctx->stream.total_out != compLen) {
786 inflateEnd(&ctx->stream);
791 /* FIXME: We need to grab the 8 verification bytes
793 inflateEnd(&ctx->stream);
797 inflateEnd(&ctx->stream);
799 eos = apr_bucket_eos_create(f->c->bucket_alloc);
800 APR_BRIGADE_INSERT_TAIL(ctx->proc_bb, eos);
805 apr_brigade_cleanup(ctx->bb);
808 /* If we are about to return nothing for a 'blocking' read and we have
809 * some data in our zlib buffer, flush it out so we can return something.
811 if (block == APR_BLOCK_READ &&
812 APR_BRIGADE_EMPTY(ctx->proc_bb) &&
813 ctx->stream.avail_out < c->bufferSize) {
814 apr_bucket *tmp_heap;
816 ctx->stream.next_out = ctx->buffer;
817 len = c->bufferSize - ctx->stream.avail_out;
819 ctx->crc = crc32(ctx->crc, (const Bytef *)ctx->buffer, len);
820 tmp_heap = apr_bucket_heap_create((char *)ctx->buffer, len,
821 NULL, f->c->bucket_alloc);
822 APR_BRIGADE_INSERT_TAIL(ctx->proc_bb, tmp_heap);
823 ctx->stream.avail_out = c->bufferSize;
826 if (!APR_BRIGADE_EMPTY(ctx->proc_bb)) {
827 apr_bucket_brigade *newbb;
829 /* May return APR_INCOMPLETE which is fine by us. */
830 apr_brigade_partition(ctx->proc_bb, readbytes, &bkt);
832 newbb = apr_brigade_split(ctx->proc_bb, bkt);
833 APR_BRIGADE_CONCAT(bb, ctx->proc_bb);
834 APR_BRIGADE_CONCAT(ctx->proc_bb, newbb);
840 static void register_hooks(apr_pool_t *p)
842 ap_register_output_filter(deflateFilterName, deflate_out_filter, NULL,
843 AP_FTYPE_CONTENT_SET);
844 ap_register_input_filter(deflateFilterName, deflate_in_filter, NULL,
845 AP_FTYPE_CONTENT_SET);
848 static const command_rec deflate_filter_cmds[] = {
849 AP_INIT_TAKE12("DeflateFilterNote", deflate_set_note, NULL, RSRC_CONF,
850 "Set a note to report on compression ratio"),
851 AP_INIT_TAKE1("DeflateWindowSize", deflate_set_window_size, NULL,
852 RSRC_CONF, "Set the Deflate window size (1-15)"),
853 AP_INIT_TAKE1("DeflateBufferSize", deflate_set_buffer_size, NULL, RSRC_CONF,
854 "Set the Deflate Buffer Size"),
855 AP_INIT_TAKE1("DeflateMemLevel", deflate_set_memlevel, NULL, RSRC_CONF,
856 "Set the Deflate Memory Level (1-9)"),
857 AP_INIT_TAKE1("CompressionLevel", deflate_set_compressionlevel, NULL, RSRC_CONF,
858 "Set the Deflate Compression Level (1-9)"),
862 module AP_MODULE_DECLARE_DATA deflate_module = {
863 STANDARD20_MODULE_STUFF,
864 NULL, /* dir config creater */
865 NULL, /* dir merger --- default is to override */
866 create_deflate_server_config, /* server config */
867 NULL, /* merge server config */
868 deflate_filter_cmds, /* command table */
869 register_hooks /* register hooks */