/[Apache-SVN]/httpd/httpd/trunk/modules/filters/mod_deflate.c
ViewVC logotype

Contents of /httpd/httpd/trunk/modules/filters/mod_deflate.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 580598 - (show annotations)
Sat Sep 29 15:43:08 2007 UTC (2 years, 1 month ago) by niq
File MIME type: text/plain
File size: 48219 byte(s)
mod_deflate: initialise inflate-out filter correctly when the
first brigade contains no data buckets.
PR 43512
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 /*
18 * mod_deflate.c: Perform deflate content-encoding on the fly
19 *
20 * Written by Ian Holsman, Justin Erenkrantz, and Nick Kew
21 */
22
23 /*
24 * Portions of this software are based upon zlib code by Jean-loup Gailly
25 * (zlib functions gz_open and gzwrite, check_header)
26 */
27
28 /* zlib flags */
29 #define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */
30 #define HEAD_CRC 0x02 /* bit 1 set: header CRC present */
31 #define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
32 #define ORIG_NAME 0x08 /* bit 3 set: original file name present */
33 #define COMMENT 0x10 /* bit 4 set: file comment present */
34 #define RESERVED 0xE0 /* bits 5..7: reserved */
35
36
37 #include "httpd.h"
38 #include "http_config.h"
39 #include "http_log.h"
40 #include "apr_lib.h"
41 #include "apr_strings.h"
42 #include "apr_general.h"
43 #include "util_filter.h"
44 #include "apr_buckets.h"
45 #include "http_request.h"
46 #define APR_WANT_STRFUNC
47 #include "apr_want.h"
48
49 #include "zlib.h"
50
51 static const char deflateFilterName[] = "DEFLATE";
52 module AP_MODULE_DECLARE_DATA deflate_module;
53
54 typedef struct deflate_filter_config_t
55 {
56 int windowSize;
57 int memlevel;
58 int compressionlevel;
59 apr_size_t bufferSize;
60 char *note_ratio_name;
61 char *note_input_name;
62 char *note_output_name;
63 } deflate_filter_config;
64
65 /* RFC 1952 Section 2.3 defines the gzip header:
66 *
67 * +---+---+---+---+---+---+---+---+---+---+
68 * |ID1|ID2|CM |FLG| MTIME |XFL|OS |
69 * +---+---+---+---+---+---+---+---+---+---+
70 */
71 static const char gzip_header[10] =
72 { '\037', '\213', Z_DEFLATED, 0,
73 0, 0, 0, 0, /* mtime */
74 0, 0x03 /* Unix OS_CODE */
75 };
76
77 /* magic header */
78 static const char deflate_magic[2] = { '\037', '\213' };
79
80 /* windowsize is negative to suppress Zlib header */
81 #define DEFAULT_COMPRESSION Z_DEFAULT_COMPRESSION
82 #define DEFAULT_WINDOWSIZE -15
83 #define DEFAULT_MEMLEVEL 9
84 #define DEFAULT_BUFFERSIZE 8096
85
86
87 /* Check whether a request is gzipped, so we can un-gzip it.
88 * If a request has multiple encodings, we need the gzip
89 * to be the outermost non-identity encoding.
90 */
91 static int check_gzip(request_rec *r, apr_table_t *hdrs1, apr_table_t *hdrs2)
92 {
93 int found = 0;
94 apr_table_t *hdrs = hdrs1;
95 const char *encoding = apr_table_get(hdrs, "Content-Encoding");
96
97 if (!encoding && (hdrs2 != NULL)) {
98 /* the output filter has two tables and a content_encoding to check */
99 encoding = apr_table_get(hdrs2, "Content-Encoding");
100 hdrs = hdrs2;
101 if (!encoding) {
102 encoding = r->content_encoding;
103 hdrs = NULL;
104 }
105 }
106 if (encoding && *encoding) {
107
108 /* check the usual/simple case first */
109 if (!strcasecmp(encoding, "gzip")
110 || !strcasecmp(encoding, "x-gzip")) {
111 found = 1;
112 if (hdrs) {
113 apr_table_unset(hdrs, "Content-Encoding");
114 }
115 else {
116 r->content_encoding = NULL;
117 }
118 }
119 else if (ap_strchr_c(encoding, ',') != NULL) {
120 /* If the outermost encoding isn't gzip, there's nowt
121 * we can do. So only check the last non-identity token
122 */
123 char *new_encoding = apr_pstrdup(r->pool, encoding);
124 char *ptr;
125 for(;;) {
126 char *token = ap_strrchr(new_encoding, ',');
127 if (!token) { /* gzip:identity or other:identity */
128 if (!strcasecmp(new_encoding, "gzip")
129 || !strcasecmp(new_encoding, "x-gzip")) {
130 found = 1;
131 if (hdrs) {
132 apr_table_unset(hdrs, "Content-Encoding");
133 }
134 else {
135 r->content_encoding = NULL;
136 }
137 }
138 break; /* seen all tokens */
139 }
140 for (ptr=token+1; apr_isspace(*ptr); ++ptr);
141 if (!strcasecmp(ptr, "gzip")
142 || !strcasecmp(ptr, "x-gzip")) {
143 *token = '\0';
144 if (hdrs) {
145 apr_table_setn(hdrs, "Content-Encoding", new_encoding);
146 }
147 else {
148 r->content_encoding = new_encoding;
149 }
150 found = 1;
151 }
152 else if (!ptr[0] || !strcasecmp(ptr, "identity")) {
153 *token = '\0';
154 continue; /* strip the token and find the next one */
155 }
156 break; /* found a non-identity token */
157 }
158 }
159 }
160 return found;
161 }
162
163 /* Outputs a long in LSB order to the given file
164 * only the bottom 4 bits are required for the deflate file format.
165 */
166 static void putLong(unsigned char *string, unsigned long x)
167 {
168 string[0] = (unsigned char)(x & 0xff);
169 string[1] = (unsigned char)((x & 0xff00) >> 8);
170 string[2] = (unsigned char)((x & 0xff0000) >> 16);
171 string[3] = (unsigned char)((x & 0xff000000) >> 24);
172 }
173
174 /* Inputs a string and returns a long.
175 */
176 static unsigned long getLong(unsigned char *string)
177 {
178 return ((unsigned long)string[0])
179 | (((unsigned long)string[1]) << 8)
180 | (((unsigned long)string[2]) << 16)
181 | (((unsigned long)string[3]) << 24);
182 }
183
184 static void *create_deflate_server_config(apr_pool_t *p, server_rec *s)
185 {
186 deflate_filter_config *c = apr_pcalloc(p, sizeof *c);
187
188 c->memlevel = DEFAULT_MEMLEVEL;
189 c->windowSize = DEFAULT_WINDOWSIZE;
190 c->bufferSize = DEFAULT_BUFFERSIZE;
191 c->compressionlevel = DEFAULT_COMPRESSION;
192
193 return c;
194 }
195
196 static const char *deflate_set_window_size(cmd_parms *cmd, void *dummy,
197 const char *arg)
198 {
199 deflate_filter_config *c = ap_get_module_config(cmd->server->module_config,
200 &deflate_module);
201 int i;
202
203 i = atoi(arg);
204
205 if (i < 1 || i > 15)
206 return "DeflateWindowSize must be between 1 and 15";
207
208 c->windowSize = i * -1;
209
210 return NULL;
211 }
212
213 static const char *deflate_set_buffer_size(cmd_parms *cmd, void *dummy,
214 const char *arg)
215 {
216 deflate_filter_config *c = ap_get_module_config(cmd->server->module_config,
217 &deflate_module);
218 int n = atoi(arg);
219
220 if (n <= 0) {
221 return "DeflateBufferSize should be positive";
222 }
223
224 c->bufferSize = (apr_size_t)n;
225
226 return NULL;
227 }
228 static const char *deflate_set_note(cmd_parms *cmd, void *dummy,
229 const char *arg1, const char *arg2)
230 {
231 deflate_filter_config *c = ap_get_module_config(cmd->server->module_config,
232 &deflate_module);
233
234 if (arg2 == NULL) {
235 c->note_ratio_name = apr_pstrdup(cmd->pool, arg1);
236 }
237 else if (!strcasecmp(arg1, "ratio")) {
238 c->note_ratio_name = apr_pstrdup(cmd->pool, arg2);
239 }
240 else if (!strcasecmp(arg1, "input")) {
241 c->note_input_name = apr_pstrdup(cmd->pool, arg2);
242 }
243 else if (!strcasecmp(arg1, "output")) {
244 c->note_output_name = apr_pstrdup(cmd->pool, arg2);
245 }
246 else {
247 return apr_psprintf(cmd->pool, "Unknown note type %s", arg1);
248 }
249
250 return NULL;
251 }
252
253 static const char *deflate_set_memlevel(cmd_parms *cmd, void *dummy,
254 const char *arg)
255 {
256 deflate_filter_config *c = ap_get_module_config(cmd->server->module_config,
257 &deflate_module);
258 int i;
259
260 i = atoi(arg);
261
262 if (i < 1 || i > 9)
263 return "DeflateMemLevel must be between 1 and 9";
264
265 c->memlevel = i;
266
267 return NULL;
268 }
269
270 static const char *deflate_set_compressionlevel(cmd_parms *cmd, void *dummy,
271 const char *arg)
272 {
273 deflate_filter_config *c = ap_get_module_config(cmd->server->module_config,
274 &deflate_module);
275 int i;
276
277 i = atoi(arg);
278
279 if (i < 1 || i > 9)
280 return "Compression Level must be between 1 and 9";
281
282 c->compressionlevel = i;
283
284 return NULL;
285 }
286
287 typedef struct deflate_ctx_t
288 {
289 z_stream stream;
290 unsigned char *buffer;
291 unsigned long crc;
292 apr_bucket_brigade *bb, *proc_bb;
293 int (*libz_end_func)(z_streamp);
294 unsigned char *validation_buffer;
295 apr_size_t validation_buffer_length;
296 int inflate_init;
297 } deflate_ctx;
298
299 /* Number of validation bytes (CRC and length) after the compressed data */
300 #define VALIDATION_SIZE 8
301 /* Do not update ctx->crc, see comment in flush_libz_buffer */
302 #define NO_UPDATE_CRC 0
303 /* Do update ctx->crc, see comment in flush_libz_buffer */
304 #define UPDATE_CRC 1
305
306 static int flush_libz_buffer(deflate_ctx *ctx, deflate_filter_config *c,
307 struct apr_bucket_alloc_t *bucket_alloc,
308 int (*libz_func)(z_streamp, int), int flush,
309 int crc)
310 {
311 int zRC = Z_OK;
312 int done = 0;
313 unsigned int deflate_len;
314 apr_bucket *b;
315
316 for (;;) {
317 deflate_len = c->bufferSize - ctx->stream.avail_out;
318
319 if (deflate_len != 0) {
320 /*
321 * Do we need to update ctx->crc? Usually this is the case for
322 * inflate action where we need to do a crc on the output, whereas
323 * in the deflate case we need to do a crc on the input
324 */
325 if (crc) {
326 ctx->crc = crc32(ctx->crc, (const Bytef *)ctx->buffer,
327 deflate_len);
328 }
329 b = apr_bucket_heap_create((char *)ctx->buffer,
330 deflate_len, NULL,
331 bucket_alloc);
332 APR_BRIGADE_INSERT_TAIL(ctx->bb, b);
333 ctx->stream.next_out = ctx->buffer;
334 ctx->stream.avail_out = c->bufferSize;
335 }
336
337 if (done)
338 break;
339
340 zRC = libz_func(&ctx->stream, flush);
341
342 /*
343 * We can ignore Z_BUF_ERROR because:
344 * When we call libz_func we can assume that
345 *
346 * - avail_in is zero (due to the surrounding code that calls
347 * flush_libz_buffer)
348 * - avail_out is non zero due to our actions some lines above
349 *
350 * So the only reason for Z_BUF_ERROR is that the internal libz
351 * buffers are now empty and thus we called libz_func one time
352 * too often. This does not hurt. It simply says that we are done.
353 */
354 if (zRC == Z_BUF_ERROR) {
355 zRC = Z_OK;
356 break;
357 }
358
359 done = (ctx->stream.avail_out != 0 || zRC == Z_STREAM_END);
360
361 if (zRC != Z_OK && zRC != Z_STREAM_END)
362 break;
363 }
364 return zRC;
365 }
366
367 static apr_status_t deflate_ctx_cleanup(void *data)
368 {
369 deflate_ctx *ctx = (deflate_ctx *)data;
370
371 if (ctx)
372 ctx->libz_end_func(&ctx->stream);
373 return APR_SUCCESS;
374 }
375
376 static apr_status_t deflate_out_filter(ap_filter_t *f,
377 apr_bucket_brigade *bb)
378 {
379 apr_bucket *e;
380 request_rec *r = f->r;
381 deflate_ctx *ctx = f->ctx;
382 int zRC;
383 deflate_filter_config *c;
384
385 /* Do nothing if asked to filter nothing. */
386 if (APR_BRIGADE_EMPTY(bb)) {
387 return ap_pass_brigade(f->next, bb);
388 }
389
390 c = ap_get_module_config(r->server->module_config,
391 &deflate_module);
392
393 /* If we don't have a context, we need to ensure that it is okay to send
394 * the deflated content. If we have a context, that means we've done
395 * this before and we liked it.
396 * This could be not so nice if we always fail. But, if we succeed,
397 * we're in better shape.
398 */
399 if (!ctx) {
400 char *token;
401 const char *encoding;
402
403 /* only work on main request/no subrequests */
404 if (r->main != NULL) {
405 ap_remove_output_filter(f);
406 return ap_pass_brigade(f->next, bb);
407 }
408
409 /* some browsers might have problems, so set no-gzip
410 * (with browsermatch) for them
411 */
412 if (apr_table_get(r->subprocess_env, "no-gzip")) {
413 ap_remove_output_filter(f);
414 return ap_pass_brigade(f->next, bb);
415 }
416
417 /* We can't operate on Content-Ranges */
418 if (apr_table_get(r->headers_out, "Content-Range") != NULL) {
419 ap_remove_output_filter(f);
420 return ap_pass_brigade(f->next, bb);
421 }
422
423 /* Some browsers might have problems with content types
424 * other than text/html, so set gzip-only-text/html
425 * (with browsermatch) for them
426 */
427 if (r->content_type == NULL
428 || strncmp(r->content_type, "text/html", 9)) {
429 const char *env_value = apr_table_get(r->subprocess_env,
430 "gzip-only-text/html");
431 if ( env_value && (strcmp(env_value,"1") == 0) ) {
432 ap_remove_output_filter(f);
433 return ap_pass_brigade(f->next, bb);
434 }
435 }
436
437 /* Let's see what our current Content-Encoding is.
438 * If it's already encoded, don't compress again.
439 * (We could, but let's not.)
440 */
441 encoding = apr_table_get(r->headers_out, "Content-Encoding");
442 if (encoding) {
443 const char *err_enc;
444
445 err_enc = apr_table_get(r->err_headers_out, "Content-Encoding");
446 if (err_enc) {
447 encoding = apr_pstrcat(r->pool, encoding, ",", err_enc, NULL);
448 }
449 }
450 else {
451 encoding = apr_table_get(r->err_headers_out, "Content-Encoding");
452 }
453
454 if (r->content_encoding) {
455 encoding = encoding ? apr_pstrcat(r->pool, encoding, ",",
456 r->content_encoding, NULL)
457 : r->content_encoding;
458 }
459
460 if (encoding) {
461 const char *tmp = encoding;
462
463 token = ap_get_token(r->pool, &tmp, 0);
464 while (token && *token) {
465 /* stolen from mod_negotiation: */
466 if (strcmp(token, "identity") && strcmp(token, "7bit") &&
467 strcmp(token, "8bit") && strcmp(token, "binary")) {
468
469 ap_remove_output_filter(f);
470 return ap_pass_brigade(f->next, bb);
471 }
472
473 /* Otherwise, skip token */
474 if (*tmp) {
475 ++tmp;
476 }
477 token = (*tmp) ? ap_get_token(r->pool, &tmp, 0) : NULL;
478 }
479 }
480
481 /* Even if we don't accept this request based on it not having
482 * the Accept-Encoding, we need to note that we were looking
483 * for this header and downstream proxies should be aware of that.
484 */
485 apr_table_mergen(r->headers_out, "Vary", "Accept-Encoding");
486
487 /* force-gzip will just force it out regardless if the browser
488 * can actually do anything with it.
489 */
490 if (!apr_table_get(r->subprocess_env, "force-gzip")) {
491 const char *accepts;
492 /* if they don't have the line, then they can't play */
493 accepts = apr_table_get(r->headers_in, "Accept-Encoding");
494 if (accepts == NULL) {
495 ap_remove_output_filter(f);
496 return ap_pass_brigade(f->next, bb);
497 }
498
499 token = ap_get_token(r->pool, &accepts, 0);
500 while (token && token[0] && strcasecmp(token, "gzip")) {
501 /* skip parameters, XXX: ;q=foo evaluation? */
502 while (*accepts == ';') {
503 ++accepts;
504 token = ap_get_token(r->pool, &accepts, 1);
505 }
506
507 /* retrieve next token */
508 if (*accepts == ',') {
509 ++accepts;
510 }
511 token = (*accepts) ? ap_get_token(r->pool, &accepts, 0) : NULL;
512 }
513
514 /* No acceptable token found. */
515 if (token == NULL || token[0] == '\0') {
516 ap_remove_output_filter(f);
517 return ap_pass_brigade(f->next, bb);
518 }
519 }
520
521 /* For a 304 or 204 response there is no entity included in
522 * the response and hence nothing to deflate. */
523 if (r->status == HTTP_NOT_MODIFIED || r->status == HTTP_NO_CONTENT) {
524 ap_remove_output_filter(f);
525 return ap_pass_brigade(f->next, bb);
526 }
527
528 /* We're cool with filtering this. */
529 ctx = f->ctx = apr_pcalloc(r->pool, sizeof(*ctx));
530 ctx->bb = apr_brigade_create(r->pool, f->c->bucket_alloc);
531 ctx->buffer = apr_palloc(r->pool, c->bufferSize);
532 ctx->libz_end_func = deflateEnd;
533
534 zRC = deflateInit2(&ctx->stream, c->compressionlevel, Z_DEFLATED,
535 c->windowSize, c->memlevel,
536 Z_DEFAULT_STRATEGY);
537
538 if (zRC != Z_OK) {
539 deflateEnd(&ctx->stream);
540 ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
541 "unable to init Zlib: "
542 "deflateInit2 returned %d: URL %s",
543 zRC, r->uri);
544 /*
545 * Remove ourselves as it does not make sense to return:
546 * We are not able to init libz and pass data down the chain
547 * uncompressed.
548 */
549 ap_remove_output_filter(f);
550 return ap_pass_brigade(f->next, bb);
551 }
552 /*
553 * Register a cleanup function to ensure that we cleanup the internal
554 * libz resources.
555 */
556 apr_pool_cleanup_register(r->pool, ctx, deflate_ctx_cleanup,
557 apr_pool_cleanup_null);
558
559 /* add immortal gzip header */
560 e = apr_bucket_immortal_create(gzip_header, sizeof gzip_header,
561 f->c->bucket_alloc);
562 APR_BRIGADE_INSERT_TAIL(ctx->bb, e);
563
564 /* If the entire Content-Encoding is "identity", we can replace it. */
565 if (!encoding || !strcasecmp(encoding, "identity")) {
566 apr_table_setn(r->headers_out, "Content-Encoding", "gzip");
567 }
568 else {
569 apr_table_mergen(r->headers_out, "Content-Encoding", "gzip");
570 }
571 apr_table_unset(r->headers_out, "Content-Length");
572 apr_table_unset(r->headers_out, "Content-MD5");
573
574 /* initialize deflate output buffer */
575 ctx->stream.next_out = ctx->buffer;
576 ctx->stream.avail_out = c->bufferSize;
577 }
578
579 while (!APR_BRIGADE_EMPTY(bb))
580 {
581 const char *data;
582 apr_bucket *b;
583 apr_size_t len;
584
585 e = APR_BRIGADE_FIRST(bb);
586
587 if (APR_BUCKET_IS_EOS(e)) {
588 char *buf;
589
590 ctx->stream.avail_in = 0; /* should be zero already anyway */
591 /* flush the remaining data from the zlib buffers */
592 flush_libz_buffer(ctx, c, f->c->bucket_alloc, deflate, Z_FINISH,
593 NO_UPDATE_CRC);
594
595 buf = apr_palloc(r->pool, VALIDATION_SIZE);
596 putLong((unsigned char *)&buf[0], ctx->crc);
597 putLong((unsigned char *)&buf[4], ctx->stream.total_in);
598
599 b = apr_bucket_pool_create(buf, VALIDATION_SIZE, r->pool,
600 f->c->bucket_alloc);
601 APR_BRIGADE_INSERT_TAIL(ctx->bb, b);
602 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
603 "Zlib: Compressed %ld to %ld : URL %s",
604 ctx->stream.total_in, ctx->stream.total_out, r->uri);
605
606 /* leave notes for logging */
607 if (c->note_input_name) {
608 apr_table_setn(r->notes, c->note_input_name,
609 (ctx->stream.total_in > 0)
610 ? apr_off_t_toa(r->pool,
611 ctx->stream.total_in)
612 : "-");
613 }
614
615 if (c->note_output_name) {
616 apr_table_setn(r->notes, c->note_output_name,
617 (ctx->stream.total_in > 0)
618 ? apr_off_t_toa(r->pool,
619 ctx->stream.total_out)
620 : "-");
621 }
622
623 if (c->note_ratio_name) {
624 apr_table_setn(r->notes, c->note_ratio_name,
625 (ctx->stream.total_in > 0)
626 ? apr_itoa(r->pool,
627 (int)(ctx->stream.total_out
628 * 100
629 / ctx->stream.total_in))
630 : "-");
631 }
632
633 deflateEnd(&ctx->stream);
634 /* No need for cleanup any longer */
635 apr_pool_cleanup_kill(r->pool, ctx, deflate_ctx_cleanup);
636
637 /* Remove EOS from the old list, and insert into the new. */
638 APR_BUCKET_REMOVE(e);
639 APR_BRIGADE_INSERT_TAIL(ctx->bb, e);
640
641 /* Okay, we've seen the EOS.
642 * Time to pass it along down the chain.
643 */
644 return ap_pass_brigade(f->next, ctx->bb);
645 }
646
647 if (APR_BUCKET_IS_FLUSH(e)) {
648 apr_status_t rv;
649
650 /* flush the remaining data from the zlib buffers */
651 zRC = flush_libz_buffer(ctx, c, f->c->bucket_alloc, deflate,
652 Z_SYNC_FLUSH, NO_UPDATE_CRC);
653 if (zRC != Z_OK) {
654 return APR_EGENERAL;
655 }
656
657 /* Remove flush bucket from old brigade anf insert into the new. */
658 APR_BUCKET_REMOVE(e);
659 APR_BRIGADE_INSERT_TAIL(ctx->bb, e);
660 rv = ap_pass_brigade(f->next, ctx->bb);
661 if (rv != APR_SUCCESS) {
662 return rv;
663 }
664 continue;
665 }
666
667 if (APR_BUCKET_IS_METADATA(e)) {
668 /*
669 * Remove meta data bucket from old brigade and insert into the
670 * new.
671 */
672 APR_BUCKET_REMOVE(e);
673 APR_BRIGADE_INSERT_TAIL(ctx->bb, e);
674 continue;
675 }
676
677 /* read */
678 apr_bucket_read(e, &data, &len, APR_BLOCK_READ);
679
680 /* This crc32 function is from zlib. */
681 ctx->crc = crc32(ctx->crc, (const Bytef *)data, len);
682
683 /* write */
684 ctx->stream.next_in = (unsigned char *)data; /* We just lost const-ness,
685 * but we'll just have to
686 * trust zlib */
687 ctx->stream.avail_in = len;
688
689 while (ctx->stream.avail_in != 0) {
690 if (ctx->stream.avail_out == 0) {
691 apr_status_t rv;
692
693 ctx->stream.next_out = ctx->buffer;
694 len = c->bufferSize - ctx->stream.avail_out;
695
696 b = apr_bucket_heap_create((char *)ctx->buffer, len,
697 NULL, f->c->bucket_alloc);
698 APR_BRIGADE_INSERT_TAIL(ctx->bb, b);
699 ctx->stream.avail_out = c->bufferSize;
700 /* Send what we have right now to the next filter. */
701 rv = ap_pass_brigade(f->next, ctx->bb);
702 if (rv != APR_SUCCESS) {
703 return rv;
704 }
705 }
706
707 zRC = deflate(&(ctx->stream), Z_NO_FLUSH);
708
709 if (zRC != Z_OK) {
710 return APR_EGENERAL;
711 }
712 }
713
714 apr_bucket_delete(e);
715 }
716
717 apr_brigade_cleanup(bb);
718 return APR_SUCCESS;
719 }
720
721 /* This is the deflate input filter (inflates). */
722 static apr_status_t deflate_in_filter(ap_filter_t *f,
723 apr_bucket_brigade *bb,
724 ap_input_mode_t mode,
725 apr_read_type_e block,
726 apr_off_t readbytes)
727 {
728 apr_bucket *bkt;
729 request_rec *r = f->r;
730 deflate_ctx *ctx = f->ctx;
731 int zRC;
732 apr_status_t rv;
733 deflate_filter_config *c;
734
735 /* just get out of the way of things we don't want. */
736 if (mode != AP_MODE_READBYTES) {
737 return ap_get_brigade(f->next, bb, mode, block, readbytes);
738 }
739
740 c = ap_get_module_config(r->server->module_config, &deflate_module);
741
742 if (!ctx) {
743 char deflate_hdr[10];
744 apr_size_t len;
745
746 /* only work on main request/no subrequests */
747 if (!ap_is_initial_req(r)) {
748 ap_remove_input_filter(f);
749 return ap_get_brigade(f->next, bb, mode, block, readbytes);
750 }
751
752 /* We can't operate on Content-Ranges */
753 if (apr_table_get(r->headers_in, "Content-Range") != NULL) {
754 ap_remove_input_filter(f);
755 return ap_get_brigade(f->next, bb, mode, block, readbytes);
756 }
757
758 /* Check whether request body is gzipped.
759 *
760 * If it is, we're transforming the contents, invalidating
761 * some request headers including Content-Encoding.
762 *
763 * If not, we just remove ourself.
764 */
765 if (check_gzip(r, r->headers_in, NULL) == 0) {
766 ap_remove_input_filter(f);
767 return ap_get_brigade(f->next, bb, mode, block, readbytes);
768 }
769
770 f->ctx = ctx = apr_pcalloc(f->r->pool, sizeof(*ctx));
771 ctx->bb = apr_brigade_create(r->pool, f->c->bucket_alloc);
772 ctx->proc_bb = apr_brigade_create(r->pool, f->c->bucket_alloc);
773 ctx->buffer = apr_palloc(r->pool, c->bufferSize);
774
775 rv = ap_get_brigade(f->next, ctx->bb, AP_MODE_READBYTES, block, 10);
776 if (rv != APR_SUCCESS) {
777 return rv;
778 }
779
780 apr_table_unset(r->headers_in, "Content-Length");
781 apr_table_unset(r->headers_in, "Content-MD5");
782
783 len = 10;
784 rv = apr_brigade_flatten(ctx->bb, deflate_hdr, &len);
785 if (rv != APR_SUCCESS) {
786 return rv;
787 }
788
789 /* We didn't get the magic bytes. */
790 if (len != 10 ||
791 deflate_hdr[0] != deflate_magic[0] ||
792 deflate_hdr[1] != deflate_magic[1]) {
793 return APR_EGENERAL;
794 }
795
796 /* We can't handle flags for now. */
797 if (deflate_hdr[3] != 0) {
798 return APR_EGENERAL;
799 }
800
801 zRC = inflateInit2(&ctx->stream, c->windowSize);
802
803 if (zRC != Z_OK) {
804 f->ctx = NULL;
805 inflateEnd(&ctx->stream);
806 ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
807 "unable to init Zlib: "
808 "inflateInit2 returned %d: URL %s",
809 zRC, r->uri);
810 ap_remove_input_filter(f);
811 return ap_get_brigade(f->next, bb, mode, block, readbytes);
812 }
813
814 /* initialize deflate output buffer */
815 ctx->stream.next_out = ctx->buffer;
816 ctx->stream.avail_out = c->bufferSize;
817
818 apr_brigade_cleanup(ctx->bb);
819 }
820
821 if (APR_BRIGADE_EMPTY(ctx->proc_bb)) {
822 rv = ap_get_brigade(f->next, ctx->bb, mode, block, readbytes);
823
824 if (rv != APR_SUCCESS) {
825 /* What about APR_EAGAIN errors? */
826 inflateEnd(&ctx->stream);
827 return rv;
828 }
829
830 for (bkt = APR_BRIGADE_FIRST(ctx->bb);
831 bkt != APR_BRIGADE_SENTINEL(ctx->bb);
832 bkt = APR_BUCKET_NEXT(bkt))
833 {
834 const char *data;
835 apr_size_t len;
836
837 /* If we actually see the EOS, that means we screwed up! */
838 if (APR_BUCKET_IS_EOS(bkt)) {
839 inflateEnd(&ctx->stream);
840 return APR_EGENERAL;
841 }
842
843 if (APR_BUCKET_IS_FLUSH(bkt)) {
844 apr_bucket *tmp_heap;
845 zRC = inflate(&(ctx->stream), Z_SYNC_FLUSH);
846 if (zRC != Z_OK) {
847 inflateEnd(&ctx->stream);
848 return APR_EGENERAL;
849 }
850
851 ctx->stream.next_out = ctx->buffer;
852 len = c->bufferSize - ctx->stream.avail_out;
853
854 ctx->crc = crc32(ctx->crc, (const Bytef *)ctx->buffer, len);
855 tmp_heap = apr_bucket_heap_create((char *)ctx->buffer, len,
856 NULL, f->c->bucket_alloc);
857 APR_BRIGADE_INSERT_TAIL(ctx->proc_bb, tmp_heap);
858 ctx->stream.avail_out = c->bufferSize;
859
860 /* Move everything to the returning brigade. */
861 APR_BUCKET_REMOVE(bkt);
862 APR_BRIGADE_CONCAT(bb, ctx->bb);
863 break;
864 }
865
866 /* read */
867 apr_bucket_read(bkt, &data, &len, APR_BLOCK_READ);
868
869 /* pass through zlib inflate. */
870 ctx->stream.next_in = (unsigned char *)data;
871 ctx->stream.avail_in = len;
872
873 zRC = Z_OK;
874
875 while (ctx->stream.avail_in != 0) {
876 if (ctx->stream.avail_out == 0) {
877 apr_bucket *tmp_heap;
878 ctx->stream.next_out = ctx->buffer;
879 len = c->bufferSize - ctx->stream.avail_out;
880
881 ctx->crc = crc32(ctx->crc, (const Bytef *)ctx->buffer, len);
882 tmp_heap = apr_bucket_heap_create((char *)ctx->buffer, len,
883 NULL, f->c->bucket_alloc);
884 APR_BRIGADE_INSERT_TAIL(ctx->proc_bb, tmp_heap);
885 ctx->stream.avail_out = c->bufferSize;
886 }
887
888 zRC = inflate(&ctx->stream, Z_NO_FLUSH);
889
890 if (zRC == Z_STREAM_END) {
891 break;
892 }
893
894 if (zRC != Z_OK) {
895 inflateEnd(&ctx->stream);
896 return APR_EGENERAL;
897 }
898 }
899 if (zRC == Z_STREAM_END) {
900 apr_bucket *tmp_heap, *eos;
901
902 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
903 "Zlib: Inflated %ld to %ld : URL %s",
904 ctx->stream.total_in, ctx->stream.total_out,
905 r->uri);
906
907 len = c->bufferSize - ctx->stream.avail_out;
908
909 ctx->crc = crc32(ctx->crc, (const Bytef *)ctx->buffer, len);
910 tmp_heap = apr_bucket_heap_create((char *)ctx->buffer, len,
911 NULL, f->c->bucket_alloc);
912 APR_BRIGADE_INSERT_TAIL(ctx->proc_bb, tmp_heap);
913 ctx->stream.avail_out = c->bufferSize;
914
915 /* Is the remaining 8 bytes already in the avail stream? */
916 if (ctx->stream.avail_in >= 8) {
917 unsigned long compCRC, compLen;
918 compCRC = getLong(ctx->stream.next_in);
919 if (ctx->crc != compCRC) {
920 inflateEnd(&ctx->stream);
921 return APR_EGENERAL;
922 }
923 ctx->stream.next_in += 4;
924 compLen = getLong(ctx->stream.next_in);
925 if (ctx->stream.total_out != compLen) {
926 inflateEnd(&ctx->stream);
927 return APR_EGENERAL;
928 }
929 }
930 else {
931 /* FIXME: We need to grab the 8 verification bytes
932 * from the wire! */
933 inflateEnd(&ctx->stream);
934 return APR_EGENERAL;
935 }
936
937 inflateEnd(&ctx->stream);
938
939 eos = apr_bucket_eos_create(f->c->bucket_alloc);
940 APR_BRIGADE_INSERT_TAIL(ctx->proc_bb, eos);
941 break;
942 }
943
944 }
945 apr_brigade_cleanup(ctx->bb);
946 }
947
948 /* If we are about to return nothing for a 'blocking' read and we have
949 * some data in our zlib buffer, flush it out so we can return something.
950 */
951 if (block == APR_BLOCK_READ &&
952 APR_BRIGADE_EMPTY(ctx->proc_bb) &&
953 ctx->stream.avail_out < c->bufferSize) {
954 apr_bucket *tmp_heap;
955 apr_size_t len;
956 ctx->stream.next_out = ctx->buffer;
957 len = c->bufferSize - ctx->stream.avail_out;
958
959 ctx->crc = crc32(ctx->crc, (const Bytef *)ctx->buffer, len);
960 tmp_heap = apr_bucket_heap_create((char *)ctx->buffer, len,
961 NULL, f->c->bucket_alloc);
962 APR_BRIGADE_INSERT_TAIL(ctx->proc_bb, tmp_heap);
963 ctx->stream.avail_out = c->bufferSize;
964 }
965
966 if (!APR_BRIGADE_EMPTY(ctx->proc_bb)) {
967 apr_bucket_brigade *newbb;
968
969 /* May return APR_INCOMPLETE which is fine by us. */
970 apr_brigade_partition(ctx->proc_bb, readbytes, &bkt);
971
972 newbb = apr_brigade_split(ctx->proc_bb, bkt);
973 APR_BRIGADE_CONCAT(bb, ctx->proc_bb);
974 APR_BRIGADE_CONCAT(ctx->proc_bb, newbb);
975 }
976
977 return APR_SUCCESS;
978 }
979
980
981 /* Filter to inflate for a content-transforming proxy. */
982 static apr_status_t inflate_out_filter(ap_filter_t *f,
983 apr_bucket_brigade *bb)
984 {
985 int zlib_method;
986 int zlib_flags;
987 apr_bucket *e;
988 request_rec *r = f->r;
989 deflate_ctx *ctx = f->ctx;
990 int zRC;
991 apr_status_t rv;
992 deflate_filter_config *c;
993
994 /* Do nothing if asked to filter nothing. */
995 if (APR_BRIGADE_EMPTY(bb)) {
996 return ap_pass_brigade(f->next, bb);
997 }
998
999 c = ap_get_module_config(r->server->module_config, &deflate_module);
1000
1001 if (!ctx) {
1002
1003 /* only work on main request/no subrequests */
1004 if (!ap_is_initial_req(r)) {
1005 ap_remove_output_filter(f);
1006 return ap_pass_brigade(f->next, bb);
1007 }
1008
1009 /* We can't operate on Content-Ranges */
1010 if (apr_table_get(r->headers_out, "Content-Range") != NULL) {
1011 ap_remove_output_filter(f);
1012 return ap_pass_brigade(f->next, bb);
1013 }
1014
1015 /*
1016 * Let's see what our current Content-Encoding is.
1017 * Only inflate if gzipped.
1018 */
1019 if (check_gzip(r, r->headers_out, r->err_headers_out) == 0) {
1020 ap_remove_output_filter(f);
1021 return ap_pass_brigade(f->next, bb);
1022 }
1023
1024 /* No need to inflate HEAD or 204/304 */
1025 if (APR_BUCKET_IS_EOS(APR_BRIGADE_FIRST(bb))) {
1026 ap_remove_output_filter(f);
1027 return ap_pass_brigade(f->next, bb);
1028 }
1029
1030 f->ctx = ctx = apr_pcalloc(f->r->pool, sizeof(*ctx));
1031 ctx->bb = apr_brigade_create(r->pool, f->c->bucket_alloc);
1032 ctx->buffer = apr_palloc(r->pool, c->bufferSize);
1033 ctx->libz_end_func = inflateEnd;
1034 ctx->validation_buffer = NULL;
1035 ctx->validation_buffer_length = 0;
1036
1037 zRC = inflateInit2(&ctx->stream, c->windowSize);
1038
1039 if (zRC != Z_OK) {
1040 f->ctx = NULL;
1041 inflateEnd(&ctx->stream);
1042 ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
1043 "unable to init Zlib: "
1044 "inflateInit2 returned %d: URL %s",
1045 zRC, r->uri);
1046 /*
1047 * Remove ourselves as it does not make sense to return:
1048 * We are not able to init libz and pass data down the chain
1049 * compressed.
1050 */
1051 ap_remove_output_filter(f);
1052 return ap_pass_brigade(f->next, bb);
1053 }
1054
1055 /*
1056 * Register a cleanup function to ensure that we cleanup the internal
1057 * libz resources.
1058 */
1059 apr_pool_cleanup_register(r->pool, ctx, deflate_ctx_cleanup,
1060 apr_pool_cleanup_null);
1061
1062 /* these are unlikely to be set anyway, but ... */
1063 apr_table_unset(r->headers_out, "Content-Length");
1064 apr_table_unset(r->headers_out, "Content-MD5");
1065
1066 /* initialize inflate output buffer */
1067 ctx->stream.next_out = ctx->buffer;
1068 ctx->stream.avail_out = c->bufferSize;
1069
1070 ctx->inflate_init = 0;
1071 }
1072
1073 while (!APR_BRIGADE_EMPTY(bb))
1074 {
1075 const char *data;
1076 apr_bucket *b;
1077 apr_size_t len;
1078
1079 e = APR_BRIGADE_FIRST(bb);
1080
1081 if (APR_BUCKET_IS_EOS(e)) {
1082 /*
1083 * We are really done now. Ensure that we never return here, even
1084 * if a second EOS bucket falls down the chain. Thus remove
1085 * ourselves.
1086 */
1087 ap_remove_output_filter(f);
1088 /* should be zero already anyway */
1089 ctx->stream.avail_in = 0;
1090 /*
1091 * Flush the remaining data from the zlib buffers. It is correct
1092 * to use Z_SYNC_FLUSH in this case and not Z_FINISH as in the
1093 * deflate case. In the inflate case Z_FINISH requires to have a
1094 * large enough output buffer to put ALL data in otherwise it
1095 * fails, whereas in the deflate case you can empty a filled output
1096 * buffer and call it again until no more output can be created.
1097 */
1098 flush_libz_buffer(ctx, c, f->c->bucket_alloc, inflate, Z_SYNC_FLUSH,
1099 UPDATE_CRC);
1100 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
1101 "Zlib: Inflated %ld to %ld : URL %s",
1102 ctx->stream.total_in, ctx->stream.total_out, r->uri);
1103
1104 if (ctx->validation_buffer_length == VALIDATION_SIZE) {
1105 unsigned long compCRC, compLen;
1106 compCRC = getLong(ctx->validation_buffer);
1107 if (ctx->crc != compCRC) {
1108 ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
1109 "Zlib: Checksum of inflated stream invalid");
1110 return APR_EGENERAL;
1111 }
1112 ctx->validation_buffer += VALIDATION_SIZE / 2;
1113 compLen = getLong(ctx->validation_buffer);
1114 if (ctx->stream.total_out != compLen) {
1115 ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
1116 "Zlib: Length of inflated stream invalid");
1117 return APR_EGENERAL;
1118 }
1119 }
1120 else {
1121 ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
1122 "Zlib: Validation bytes not present");
1123 return APR_EGENERAL;
1124 }
1125
1126 inflateEnd(&ctx->stream);
1127 /* No need for cleanup any longer */
1128 apr_pool_cleanup_kill(r->pool, ctx, deflate_ctx_cleanup);
1129
1130 /* Remove EOS from the old list, and insert into the new. */
1131 APR_BUCKET_REMOVE(e);
1132 APR_BRIGADE_INSERT_TAIL(ctx->bb, e);
1133
1134 /*
1135 * Okay, we've seen the EOS.
1136 * Time to pass it along down the chain.
1137 */
1138 return ap_pass_brigade(f->next, ctx->bb);
1139 }
1140
1141 if (APR_BUCKET_IS_FLUSH(e)) {
1142 apr_status_t rv;
1143
1144 /* flush the remaining data from the zlib buffers */
1145 zRC = flush_libz_buffer(ctx, c, f->c->bucket_alloc, inflate,
1146 Z_SYNC_FLUSH, UPDATE_CRC);
1147 if (zRC != Z_OK) {
1148 return APR_EGENERAL;
1149 }
1150
1151 /* Remove flush bucket from old brigade anf insert into the new. */
1152 APR_BUCKET_REMOVE(e);
1153 APR_BRIGADE_INSERT_TAIL(ctx->bb, e);
1154 rv = ap_pass_brigade(f->next, ctx->bb);
1155 if (rv != APR_SUCCESS) {
1156 return rv;
1157 }
1158 continue;
1159 }
1160
1161 if (APR_BUCKET_IS_METADATA(e)) {
1162 /*
1163 * Remove meta data bucket from old brigade and insert into the
1164 * new.
1165 */
1166 APR_BUCKET_REMOVE(e);
1167 APR_BRIGADE_INSERT_TAIL(ctx->bb, e);
1168 continue;
1169 }
1170
1171 /* read */
1172 apr_bucket_read(e, &data, &len, APR_BLOCK_READ);
1173
1174 /* first bucket contains zlib header */
1175 if (!ctx->inflate_init++) {
1176 if (len < 10) {
1177 ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
1178 "Insufficient data for inflate");
1179 return APR_EGENERAL;
1180 }
1181 else {
1182 zlib_method = data[2];
1183 zlib_flags = data[3];
1184 if (zlib_method != Z_DEFLATED) {
1185 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
1186 "inflate: data not deflated!");
1187 ap_remove_output_filter(f);
1188 return ap_pass_brigade(f->next, bb);
1189 }
1190 if (data[0] != deflate_magic[0] ||
1191 data[1] != deflate_magic[1] ||
1192 (zlib_flags & RESERVED) != 0) {
1193 ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
1194 "inflate: bad header");
1195 return APR_EGENERAL ;
1196 }
1197 data += 10 ;
1198 len -= 10 ;
1199 }
1200 if (zlib_flags & EXTRA_FIELD) {
1201 unsigned int bytes = (unsigned int)(data[0]);
1202 bytes += ((unsigned int)(data[1])) << 8;
1203 bytes += 2;
1204 if (len < bytes) {
1205 ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r,
1206 "inflate: extra field too big (not "
1207 "supported)");
1208 return APR_EGENERAL;
1209 }
1210 data += bytes;
1211 len -= bytes;
1212 }
1213 if (zlib_flags & ORIG_NAME) {
1214 while (len-- && *data++);
1215 }
1216 if (zlib_flags & COMMENT) {
1217 while (len-- && *data++);
1218 }
1219 if (zlib_flags & HEAD_CRC) {
1220 len -= 2;
1221 data += 2;
1222 }
1223 }
1224
1225 /* pass through zlib inflate. */
1226 ctx->stream.next_in = (unsigned char *)data;
1227 ctx->stream.avail_in = len;
1228
1229 if (ctx->validation_buffer) {
1230 if (ctx->validation_buffer_length < VALIDATION_SIZE) {
1231 apr_size_t copy_size;
1232
1233 copy_size = VALIDATION_SIZE - ctx->validation_buffer_length;
1234 if (copy_size > ctx->stream.avail_in)
1235 copy_size = ctx->stream.avail_in;
1236 memcpy(ctx->validation_buffer + ctx->validation_buffer_length,
1237 ctx->stream.next_in, copy_size);
1238 /* Saved copy_size bytes */
1239 ctx->stream.avail_in -= copy_size;
1240 ctx->validation_buffer_length += copy_size;
1241 }
1242 if (ctx->stream.avail_in) {
1243 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
1244 "Zlib: %d bytes of garbage at the end of "
1245 "compressed stream.", ctx->stream.avail_in);
1246 /*
1247 * There is nothing worth consuming for zlib left, because it is
1248 * either garbage data or the data has been copied to the
1249 * validation buffer (processing validation data is no business
1250 * for zlib). So set ctx->stream.avail_in to zero to indicate
1251 * this to the following while loop.
1252 */
1253 ctx->stream.avail_in = 0;
1254 }
1255 }
1256
1257 zRC = Z_OK;
1258
1259 while (ctx->stream.avail_in != 0) {
1260 if (ctx->stream.avail_out == 0) {
1261
1262 ctx->stream.next_out = ctx->buffer;
1263 len = c->bufferSize - ctx->stream.avail_out;
1264
1265 ctx->crc = crc32(ctx->crc, (const Bytef *)ctx->buffer, len);
1266 b = apr_bucket_heap_create((char *)ctx->buffer, len,
1267 NULL, f->c->bucket_alloc);
1268 APR_BRIGADE_INSERT_TAIL(ctx->bb, b);
1269 ctx->stream.avail_out = c->bufferSize;
1270 /* Send what we have right now to the next filter. */
1271 rv = ap_pass_brigade(f->next, ctx->bb);
1272 if (rv != APR_SUCCESS) {
1273 return rv;
1274 }
1275 }
1276
1277 zRC = inflate(&ctx->stream, Z_NO_FLUSH);
1278
1279 if (zRC == Z_STREAM_END) {
1280 /*
1281 * We have inflated all data. Now try to capture the
1282 * validation bytes. We may not have them all available
1283 * right now, but capture what is there.
1284 */
1285 ctx->validation_buffer = apr_pcalloc(f->r->pool,
1286 VALIDATION_SIZE);
1287 if (ctx->stream.avail_in > VALIDATION_SIZE) {
1288 ctx->validation_buffer_length = VALIDATION_SIZE;
1289 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
1290 "Zlib: %d bytes of garbage at the end of "
1291 "compressed stream.",
1292 ctx->stream.avail_in - VALIDATION_SIZE);
1293 } else if (ctx->stream.avail_in > 0) {
1294 ctx->validation_buffer_length = ctx->stream.avail_in;
1295 }
1296 if (ctx->validation_buffer_length)
1297 memcpy(ctx->validation_buffer, ctx->stream.next_in,
1298 ctx->validation_buffer_length);
1299 break;
1300 }
1301
1302 if (zRC != Z_OK) {
1303 return APR_EGENERAL;
1304 }
1305 }
1306
1307 apr_bucket_delete(e);
1308 }
1309
1310 apr_brigade_cleanup(bb);
1311 return APR_SUCCESS;
1312 }
1313
1314 #define PROTO_FLAGS AP_FILTER_PROTO_CHANGE|AP_FILTER_PROTO_CHANGE_LENGTH
1315 static void register_hooks(apr_pool_t *p)
1316 {
1317 ap_register_output_filter(deflateFilterName, deflate_out_filter, NULL,
1318 AP_FTYPE_CONTENT_SET);
1319 ap_register_output_filter("INFLATE", inflate_out_filter, NULL,
1320 AP_FTYPE_RESOURCE-1);
1321 ap_register_input_filter(deflateFilterName, deflate_in_filter, NULL,
1322 AP_FTYPE_CONTENT_SET);
1323 }
1324
1325 static const command_rec deflate_filter_cmds[] = {
1326 AP_INIT_TAKE12("DeflateFilterNote", deflate_set_note, NULL, RSRC_CONF,
1327 "Set a note to report on compression ratio"),
1328 AP_INIT_TAKE1("DeflateWindowSize", deflate_set_window_size, NULL,
1329 RSRC_CONF, "Set the Deflate window size (1-15)"),
1330 AP_INIT_TAKE1("DeflateBufferSize", deflate_set_buffer_size, NULL, RSRC_CONF,
1331 "Set the Deflate Buffer Size"),
1332 AP_INIT_TAKE1("DeflateMemLevel", deflate_set_memlevel, NULL, RSRC_CONF,
1333 "Set the Deflate Memory Level (1-9)"),
1334 AP_INIT_TAKE1("DeflateCompressionLevel", deflate_set_compressionlevel, NULL, RSRC_CONF,
1335 "Set the Deflate Compression Level (1-9)"),
1336 {NULL}
1337 };
1338
1339 module AP_MODULE_DECLARE_DATA deflate_module = {
1340 STANDARD20_MODULE_STUFF,
1341 NULL, /* dir config creater */
1342 NULL, /* dir merger --- default is to override */
1343 create_deflate_server_config, /* server config */
1344 NULL, /* merge server config */
1345 deflate_filter_cmds, /* command table */
1346 register_hooks /* register hooks */
1347 };

Properties

Name Value
svn:eol-style native

apache@apache.org
ViewVC Help
Powered by ViewVC 1.1.2