Mercurial > hg > nginx
comparison src/http/modules/ngx_http_gzip_static_module.c @ 4836:e368b822d034
Gzip static: "always" parameter in "gzip_static" directive.
With "always" gzip static returns gzipped content in all cases, without
checking if client supports it. It is useful if there are no uncompressed
files on disk anyway.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 10 Sep 2012 16:48:25 +0000 |
parents | 192f54280a7a |
children | ceecde39853f |
comparison
equal
deleted
inserted
replaced
4835:a4512d7737f6 | 4836:e368b822d034 |
---|---|
8 #include <ngx_config.h> | 8 #include <ngx_config.h> |
9 #include <ngx_core.h> | 9 #include <ngx_core.h> |
10 #include <ngx_http.h> | 10 #include <ngx_http.h> |
11 | 11 |
12 | 12 |
13 #define NGX_HTTP_GZIP_STATIC_OFF 0 | |
14 #define NGX_HTTP_GZIP_STATIC_ON 1 | |
15 #define NGX_HTTP_GZIP_STATIC_ALWAYS 2 | |
16 | |
17 | |
13 typedef struct { | 18 typedef struct { |
14 ngx_flag_t enable; | 19 ngx_uint_t enable; |
15 } ngx_http_gzip_static_conf_t; | 20 } ngx_http_gzip_static_conf_t; |
16 | 21 |
17 | 22 |
18 static ngx_int_t ngx_http_gzip_static_handler(ngx_http_request_t *r); | 23 static ngx_int_t ngx_http_gzip_static_handler(ngx_http_request_t *r); |
19 static void *ngx_http_gzip_static_create_conf(ngx_conf_t *cf); | 24 static void *ngx_http_gzip_static_create_conf(ngx_conf_t *cf); |
20 static char *ngx_http_gzip_static_merge_conf(ngx_conf_t *cf, void *parent, | 25 static char *ngx_http_gzip_static_merge_conf(ngx_conf_t *cf, void *parent, |
21 void *child); | 26 void *child); |
22 static ngx_int_t ngx_http_gzip_static_init(ngx_conf_t *cf); | 27 static ngx_int_t ngx_http_gzip_static_init(ngx_conf_t *cf); |
23 | 28 |
24 | 29 |
30 static ngx_conf_enum_t ngx_http_gzip_static[] = { | |
31 { ngx_string("off"), NGX_HTTP_GZIP_STATIC_OFF }, | |
32 { ngx_string("on"), NGX_HTTP_GZIP_STATIC_ON }, | |
33 { ngx_string("always"), NGX_HTTP_GZIP_STATIC_ALWAYS }, | |
34 { ngx_null_string, 0 } | |
35 }; | |
36 | |
37 | |
25 static ngx_command_t ngx_http_gzip_static_commands[] = { | 38 static ngx_command_t ngx_http_gzip_static_commands[] = { |
26 | 39 |
27 { ngx_string("gzip_static"), | 40 { ngx_string("gzip_static"), |
28 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | 41 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, |
29 ngx_conf_set_flag_slot, | 42 ngx_conf_set_enum_slot, |
30 NGX_HTTP_LOC_CONF_OFFSET, | 43 NGX_HTTP_LOC_CONF_OFFSET, |
31 offsetof(ngx_http_gzip_static_conf_t, enable), | 44 offsetof(ngx_http_gzip_static_conf_t, enable), |
32 NULL }, | 45 &ngx_http_gzip_static }, |
33 | 46 |
34 ngx_null_command | 47 ngx_null_command |
35 }; | 48 }; |
36 | 49 |
37 | 50 |
90 return NGX_DECLINED; | 103 return NGX_DECLINED; |
91 } | 104 } |
92 | 105 |
93 gzcf = ngx_http_get_module_loc_conf(r, ngx_http_gzip_static_module); | 106 gzcf = ngx_http_get_module_loc_conf(r, ngx_http_gzip_static_module); |
94 | 107 |
95 if (!gzcf->enable) { | 108 if (gzcf->enable == NGX_HTTP_GZIP_STATIC_OFF) { |
96 return NGX_DECLINED; | 109 return NGX_DECLINED; |
97 } | 110 } |
98 | 111 |
99 rc = ngx_http_gzip_ok(r); | 112 if (gzcf->enable == NGX_HTTP_GZIP_STATIC_ON) { |
113 rc = ngx_http_gzip_ok(r); | |
114 | |
115 } else { | |
116 /* always */ | |
117 rc = NGX_OK; | |
118 } | |
100 | 119 |
101 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | 120 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
102 | 121 |
103 if (!clcf->gzip_vary && rc != NGX_OK) { | 122 if (!clcf->gzip_vary && rc != NGX_OK) { |
104 return NGX_DECLINED; | 123 return NGX_DECLINED; |
167 "%s \"%s\" failed", of.failed, path.data); | 186 "%s \"%s\" failed", of.failed, path.data); |
168 | 187 |
169 return NGX_DECLINED; | 188 return NGX_DECLINED; |
170 } | 189 } |
171 | 190 |
172 r->gzip_vary = 1; | 191 if (gzcf->enable == NGX_HTTP_GZIP_STATIC_ON) { |
173 | 192 r->gzip_vary = 1; |
174 if (rc != NGX_OK) { | 193 |
175 return NGX_DECLINED; | 194 if (rc != NGX_OK) { |
195 return NGX_DECLINED; | |
196 } | |
176 } | 197 } |
177 | 198 |
178 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, "http static fd: %d", of.fd); | 199 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, log, 0, "http static fd: %d", of.fd); |
179 | 200 |
180 if (of.is_dir) { | 201 if (of.is_dir) { |
272 conf = ngx_palloc(cf->pool, sizeof(ngx_http_gzip_static_conf_t)); | 293 conf = ngx_palloc(cf->pool, sizeof(ngx_http_gzip_static_conf_t)); |
273 if (conf == NULL) { | 294 if (conf == NULL) { |
274 return NULL; | 295 return NULL; |
275 } | 296 } |
276 | 297 |
277 conf->enable = NGX_CONF_UNSET; | 298 conf->enable = NGX_CONF_UNSET_UINT; |
278 | 299 |
279 return conf; | 300 return conf; |
280 } | 301 } |
281 | 302 |
282 | 303 |
284 ngx_http_gzip_static_merge_conf(ngx_conf_t *cf, void *parent, void *child) | 305 ngx_http_gzip_static_merge_conf(ngx_conf_t *cf, void *parent, void *child) |
285 { | 306 { |
286 ngx_http_gzip_static_conf_t *prev = parent; | 307 ngx_http_gzip_static_conf_t *prev = parent; |
287 ngx_http_gzip_static_conf_t *conf = child; | 308 ngx_http_gzip_static_conf_t *conf = child; |
288 | 309 |
289 ngx_conf_merge_value(conf->enable, prev->enable, 0); | 310 ngx_conf_merge_uint_value(conf->enable, prev->enable, |
311 NGX_HTTP_GZIP_STATIC_OFF); | |
290 | 312 |
291 return NGX_CONF_OK; | 313 return NGX_CONF_OK; |
292 } | 314 } |
293 | 315 |
294 | 316 |