comparison src/http/modules/ngx_http_ssi_filter_module.c @ 394:05981f639d21 NGINX_0_7_9

nginx 0.7.9 *) Change: now ngx_http_charset_module works by default with following MIME types: text/html, text/css, text/xml, text/plain, text/vnd.wap.wml, application/x-javascript, and application/rss+xml. *) Feature: the "charset_types" and "addition_types" directives. *) Feature: now the "gzip_types", "ssi_types", and "sub_filter_types" directives use hash. *) Feature: the ngx_cpp_test_module. *) Feature: the "expires" directive supports daily time. *) Feature: the ngx_http_xslt_module improvements and bug fixing. Thanks to Denis F. Latypoff and Maxim Dounin. *) Bugfix: the "log_not_found" directive did not work for index files tests. *) Bugfix: HTTPS connections might hang, if kqueue, epoll, rtsig, or eventport methods were used; the bug had appeared in 0.7.7. *) Bugfix: if the "server_name", "valid_referers", and "map" directives used an "*.domain.tld" wildcard and exact name "domain.tld" was not set, then the exact name was matched by the wildcard; the bugs had appeared in 0.3.18.
author Igor Sysoev <http://sysoev.ru>
date Tue, 12 Aug 2008 00:00:00 +0400
parents 34fb3a573548
children e7dbea1ee115
comparison
equal deleted inserted replaced
393:040b8c84d040 394:05981f639d21
20 typedef struct { 20 typedef struct {
21 ngx_flag_t enable; 21 ngx_flag_t enable;
22 ngx_flag_t silent_errors; 22 ngx_flag_t silent_errors;
23 ngx_flag_t ignore_recycled_buffers; 23 ngx_flag_t ignore_recycled_buffers;
24 24
25 ngx_array_t *types; /* array of ngx_str_t */ 25 ngx_hash_t types;
26 26
27 size_t min_file_chunk; 27 size_t min_file_chunk;
28 size_t value_len; 28 size_t value_len;
29
30 ngx_array_t *types_keys;
29 } ngx_http_ssi_loc_conf_t; 31 } ngx_http_ssi_loc_conf_t;
30 32
31 33
32 typedef struct { 34 typedef struct {
33 ngx_str_t name; 35 ngx_str_t name;
100 ngx_http_ssi_ctx_t *ctx, ngx_str_t **params); 102 ngx_http_ssi_ctx_t *ctx, ngx_str_t **params);
101 103
102 static ngx_int_t ngx_http_ssi_date_gmt_local_variable(ngx_http_request_t *r, 104 static ngx_int_t ngx_http_ssi_date_gmt_local_variable(ngx_http_request_t *r,
103 ngx_http_variable_value_t *v, uintptr_t gmt); 105 ngx_http_variable_value_t *v, uintptr_t gmt);
104 106
105 static char *ngx_http_ssi_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
106
107 static ngx_int_t ngx_http_ssi_preconfiguration(ngx_conf_t *cf); 107 static ngx_int_t ngx_http_ssi_preconfiguration(ngx_conf_t *cf);
108 static void *ngx_http_ssi_create_main_conf(ngx_conf_t *cf); 108 static void *ngx_http_ssi_create_main_conf(ngx_conf_t *cf);
109 static char *ngx_http_ssi_init_main_conf(ngx_conf_t *cf, void *conf); 109 static char *ngx_http_ssi_init_main_conf(ngx_conf_t *cf, void *conf);
110 static void *ngx_http_ssi_create_loc_conf(ngx_conf_t *cf); 110 static void *ngx_http_ssi_create_loc_conf(ngx_conf_t *cf);
111 static char *ngx_http_ssi_merge_loc_conf(ngx_conf_t *cf, 111 static char *ngx_http_ssi_merge_loc_conf(ngx_conf_t *cf,
151 offsetof(ngx_http_ssi_loc_conf_t, value_len), 151 offsetof(ngx_http_ssi_loc_conf_t, value_len),
152 NULL }, 152 NULL },
153 153
154 { ngx_string("ssi_types"), 154 { ngx_string("ssi_types"),
155 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE, 155 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
156 ngx_http_ssi_types, 156 ngx_http_types_slot,
157 NGX_HTTP_LOC_CONF_OFFSET, 157 NGX_HTTP_LOC_CONF_OFFSET,
158 0, 158 offsetof(ngx_http_ssi_loc_conf_t, types_keys),
159 NULL }, 159 &ngx_http_html_default_types[0] },
160 160
161 ngx_null_command 161 ngx_null_command
162 }; 162 };
163 163
164 164
314 314
315 315
316 static ngx_int_t 316 static ngx_int_t
317 ngx_http_ssi_header_filter(ngx_http_request_t *r) 317 ngx_http_ssi_header_filter(ngx_http_request_t *r)
318 { 318 {
319 ngx_uint_t i;
320 ngx_str_t *type;
321 ngx_http_ssi_ctx_t *ctx; 319 ngx_http_ssi_ctx_t *ctx;
322 ngx_http_ssi_loc_conf_t *slcf; 320 ngx_http_ssi_loc_conf_t *slcf;
323 321
324 slcf = ngx_http_get_module_loc_conf(r, ngx_http_ssi_filter_module); 322 slcf = ngx_http_get_module_loc_conf(r, ngx_http_ssi_filter_module);
325 323
326 if (!slcf->enable 324 if (!slcf->enable
327 || r->headers_out.content_type.len == 0 325 || r->headers_out.content_length_n == 0
328 || r->headers_out.content_length_n == 0) 326 || ngx_http_test_content_type(r, &slcf->types) == NULL)
329 { 327 {
330 return ngx_http_next_header_filter(r); 328 return ngx_http_next_header_filter(r);
331 } 329 }
332
333
334 type = slcf->types->elts;
335 for (i = 0; i < slcf->types->nelts; i++) {
336 if (r->headers_out.content_type.len >= type[i].len
337 && ngx_strncasecmp(r->headers_out.content_type.data,
338 type[i].data, type[i].len) == 0)
339 {
340 goto found;
341 }
342 }
343
344 return ngx_http_next_header_filter(r);
345
346
347 found:
348 330
349 ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_ssi_ctx_t)); 331 ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_ssi_ctx_t));
350 if (ctx == NULL) { 332 if (ctx == NULL) {
351 return NGX_ERROR; 333 return NGX_ERROR;
352 } 334 }
2677 2659
2678 return NGX_OK; 2660 return NGX_OK;
2679 } 2661 }
2680 2662
2681 2663
2682 static char *
2683 ngx_http_ssi_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
2684 {
2685 ngx_http_ssi_loc_conf_t *slcf = conf;
2686
2687 ngx_str_t *value, *type;
2688 ngx_uint_t i;
2689
2690 if (slcf->types == NULL) {
2691 slcf->types = ngx_array_create(cf->pool, 4, sizeof(ngx_str_t));
2692 if (slcf->types == NULL) {
2693 return NGX_CONF_ERROR;
2694 }
2695
2696 type = ngx_array_push(slcf->types);
2697 if (type == NULL) {
2698 return NGX_CONF_ERROR;
2699 }
2700
2701 type->len = sizeof("text/html") - 1;
2702 type->data = (u_char *) "text/html";
2703 }
2704
2705 value = cf->args->elts;
2706
2707 for (i = 1; i < cf->args->nelts; i++) {
2708
2709 if (ngx_strcmp(value[i].data, "text/html") == 0) {
2710 continue;
2711 }
2712
2713 type = ngx_array_push(slcf->types);
2714 if (type == NULL) {
2715 return NGX_CONF_ERROR;
2716 }
2717
2718 type->len = value[i].len;
2719
2720 type->data = ngx_pnalloc(cf->pool, type->len + 1);
2721 if (type->data == NULL) {
2722 return NGX_CONF_ERROR;
2723 }
2724
2725 ngx_cpystrn(type->data, value[i].data, type->len + 1);
2726 }
2727
2728 return NGX_CONF_OK;
2729 }
2730
2731
2732 static ngx_int_t 2664 static ngx_int_t
2733 ngx_http_ssi_preconfiguration(ngx_conf_t *cf) 2665 ngx_http_ssi_preconfiguration(ngx_conf_t *cf)
2734 { 2666 {
2735 ngx_int_t rc; 2667 ngx_int_t rc;
2736 ngx_http_variable_t *var, *v; 2668 ngx_http_variable_t *var, *v;
2827 } 2759 }
2828 2760
2829 /* 2761 /*
2830 * set by ngx_pcalloc(): 2762 * set by ngx_pcalloc():
2831 * 2763 *
2832 * conf->types = NULL; 2764 * conf->types = { NULL };
2765 * conf->types_keys = NULL;
2833 */ 2766 */
2834 2767
2835 slcf->enable = NGX_CONF_UNSET; 2768 slcf->enable = NGX_CONF_UNSET;
2836 slcf->silent_errors = NGX_CONF_UNSET; 2769 slcf->silent_errors = NGX_CONF_UNSET;
2837 slcf->ignore_recycled_buffers = NGX_CONF_UNSET; 2770 slcf->ignore_recycled_buffers = NGX_CONF_UNSET;
2847 ngx_http_ssi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) 2780 ngx_http_ssi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
2848 { 2781 {
2849 ngx_http_ssi_loc_conf_t *prev = parent; 2782 ngx_http_ssi_loc_conf_t *prev = parent;
2850 ngx_http_ssi_loc_conf_t *conf = child; 2783 ngx_http_ssi_loc_conf_t *conf = child;
2851 2784
2852 ngx_str_t *type;
2853
2854 ngx_conf_merge_value(conf->enable, prev->enable, 0); 2785 ngx_conf_merge_value(conf->enable, prev->enable, 0);
2855 ngx_conf_merge_value(conf->silent_errors, prev->silent_errors, 0); 2786 ngx_conf_merge_value(conf->silent_errors, prev->silent_errors, 0);
2856 ngx_conf_merge_value(conf->ignore_recycled_buffers, 2787 ngx_conf_merge_value(conf->ignore_recycled_buffers,
2857 prev->ignore_recycled_buffers, 0); 2788 prev->ignore_recycled_buffers, 0);
2858 2789
2859 ngx_conf_merge_size_value(conf->min_file_chunk, prev->min_file_chunk, 1024); 2790 ngx_conf_merge_size_value(conf->min_file_chunk, prev->min_file_chunk, 1024);
2860 ngx_conf_merge_size_value(conf->value_len, prev->value_len, 256); 2791 ngx_conf_merge_size_value(conf->value_len, prev->value_len, 256);
2861 2792
2862 if (conf->types == NULL) { 2793 if (ngx_http_merge_types(cf, conf->types_keys, &conf->types,
2863 if (prev->types == NULL) { 2794 prev->types_keys, &prev->types,
2864 conf->types = ngx_array_create(cf->pool, 1, sizeof(ngx_str_t)); 2795 ngx_http_html_default_types)
2865 if (conf->types == NULL) { 2796 != NGX_OK)
2866 return NGX_CONF_ERROR; 2797 {
2867 } 2798 return NGX_CONF_ERROR;
2868
2869 type = ngx_array_push(conf->types);
2870 if (type == NULL) {
2871 return NGX_CONF_ERROR;
2872 }
2873
2874 type->len = sizeof("text/html") - 1;
2875 type->data = (u_char *) "text/html";
2876
2877 } else {
2878 conf->types = prev->types;
2879 }
2880 } 2799 }
2881 2800
2882 return NGX_CONF_OK; 2801 return NGX_CONF_OK;
2883 } 2802 }
2884 2803