{
int windowSize;
int memlevel;
+ int bufferSize;
char *noteName;
} deflate_filter_config;
/* windowsize is negative to suppress Zlib header */
#define DEFAULT_WINDOWSIZE -15
#define DEFAULT_MEMLEVEL 9
-#define FILTER_BUFSIZE 8096
+#define DEFAULT_BUFFERSIZE 8096
/* Outputs a long in LSB order to the given file
* only the bottom 4 bits are required for the deflate file format.
c->memlevel = DEFAULT_MEMLEVEL;
c->windowSize = DEFAULT_WINDOWSIZE;
+ c->bufferSize = DEFAULT_BUFFERSIZE;
return c;
}
return NULL;
}
+static const char *deflate_set_buffer_size(cmd_parms *cmd, void *dummy,
+ const char *arg)
+{
+ deflate_filter_config *c = ap_get_module_config(cmd->server->module_config,
+ &deflate_module);
+
+ c->bufferSize = atoi(arg);
+
+ if (c->bufferSize <= 0) {
+ return "DeflateBufferSize should be positive";
+ }
+
+ return NULL;
+}
static const char *deflate_set_note(cmd_parms *cmd, void *dummy,
const char *arg)
{
typedef struct deflate_ctx_t
{
z_stream stream;
- unsigned char buffer[FILTER_BUFSIZE];
+ unsigned char *buffer;
unsigned long crc;
apr_bucket_brigade *bb;
} deflate_ctx;
/* We're cool with filtering this. */
ctx = f->ctx = apr_pcalloc(r->pool, sizeof(*ctx));
ctx->bb = apr_brigade_create(r->pool, f->c->bucket_alloc);
+ ctx->buffer = apr_palloc(r->pool, c->bufferSize);
/*
ctx->stream.zalloc = (alloc_func) 0;
ctx->stream.zfree = (free_func) 0;
ctx->stream.avail_in = 0; /* should be zero already anyway */
for (;;) {
- deflate_len = FILTER_BUFSIZE - ctx->stream.avail_out;
+ deflate_len = c->bufferSize - ctx->stream.avail_out;
if (deflate_len != 0) {
b = apr_bucket_heap_create((char *)ctx->buffer,
f->c->bucket_alloc);
APR_BRIGADE_INSERT_TAIL(ctx->bb, b);
ctx->stream.next_out = ctx->buffer;
- ctx->stream.avail_out = FILTER_BUFSIZE;
+ ctx->stream.avail_out = c->bufferSize;
}
if (done) {
* trust zlib */
ctx->stream.avail_in = len;
ctx->stream.next_out = ctx->buffer;
- ctx->stream.avail_out = FILTER_BUFSIZE;
+ ctx->stream.avail_out = c->bufferSize;
while (ctx->stream.avail_in != 0) {
if (ctx->stream.avail_out == 0) {
ctx->stream.next_out = ctx->buffer;
- len = FILTER_BUFSIZE - ctx->stream.avail_out;
+ len = c->bufferSize - ctx->stream.avail_out;
b = apr_bucket_heap_create((char *)ctx->buffer, len,
NULL, f->c->bucket_alloc);
APR_BRIGADE_INSERT_TAIL(ctx->bb, b);
- ctx->stream.avail_out = FILTER_BUFSIZE;
+ ctx->stream.avail_out = c->bufferSize;
}
zRC = deflate(&(ctx->stream), Z_NO_FLUSH);
"Set a note to report on compression ratio"),
AP_INIT_TAKE1("DeflateWindowSize", deflate_set_window_size, NULL,
RSRC_CONF, "Set the Deflate window size (1-15)"),
+ AP_INIT_TAKE1("DeflateBufferSize", deflate_set_buffer_size, NULL, RSRC_CONF,
+ "Set the Deflate Buffer Size"),
AP_INIT_TAKE1("DeflateMemLevel", deflate_set_memlevel, NULL, RSRC_CONF,
"Set the Deflate Memory Level (1-9)"),
{NULL}