1 --- lighttpd-1.4.19/src/mod_compress.c 2008-09-19 17:24:45.542342957 +0300
2 +++ lighttpd-1.4.19/src/mod_compress.c 2008-09-22 14:24:00.738911820 +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