1 --- lighttpd-1.4.19/src/mod_compress.c 2008-09-19 14:16:06.292324544 +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;
20 p->ofn = buffer_init();
22 + p->encodings_arr = array_init();
27 { "compress.cache-dir", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_CONNECTION },
28 { "compress.filetype", NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION },
29 { "compress.max-filesize", NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION },
30 + { "compress.allowed_encodings", NULL, T_CONFIG_ARRAY, T_CONFIG_SCOPE_CONNECTION },
31 { NULL, NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }
35 s->compress_cache_dir = buffer_init();
36 s->compress = array_init();
37 s->compress_max_filesize = 0;
38 + s->allowed_encodings = 0;
40 cv[0].destination = s->compress_cache_dir;
41 cv[1].destination = s->compress;
42 cv[2].destination = &(s->compress_max_filesize);
43 + cv[3].destination = p->encodings_arr; /* temp array for allowed encodings list */
45 p->config_storage[i] = s;
51 + if (p->encodings_arr->used) {
53 + for (j = 0; j < p->encodings_arr->used; j++) {
54 + data_string *ds = (data_string *)p->encodings_arr->data[j];
56 + if (NULL != strstr(ds->value->ptr, "gzip"))
57 + s->allowed_encodings |= HTTP_ACCEPT_ENCODING_GZIP;
58 + if (NULL != strstr(ds->value->ptr, "deflate"))
59 + s->allowed_encodings |= HTTP_ACCEPT_ENCODING_DEFLATE;
62 + if (NULL != strstr(ds->value->ptr, "compress"))
63 + s->allowed_encodings |= HTTP_ACCEPT_ENCODING_COMPRESS;
66 + if (NULL != strstr(ds->value->ptr, "bzip2"))
67 + s->allowed_encodings |= HTTP_ACCEPT_ENCODING_BZIP2;
71 + /* default encodings */
72 + s->allowed_encodings = HTTP_ACCEPT_ENCODING_IDENTITY | HTTP_ACCEPT_ENCODING_GZIP |
73 + HTTP_ACCEPT_ENCODING_DEFLATE | HTTP_ACCEPT_ENCODING_COMPRESS | HTTP_ACCEPT_ENCODING_BZIP2;
77 if (!buffer_is_empty(s->compress_cache_dir)) {
79 mkdir_recursive(s->compress_cache_dir->ptr);
81 PATCH(compress_cache_dir);
83 PATCH(compress_max_filesize);
84 + PATCH(allowed_encodings);
86 /* skip the first, the global context */
87 for (i = 1; i < srv->config_context->used; i++) {
90 } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("compress.max-filesize"))) {
91 PATCH(compress_max_filesize);
92 + } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("compress.allowed_encodings"))) {
93 + PATCH(allowed_encodings);
98 if (NULL != (ds = (data_string *)array_get_element(con->request.headers, "Accept-Encoding"))) {
99 int accept_encoding = 0;
100 char *value = ds->value->ptr;
101 - int srv_encodings = 0;
102 int matched_encodings = 0;
104 /* get client side support encodings */
105 if (NULL != strstr(value, "gzip")) accept_encoding |= HTTP_ACCEPT_ENCODING_GZIP;
106 if (NULL != strstr(value, "deflate")) accept_encoding |= HTTP_ACCEPT_ENCODING_DEFLATE;
107 if (NULL != strstr(value, "compress")) accept_encoding |= HTTP_ACCEPT_ENCODING_COMPRESS;
108 - if (NULL != strstr(value, "bzip2")) accept_encoding |= HTTP_ACCEPT_ENCODING_BZIP2;
109 - if (NULL != strstr(value, "identity")) accept_encoding |= HTTP_ACCEPT_ENCODING_IDENTITY;
111 - /* get server side supported ones */
113 - srv_encodings |= HTTP_ACCEPT_ENCODING_BZIP2;
116 - srv_encodings |= HTTP_ACCEPT_ENCODING_GZIP;
117 - 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