1 --- lighttpd-1.4.19/src/mod_compress.c 2008-09-22 16:24:49.930179728 +0300
2 +++ lighttpd-1.4.19/src/mod_compress.c 2008-09-22 17:02:36.097001825 +0300
4 buffer *compress_cache_dir;
6 off_t compress_max_filesize; /** max filesize in kb */
7 + int allowed_encodings;
12 { "compress.cache-dir", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },
13 { "compress.filetype", NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION },
14 { "compress.max-filesize", NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION },
15 + { "compress.allowed-encodings", NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION },
16 { NULL, NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }
21 for (i = 0; i < srv->config_context->used; i++) {
23 + array *encodings_arr = array_init();
25 s = calloc(1, sizeof(plugin_config));
26 s->compress_cache_dir = buffer_init();
27 s->compress = array_init();
28 s->compress_max_filesize = 0;
29 + s->allowed_encodings = 0;
31 cv[0].destination = s->compress_cache_dir;
32 cv[1].destination = s->compress;
33 cv[2].destination = &(s->compress_max_filesize);
34 + cv[3].destination = encodings_arr; /* temp array for allowed encodings list */
36 p->config_storage[i] = s;
42 + if (encodings_arr->used) {
44 + for (j = 0; j < encodings_arr->used; j++) {
45 + data_string *ds = (data_string *)encodings_arr->data[j];
47 + if (NULL != strstr(ds->value->ptr, "gzip"))
48 + s->allowed_encodings |= HTTP_ACCEPT_ENCODING_GZIP;
49 + if (NULL != strstr(ds->value->ptr, "deflate"))
50 + s->allowed_encodings |= HTTP_ACCEPT_ENCODING_DEFLATE;
52 + if (NULL != strstr(ds->value->ptr, "compress"))
53 + s->allowed_encodings |= HTTP_ACCEPT_ENCODING_COMPRESS;
57 + if (NULL != strstr(ds->value->ptr, "bzip2"))
58 + s->allowed_encodings |= HTTP_ACCEPT_ENCODING_BZIP2;
62 + /* default encodings */
63 + s->allowed_encodings = 0
65 + | HTTP_ACCEPT_ENCODING_GZIP | HTTP_ACCEPT_ENCODING_DEFLATE
68 + | HTTP_ACCEPT_ENCODING_BZIP2
73 + array_free(encodings_arr);
75 if (!buffer_is_empty(s->compress_cache_dir)) {
77 mkdir_recursive(s->compress_cache_dir->ptr);
79 PATCH(compress_cache_dir);
81 PATCH(compress_max_filesize);
82 + PATCH(allowed_encodings);
84 /* skip the first, the global context */
85 for (i = 1; i < srv->config_context->used; i++) {
88 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("compress.max-filesize"))) {
89 PATCH(compress_max_filesize);
90 + } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("compress.allowed-encodings"))) {
91 + PATCH(allowed_encodings);
96 if (NULL != (ds = (data_string *)array_get_element(con->request.headers, "Accept-Encoding"))) {
97 int accept_encoding = 0;
98 char *value = ds->value->ptr;
99 - int srv_encodings = 0;
100 int matched_encodings = 0;
102 /* get client side support encodings */
104 if (NULL != strstr(value, "gzip")) accept_encoding |= HTTP_ACCEPT_ENCODING_GZIP;
105 if (NULL != strstr(value, "deflate")) accept_encoding |= HTTP_ACCEPT_ENCODING_DEFLATE;
106 if (NULL != strstr(value, "compress")) accept_encoding |= HTTP_ACCEPT_ENCODING_COMPRESS;
107 - if (NULL != strstr(value, "bzip2")) accept_encoding |= HTTP_ACCEPT_ENCODING_BZIP2;
108 - if (NULL != strstr(value, "identity")) accept_encoding |= HTTP_ACCEPT_ENCODING_IDENTITY;
110 - /* get server side supported ones */
112 - srv_encodings |= HTTP_ACCEPT_ENCODING_BZIP2;
115 - srv_encodings |= HTTP_ACCEPT_ENCODING_GZIP;
116 - srv_encodings |= HTTP_ACCEPT_ENCODING_DEFLATE;
118 + if (NULL != strstr(value, "bzip2")) accept_encoding |= HTTP_ACCEPT_ENCODING_BZIP2;
120 + if (NULL != strstr(value, "identity")) accept_encoding |= HTTP_ACCEPT_ENCODING_IDENTITY;
122 /* find matching entries */
123 - matched_encodings = accept_encoding & srv_encodings;
124 + matched_encodings = accept_encoding & p->conf.allowed_encodings;
126 if (matched_encodings) {
127 const char *dflt_gzip = "gzip";
128 --- lighttpd-1.4.19/doc/compress.txt 2008-09-19 13:27:27.571638906 +0300
129 +++ lighttpd-1.4.19/doc/compress.txt 2008-09-19 14:24:12.308407368 +0300
134 +compress.allowed-encodings
135 + override default set of allowed encodings
138 + compress.allowed-encodings = ("bzip2", "gzip", "deflate")
141 name of the directory where compressed content will be cached
143 Index: mod-compress.conf
144 --- ./tests/mod-compress.conf (revision 0)
145 +++ ./tests/mod-compress.conf (revision 0)
147 +debug.log-request-handling = "enable"
148 +debug.log-response-header = "disable"
149 +debug.log-request-header = "disable"
151 +server.document-root = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
152 +server.pid-file = env.SRCDIR + "/tmp/lighttpd/lighttpd.pid"
154 +## bind to port (default: 80)
157 +## bind to localhost (default: all interfaces)
158 +server.bind = "localhost"
159 +server.errorlog = env.SRCDIR + "/tmp/lighttpd/logs/lighttpd.error.log"
160 +server.name = "www.example.org"
166 +######################## MODULE CONFIG ############################
169 + ".html" => "text/html",
170 + ".txt" => "text/plain",
173 +$HTTP["host"] == "cache.example.org" {
174 + compress.cache-dir = env.SRCDIR + "/tmp/lighttpd/cache/compress/"
176 +compress.filetype = ("text/plain", "text/html")
178 +compress.allowed-encodings = ( "gzip", "deflate" )
179 Index: mod-compress.t
180 ===================================================================
181 --- ./tests/mod-compress.t (revision 2191)
182 +++ ./tests/mod-compress.t (working copy)
187 -use Test::More tests => 10;
188 +use Test::More tests => 11;
191 my $tf = LightyTest->new();
194 +$tf->{CONFIGFILE} = 'mod-compress.conf';
196 ok($tf->start_proc == 0, "Starting lighttpd") or die();
198 $t->{REQUEST} = ( <<EOF
200 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '+Vary' => '', 'Content-Type' => "text/plain" } ];
201 ok($tf->handle_http($t) == 0, 'Empty Accept-Encoding');
203 +$t->{REQUEST} = ( <<EOF
204 +GET /index.txt HTTP/1.0
205 +Accept-Encoding: bzip2, gzip, deflate
206 +Host: cache.example.org
209 +$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '+Vary' => '', 'Content-Encoding' => 'gzip', 'Content-Type' => "text/plain" } ];
210 +ok($tf->handle_http($t) == 0, 'bzip2 requested but disabled');
213 ok($tf->stop_proc == 0, "Stopping lighttpd");