1 --- lighttpd-1.4.19/src/mod_compress.c 2008-09-19 13:24:30.921429633 +0300
2 +++ lighttpd-1.4.19/src/mod_compress.c 2008-09-19 14:16:06.292324544 +0300
4 buffer *compress_cache_dir;
6 off_t compress_max_filesize; /** max filesize in kb */
7 + int allowed_encodings;
14 + array *encodings_arr;
16 plugin_config **config_storage;
19 { "compress.cache-dir", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },
20 { "compress.filetype", NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION },
21 { "compress.max-filesize", NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION },
22 + { "compress.allowed_encodings", NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION },
23 { NULL, NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }
27 s->compress_cache_dir = buffer_init();
28 s->compress = array_init();
29 s->compress_max_filesize = 0;
30 + s->allowed_encodings = 0;
32 cv[0].destination = s->compress_cache_dir;
33 cv[1].destination = s->compress;
34 cv[2].destination = &(s->compress_max_filesize);
35 + cv[3].destination = p->encodings_arr; /* temp array for allowed encodings list */
37 p->config_storage[i] = s;
43 + if (p->encodings_arr->used) {
45 + for (j = 0; j < p->encodings_arr->used; j++) {
46 + data_string *ds = (data_string *)p->encodings_arr->data[j];
48 + if (NULL != strstr(ds->value->ptr, "gzip"))
49 + s->allowed_encodings |= HTTP_ACCEPT_ENCODING_GZIP;
50 + if (NULL != strstr(ds->value->ptr, "deflate"))
51 + s->allowed_encodings |= HTTP_ACCEPT_ENCODING_DEFLATE;
54 + if (NULL != strstr(ds->value->ptr, "compress"))
55 + s->allowed_encodings |= HTTP_ACCEPT_ENCODING_COMPRESS;
58 + if (NULL != strstr(ds->value->ptr, "bzip2"))
59 + s->allowed_encodings |= HTTP_ACCEPT_ENCODING_BZIP2;
63 + /* default encodings */
64 + s->allowed_encodings = HTTP_ACCEPT_ENCODING_IDENTITY | HTTP_ACCEPT_ENCODING_GZIP |
65 + HTTP_ACCEPT_ENCODING_DEFLATE | HTTP_ACCEPT_ENCODING_COMPRESS | HTTP_ACCEPT_ENCODING_BZIP2;
69 if (!buffer_is_empty(s->compress_cache_dir)) {
71 mkdir_recursive(s->compress_cache_dir->ptr);
73 PATCH(compress_cache_dir);
75 PATCH(compress_max_filesize);
76 + PATCH(allowed_encodings);
78 /* skip the first, the global context */
79 for (i = 1; i < srv->config_context->used; i++) {
82 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("compress.max-filesize"))) {
83 PATCH(compress_max_filesize);
84 + } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("compress.allowed_encodings"))) {
85 + PATCH(allowed_encodings);
90 if (NULL != (ds = (data_string *)array_get_element(con->request.headers, "Accept-Encoding"))) {
91 int accept_encoding = 0;
92 char *value = ds->value->ptr;
93 - int srv_encodings = 0;
94 int matched_encodings = 0;
96 /* get client side support encodings */
97 if (NULL != strstr(value, "gzip")) accept_encoding |= HTTP_ACCEPT_ENCODING_GZIP;
98 if (NULL != strstr(value, "deflate")) accept_encoding |= HTTP_ACCEPT_ENCODING_DEFLATE;
99 if (NULL != strstr(value, "compress")) accept_encoding |= HTTP_ACCEPT_ENCODING_COMPRESS;
100 - if (NULL != strstr(value, "bzip2")) accept_encoding |= HTTP_ACCEPT_ENCODING_BZIP2;
101 - if (NULL != strstr(value, "identity")) accept_encoding |= HTTP_ACCEPT_ENCODING_IDENTITY;
103 - /* get server side supported ones */
105 - srv_encodings |= HTTP_ACCEPT_ENCODING_BZIP2;
108 - srv_encodings |= HTTP_ACCEPT_ENCODING_GZIP;
109 - srv_encodings |= HTTP_ACCEPT_ENCODING_DEFLATE;
110 + if (NULL != strstr(value, "bzip2")) accept_encoding |= HTTP_ACCEPT_ENCODING_BZIP2;
112 + if (NULL != strstr(value, "identity")) accept_encoding |= HTTP_ACCEPT_ENCODING_IDENTITY;
114 /* find matching entries */
115 - matched_encodings = accept_encoding & srv_encodings;
116 + matched_encodings = accept_encoding & p->conf.allowed_encodings;
118 if (matched_encodings) {
119 const char *dflt_gzip = "gzip";
120 --- lighttpd-1.4.19/doc/compress.txt 2008-09-19 13:27:27.571638906 +0300
121 +++ lighttpd-1.4.19/doc/compress.txt 2008-09-19 14:24:12.308407368 +0300
126 +compress.allowed_encodings
127 + override default set of allowed encodings
130 + compress.allowed_encodings = ("bzip2", "gzip", "deflate")
133 name of the directory where compressed content will be cached