]> git.pld-linux.org Git - packages/lighttpd.git/blob - lighttpd-mod_compress-disable-bzip2.patch
- update to r2392 (PRE-RELEASE: 1.4.21-r2392)
[packages/lighttpd.git] / lighttpd-mod_compress-disable-bzip2.patch
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
3 @@ -49,6 +49,7 @@
4         buffer *compress_cache_dir;
5         array  *compress;
6         off_t   compress_max_filesize; /** max filesize in kb */
7 +       int     allowed_encodings;
8  } plugin_config;
9  
10  typedef struct {
11 @@ -154,6 +155,7 @@
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 }
17         };
18  
19 @@ -161,15 +163,18 @@
20  
21         for (i = 0; i < srv->config_context->used; i++) {
22                 plugin_config *s;
23 +               array  *encodings_arr = array_init();
24  
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;
30  
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 */
35  
36                 p->config_storage[i] = s;
37  
38 @@ -177,6 +182,39 @@
39                         return HANDLER_ERROR;
40                 }
41  
42 +               if (encodings_arr->used) {
43 +                       size_t j = 0;
44 +                       for (j = 0; j < encodings_arr->used; j++) {
45 +                               data_string *ds = (data_string *)encodings_arr->data[j];
46 +#ifdef USE_ZLIB
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;
51 +                               /*
52 +                               if (NULL != strstr(ds->value->ptr, "compress"))
53 +                                       s->allowed_encodings |= HTTP_ACCEPT_ENCODING_COMPRESS;
54 +                               */
55 +#endif
56 +#ifdef USE_BZ2LIB
57 +                               if (NULL != strstr(ds->value->ptr, "bzip2"))
58 +                                       s->allowed_encodings |= HTTP_ACCEPT_ENCODING_BZIP2;
59 +#endif
60 +                       }
61 +               } else {
62 +                       /* default encodings */
63 +                       s->allowed_encodings = 0
64 +#ifdef USE_ZLIB
65 +                               | HTTP_ACCEPT_ENCODING_GZIP | HTTP_ACCEPT_ENCODING_DEFLATE
66 +#endif
67 +#ifdef USE_BZ2LIB
68 +                               | HTTP_ACCEPT_ENCODING_BZIP2
69 +#endif
70 +                               ;
71 +               }
72 +
73 +               array_free(encodings_arr);
74 +
75                 if (!buffer_is_empty(s->compress_cache_dir)) {
76                         struct stat st;
77                         mkdir_recursive(s->compress_cache_dir->ptr);
78 @@ -587,6 +625,7 @@
79         PATCH(compress_cache_dir);
80         PATCH(compress);
81         PATCH(compress_max_filesize);
82 +       PATCH(allowed_encodings);
83  
84         /* skip the first, the global context */
85         for (i = 1; i < srv->config_context->used; i++) {
86 @@ -606,6 +645,8 @@
87                                 PATCH(compress);
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);
92                         }
93                 }
94         }
95 @@ -668,27 +709,21 @@
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;
101  
102                                 /* get client side support encodings */
103 +#ifdef USE_ZLIB
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;
109 -
110 -                               /* get server side supported ones */
111 -#ifdef USE_BZ2LIB
112 -                               srv_encodings |= HTTP_ACCEPT_ENCODING_BZIP2;
113  #endif
114 -#ifdef USE_ZLIB
115 -                               srv_encodings |= HTTP_ACCEPT_ENCODING_GZIP;
116 -                               srv_encodings |= HTTP_ACCEPT_ENCODING_DEFLATE;
117 +#ifdef USE_BZ2LIB
118 +                               if (NULL != strstr(value, "bzip2")) accept_encoding |= HTTP_ACCEPT_ENCODING_BZIP2;
119  #endif
120 +                               if (NULL != strstr(value, "identity")) accept_encoding |= HTTP_ACCEPT_ENCODING_IDENTITY;
121  
122                                 /* find matching entries */
123 -                               matched_encodings = accept_encoding & srv_encodings;
124 +                               matched_encodings = accept_encoding & p->conf.allowed_encodings;
125  
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
130 @@ -32,6 +32,12 @@
131  Options
132  =======
133  
134 +compress.allowed-encodings
135 +  override default set of allowed encodings
136 +
137 +  e.g.: ::
138 +    compress.allowed-encodings = ("bzip2", "gzip", "deflate")
139 +
140  compress.cache-dir
141    name of the directory where compressed content will be cached
142  
143 Index: mod-compress.conf
144 --- ./tests/mod-compress.conf   (revision 0)
145 +++ ./tests/mod-compress.conf   (revision 0)
146 @@ -0,0 +1,32 @@
147 +debug.log-request-handling   = "enable"
148 +debug.log-response-header   = "disable"
149 +debug.log-request-header   = "disable"
150 +
151 +server.document-root         = env.SRCDIR + "/tmp/lighttpd/servers/www.example.org/pages/"
152 +server.pid-file              = env.SRCDIR + "/tmp/lighttpd/lighttpd.pid"
153 +
154 +## bind to port (default: 80)
155 +server.port                 = 2048
156 +
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"
161 +
162 +server.modules = (
163 +       "mod_compress"
164 +)
165 +
166 +######################## MODULE CONFIG ############################
167 +
168 +mimetype.assign = (
169 +       ".html" => "text/html",
170 +       ".txt"  => "text/plain",
171 +)
172 +
173 +$HTTP["host"] == "cache.example.org" {
174 +       compress.cache-dir = env.SRCDIR + "/tmp/lighttpd/cache/compress/"
175 +}
176 +compress.filetype = ("text/plain", "text/html")
177 +
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)
183 @@ -8,12 +8,14 @@
184  
185  use strict;
186  use IO::Socket;
187 -use Test::More tests => 10;
188 +use Test::More tests => 11;
189  use LightyTest;
190  
191  my $tf = LightyTest->new();
192  my $t;
193  
194 +$tf->{CONFIGFILE} = 'mod-compress.conf';
195 +
196  ok($tf->start_proc == 0, "Starting lighttpd") or die();
197  
198  $t->{REQUEST}  = ( <<EOF
199 @@ -88,5 +90,14 @@
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');
202  
203 +$t->{REQUEST}  = ( <<EOF
204 +GET /index.txt HTTP/1.0
205 +Accept-Encoding: bzip2, gzip, deflate
206 +Host: cache.example.org
207 +EOF
208 + );
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');
211  
212 +
213  ok($tf->stop_proc == 0, "Stopping lighttpd");
This page took 0.044287 seconds and 3 git commands to generate.