comparison src/http/modules/ngx_http_gzip_filter_module.c @ 527:7fa11e5c6e96 release-0.1.38

nginx-0.1.38-RELEASE import *) Feature: the "limit_rate" directive is supported in in proxy and FastCGI mode. *) Feature: the "X-Accel-Limit-Rate" response header line is supported in proxy and FastCGI mode. *) Feature: the "break" directive. *) Feature: the "log_not_found" directive. *) Bugfix: the response status code was not changed when request was redirected by the ""X-Accel-Redirect" header line. *) Bugfix: the variables set by the "set" directive could not be used in SSI. *) Bugfix: the segmentation fault may occurred if the SSI page has more than one remote subrequest. *) Bugfix: nginx treated the backend response as invalid if the status line in the header was transferred in two packets; the bug had appeared in 0.1.29. *) Feature: the "ssi_types" directive. *) Feature: the "autoindex_exact_size" directive. *) Bugfix: the ngx_http_autoindex_module did not support the long file names in UTF-8. *) Feature: the IMAP/POP3 proxy.
author Igor Sysoev <igor@sysoev.ru>
date Fri, 08 Jul 2005 14:34:20 +0000
parents fbbf16224844
children e5d7d0334fdb
comparison
equal deleted inserted replaced
526:e31ce4d8b8e6 527:7fa11e5c6e96
13 13
14 typedef struct { 14 typedef struct {
15 ngx_flag_t enable; 15 ngx_flag_t enable;
16 ngx_flag_t no_buffer; 16 ngx_flag_t no_buffer;
17 17
18 ngx_array_t *types; /* array of ngx_http_gzip_type_t */ 18 ngx_array_t *types; /* array of ngx_str_t */
19 19
20 ngx_bufs_t bufs; 20 ngx_bufs_t bufs;
21 21
22 ngx_uint_t http_version; 22 ngx_uint_t http_version;
23 ngx_uint_t proxied; 23 ngx_uint_t proxied;
25 int level; 25 int level;
26 size_t wbits; 26 size_t wbits;
27 size_t memlevel; 27 size_t memlevel;
28 ssize_t min_length; 28 ssize_t min_length;
29 } ngx_http_gzip_conf_t; 29 } ngx_http_gzip_conf_t;
30
31
32 typedef struct {
33 ngx_str_t name;
34 ngx_uint_t enable;
35 } ngx_http_gzip_type_t;
36 30
37 31
38 #define NGX_HTTP_GZIP_PROXIED_OFF 0x0002 32 #define NGX_HTTP_GZIP_PROXIED_OFF 0x0002
39 #define NGX_HTTP_GZIP_PROXIED_EXPIRED 0x0004 33 #define NGX_HTTP_GZIP_PROXIED_EXPIRED 0x0004
40 #define NGX_HTTP_GZIP_PROXIED_NO_CACHE 0x0008 34 #define NGX_HTTP_GZIP_PROXIED_NO_CACHE 0x0008
89 83
90 static ngx_int_t ngx_http_gzip_filter_init(ngx_cycle_t *cycle); 84 static ngx_int_t ngx_http_gzip_filter_init(ngx_cycle_t *cycle);
91 static void *ngx_http_gzip_create_conf(ngx_conf_t *cf); 85 static void *ngx_http_gzip_create_conf(ngx_conf_t *cf);
92 static char *ngx_http_gzip_merge_conf(ngx_conf_t *cf, 86 static char *ngx_http_gzip_merge_conf(ngx_conf_t *cf,
93 void *parent, void *child); 87 void *parent, void *child);
94 static char *ngx_http_gzip_set_types(ngx_conf_t *cf, ngx_command_t *cmd, 88 static char *ngx_http_gzip_types(ngx_conf_t *cf, ngx_command_t *cmd,
95 void *conf); 89 void *conf);
96 static char *ngx_http_gzip_set_window(ngx_conf_t *cf, void *post, void *data); 90 static char *ngx_http_gzip_window(ngx_conf_t *cf, void *post, void *data);
97 static char *ngx_http_gzip_set_hash(ngx_conf_t *cf, void *post, void *data); 91 static char *ngx_http_gzip_hash(ngx_conf_t *cf, void *post, void *data);
98 92
99 93
100 static ngx_conf_num_bounds_t ngx_http_gzip_comp_level_bounds = { 94 static ngx_conf_num_bounds_t ngx_http_gzip_comp_level_bounds = {
101 ngx_conf_check_num_bounds, 1, 9 95 ngx_conf_check_num_bounds, 1, 9
102 }; 96 };
103 97
104 static ngx_conf_post_handler_pt ngx_http_gzip_set_window_p = 98 static ngx_conf_post_handler_pt ngx_http_gzip_window_p = ngx_http_gzip_window;
105 ngx_http_gzip_set_window; 99 static ngx_conf_post_handler_pt ngx_http_gzip_hash_p = ngx_http_gzip_hash;
106 static ngx_conf_post_handler_pt ngx_http_gzip_set_hash_p =
107 ngx_http_gzip_set_hash;
108 100
109 101
110 102
111 static ngx_conf_enum_t ngx_http_gzip_http_version[] = { 103 static ngx_conf_enum_t ngx_http_gzip_http_version[] = {
112 { ngx_string("1.0"), NGX_HTTP_VERSION_10 }, 104 { ngx_string("1.0"), NGX_HTTP_VERSION_10 },
146 offsetof(ngx_http_gzip_conf_t, bufs), 138 offsetof(ngx_http_gzip_conf_t, bufs),
147 NULL }, 139 NULL },
148 140
149 { ngx_string("gzip_types"), 141 { ngx_string("gzip_types"),
150 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE, 142 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
151 ngx_http_gzip_set_types, 143 ngx_http_gzip_types,
152 NGX_HTTP_LOC_CONF_OFFSET, 144 NGX_HTTP_LOC_CONF_OFFSET,
153 0, 145 0,
154 NULL }, 146 NULL },
155 147
156 { ngx_string("gzip_comp_level"), 148 { ngx_string("gzip_comp_level"),
163 { ngx_string("gzip_window"), 155 { ngx_string("gzip_window"),
164 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, 156 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
165 ngx_conf_set_size_slot, 157 ngx_conf_set_size_slot,
166 NGX_HTTP_LOC_CONF_OFFSET, 158 NGX_HTTP_LOC_CONF_OFFSET,
167 offsetof(ngx_http_gzip_conf_t, wbits), 159 offsetof(ngx_http_gzip_conf_t, wbits),
168 &ngx_http_gzip_set_window_p }, 160 &ngx_http_gzip_window_p },
169 161
170 { ngx_string("gzip_hash"), 162 { ngx_string("gzip_hash"),
171 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, 163 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
172 ngx_conf_set_size_slot, 164 ngx_conf_set_size_slot,
173 NGX_HTTP_LOC_CONF_OFFSET, 165 NGX_HTTP_LOC_CONF_OFFSET,
174 offsetof(ngx_http_gzip_conf_t, memlevel), 166 offsetof(ngx_http_gzip_conf_t, memlevel),
175 &ngx_http_gzip_set_hash_p }, 167 &ngx_http_gzip_hash_p },
176 168
177 { ngx_string("gzip_no_buffer"), 169 { ngx_string("gzip_no_buffer"),
178 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, 170 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
179 ngx_conf_set_flag_slot, 171 ngx_conf_set_flag_slot,
180 NGX_HTTP_LOC_CONF_OFFSET, 172 NGX_HTTP_LOC_CONF_OFFSET,
268 260
269 261
270 static ngx_int_t 262 static ngx_int_t
271 ngx_http_gzip_header_filter(ngx_http_request_t *r) 263 ngx_http_gzip_header_filter(ngx_http_request_t *r)
272 { 264 {
273 ngx_uint_t i, found; 265 ngx_str_t *type;
266 ngx_uint_t i;
274 ngx_http_gzip_ctx_t *ctx; 267 ngx_http_gzip_ctx_t *ctx;
275 ngx_http_gzip_conf_t *conf; 268 ngx_http_gzip_conf_t *conf;
276 ngx_http_gzip_type_t *type;
277 269
278 conf = ngx_http_get_module_loc_conf(r, ngx_http_gzip_filter_module); 270 conf = ngx_http_get_module_loc_conf(r, ngx_http_gzip_filter_module);
279 271
280 if (!conf->enable 272 if (!conf->enable
281 || (r->headers_out.status != NGX_HTTP_OK 273 || (r->headers_out.status != NGX_HTTP_OK
295 { 287 {
296 return ngx_http_next_header_filter(r); 288 return ngx_http_next_header_filter(r);
297 } 289 }
298 290
299 291
300 found = 0;
301 type = conf->types->elts; 292 type = conf->types->elts;
302
303 for (i = 0; i < conf->types->nelts; i++) { 293 for (i = 0; i < conf->types->nelts; i++) {
304 if (r->headers_out.content_type.len >= type[i].name.len 294 if (r->headers_out.content_type.len >= type[i].len
305 && ngx_strncasecmp(r->headers_out.content_type.data, 295 && ngx_strncasecmp(r->headers_out.content_type.data,
306 type[i].name.data, type[i].name.len) == 0) 296 type[i].data, type[i].len) == 0)
307 { 297 {
308 found = 1; 298 goto found;
309 break; 299 }
310 } 300 }
311 } 301
312 302 return ngx_http_next_header_filter(r);
313 if (!found) { 303
314 return ngx_http_next_header_filter(r); 304
315 } 305 found:
316
317 306
318 if (r->headers_in.via) { 307 if (r->headers_in.via) {
319 if (conf->proxied & NGX_HTTP_GZIP_PROXIED_OFF) { 308 if (conf->proxied & NGX_HTTP_GZIP_PROXIED_OFF) {
320 return ngx_http_next_header_filter(r); 309 return ngx_http_next_header_filter(r);
321 } 310 }
1029 ngx_http_gzip_merge_conf(ngx_conf_t *cf, void *parent, void *child) 1018 ngx_http_gzip_merge_conf(ngx_conf_t *cf, void *parent, void *child)
1030 { 1019 {
1031 ngx_http_gzip_conf_t *prev = parent; 1020 ngx_http_gzip_conf_t *prev = parent;
1032 ngx_http_gzip_conf_t *conf = child; 1021 ngx_http_gzip_conf_t *conf = child;
1033 1022
1034 ngx_http_gzip_type_t *type; 1023 ngx_str_t *type;
1035 1024
1036 ngx_conf_merge_value(conf->enable, prev->enable, 0); 1025 ngx_conf_merge_value(conf->enable, prev->enable, 0);
1037 1026
1038 ngx_conf_merge_bufs_value(conf->bufs, prev->bufs, 4, ngx_pagesize); 1027 ngx_conf_merge_bufs_value(conf->bufs, prev->bufs, 4, ngx_pagesize);
1039 1028
1049 ngx_conf_merge_value(conf->min_length, prev->min_length, 0); 1038 ngx_conf_merge_value(conf->min_length, prev->min_length, 0);
1050 ngx_conf_merge_value(conf->no_buffer, prev->no_buffer, 0); 1039 ngx_conf_merge_value(conf->no_buffer, prev->no_buffer, 0);
1051 1040
1052 if (conf->types == NULL) { 1041 if (conf->types == NULL) {
1053 if (prev->types == NULL) { 1042 if (prev->types == NULL) {
1054 conf->types = ngx_array_create(cf->pool, 1, 1043 conf->types = ngx_array_create(cf->pool, 1, sizeof(ngx_str_t));
1055 sizeof(ngx_http_gzip_type_t));
1056 if (conf->types == NULL) { 1044 if (conf->types == NULL) {
1057 return NGX_CONF_ERROR; 1045 return NGX_CONF_ERROR;
1058 } 1046 }
1059 1047
1060 type = ngx_array_push(conf->types); 1048 type = ngx_array_push(conf->types);
1061 if (type == NULL) { 1049 if (type == NULL) {
1062 return NGX_CONF_ERROR; 1050 return NGX_CONF_ERROR;
1063 } 1051 }
1064 1052
1065 type->name.len = sizeof("text/html") - 1; 1053 type->len = sizeof("text/html") - 1;
1066 type->name.data = (u_char *) "text/html"; 1054 type->data = (u_char *) "text/html";
1067 type->enable = 1;
1068 1055
1069 } else { 1056 } else {
1070 conf->types = prev->types; 1057 conf->types = prev->types;
1071 } 1058 }
1072 } 1059 }
1074 return NGX_CONF_OK; 1061 return NGX_CONF_OK;
1075 } 1062 }
1076 1063
1077 1064
1078 static char * 1065 static char *
1079 ngx_http_gzip_set_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 1066 ngx_http_gzip_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
1080 { 1067 {
1081 ngx_http_gzip_conf_t *gcf = conf; 1068 ngx_http_gzip_conf_t *gcf = conf;
1082 1069
1083 ngx_str_t *value; 1070 ngx_str_t *value, *type;
1084 ngx_uint_t i; 1071 ngx_uint_t i;
1085 ngx_http_gzip_type_t *type;
1086 1072
1087 if (gcf->types == NULL) { 1073 if (gcf->types == NULL) {
1088 gcf->types = ngx_array_create(cf->pool, 4, 1074 gcf->types = ngx_array_create(cf->pool, 4, sizeof(ngx_str_t));
1089 sizeof(ngx_http_gzip_type_t));
1090 if (gcf->types == NULL) { 1075 if (gcf->types == NULL) {
1091 return NGX_CONF_ERROR; 1076 return NGX_CONF_ERROR;
1092 } 1077 }
1093 1078
1094 type = ngx_array_push(gcf->types); 1079 type = ngx_array_push(gcf->types);
1095 if (type == NULL) { 1080 if (type == NULL) {
1096 return NGX_CONF_ERROR; 1081 return NGX_CONF_ERROR;
1097 } 1082 }
1098 1083
1099 type->name.len = sizeof("text/html") - 1; 1084 type->len = sizeof("text/html") - 1;
1100 type->name.data = (u_char *) "text/html"; 1085 type->data = (u_char *) "text/html";
1101 type->enable = 1;
1102 } 1086 }
1103 1087
1104 value = cf->args->elts; 1088 value = cf->args->elts;
1105 1089
1106 for (i = 1; i < cf->args->nelts; i++) { 1090 for (i = 1; i < cf->args->nelts; i++) {
1112 type = ngx_array_push(gcf->types); 1096 type = ngx_array_push(gcf->types);
1113 if (type == NULL) { 1097 if (type == NULL) {
1114 return NGX_CONF_ERROR; 1098 return NGX_CONF_ERROR;
1115 } 1099 }
1116 1100
1117 type->name.len = value[i].len; 1101 type->len = value[i].len;
1118 1102
1119 type->name.data = ngx_palloc(cf->pool, type->name.len + 1); 1103 type->data = ngx_palloc(cf->pool, type->len + 1);
1120 if (type->name.data == NULL) { 1104 if (type->data == NULL) {
1121 return NGX_CONF_ERROR; 1105 return NGX_CONF_ERROR;
1122 } 1106 }
1123 1107
1124 ngx_cpystrn(type->name.data, value[i].data, type->name.len + 1); 1108 ngx_cpystrn(type->data, value[i].data, type->len + 1);
1125 } 1109 }
1126 1110
1127 return NGX_CONF_OK; 1111 return NGX_CONF_OK;
1128 } 1112 }
1129 1113
1130 1114
1131 static char * 1115 static char *
1132 ngx_http_gzip_set_window(ngx_conf_t *cf, void *post, void *data) 1116 ngx_http_gzip_window(ngx_conf_t *cf, void *post, void *data)
1133 { 1117 {
1134 int *np = data; 1118 int *np = data;
1135 1119
1136 int wbits, wsize; 1120 int wbits, wsize;
1137 1121
1151 return "must be 512, 1k, 2k, 4k, 8k, 16k, or 32k"; 1135 return "must be 512, 1k, 2k, 4k, 8k, 16k, or 32k";
1152 } 1136 }
1153 1137
1154 1138
1155 static char * 1139 static char *
1156 ngx_http_gzip_set_hash(ngx_conf_t *cf, void *post, void *data) 1140 ngx_http_gzip_hash(ngx_conf_t *cf, void *post, void *data)
1157 { 1141 {
1158 int *np = data; 1142 int *np = data;
1159 1143
1160 int memlevel, hsize; 1144 int memlevel, hsize;
1161 1145