Mercurial > hg > nginx-ranges
comparison src/http/modules/ngx_http_gzip_filter.c @ 46:9f3205d496a0 NGINX_0_1_23
nginx 0.1.23
*) Feature: the ngx_http_ssi_filter_module and the ssi,
ssi_silent_errors, and ssi_min_file_chunk directives. The 'echo
var="HTTP_..." default=""' and 'echo var="REMOTE_ADDR"' commands are
supported.
*) Feature: the %request_time log parameter.
*) Feature: if the request has no the "Host" header line, then the
"proxy_preserve_host" directive set this header line to the first
server name of the "server_name" directive.
*) Bugfix: nginx could not be built on platforms different from i386,
amd64, sparc и ppc; bug appeared in 0.1.22.
*) Bugfix: the ngx_http_autoindex_module now shows the information not
about the symlink, but about file or directory it points to.
*) Bugfix: the %apache_length parameter logged the negative length of
the response header if the no response was transferred to a client.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Tue, 01 Mar 2005 00:00:00 +0300 |
parents | 2879cd3a40cb |
children |
comparison
equal
deleted
inserted
replaced
45:09c688b472a7 | 46:9f3205d496a0 |
---|---|
74 ngx_http_request_t *request; | 74 ngx_http_request_t *request; |
75 } ngx_http_gzip_ctx_t; | 75 } ngx_http_gzip_ctx_t; |
76 | 76 |
77 | 77 |
78 static ngx_int_t ngx_http_gzip_proxied(ngx_http_request_t *r, | 78 static ngx_int_t ngx_http_gzip_proxied(ngx_http_request_t *r, |
79 ngx_http_gzip_conf_t *conf); | 79 ngx_http_gzip_conf_t *conf); |
80 static void *ngx_http_gzip_filter_alloc(void *opaque, u_int items, | 80 static void *ngx_http_gzip_filter_alloc(void *opaque, u_int items, |
81 u_int size); | 81 u_int size); |
82 static void ngx_http_gzip_filter_free(void *opaque, void *address); | 82 static void ngx_http_gzip_filter_free(void *opaque, void *address); |
83 static void ngx_http_gzip_error(ngx_http_gzip_ctx_t *ctx); | 83 static void ngx_http_gzip_error(ngx_http_gzip_ctx_t *ctx); |
84 | 84 |
85 static u_char *ngx_http_gzip_log_ratio(ngx_http_request_t *r, u_char *buf, | 85 static u_char *ngx_http_gzip_log_ratio(ngx_http_request_t *r, u_char *buf, |
86 ngx_http_log_op_t *op); | 86 ngx_http_log_op_t *op); |
87 | 87 |
88 static ngx_int_t ngx_http_gzip_add_log_formats(ngx_conf_t *cf); | 88 static ngx_int_t ngx_http_gzip_add_log_formats(ngx_conf_t *cf); |
89 | 89 |
90 static ngx_int_t ngx_http_gzip_filter_init(ngx_cycle_t *cycle); | 90 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); | 91 static void *ngx_http_gzip_create_conf(ngx_conf_t *cf); |
92 static char *ngx_http_gzip_merge_conf(ngx_conf_t *cf, | 92 static char *ngx_http_gzip_merge_conf(ngx_conf_t *cf, |
93 void *parent, void *child); | 93 void *parent, void *child); |
94 static char *ngx_http_gzip_set_types(ngx_conf_t *cf, ngx_command_t *cmd, | 94 static char *ngx_http_gzip_set_types(ngx_conf_t *cf, ngx_command_t *cmd, |
95 void *conf); | 95 void *conf); |
96 static char *ngx_http_gzip_set_window(ngx_conf_t *cf, void *post, void *data); | 96 static char *ngx_http_gzip_set_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); | 97 static char *ngx_http_gzip_set_hash(ngx_conf_t *cf, void *post, void *data); |
98 | 98 |
99 | 99 |
100 static ngx_conf_num_bounds_t ngx_http_gzip_comp_level_bounds = { | 100 static ngx_conf_num_bounds_t ngx_http_gzip_comp_level_bounds = { |
259 | 259 |
260 static ngx_http_output_header_filter_pt ngx_http_next_header_filter; | 260 static ngx_http_output_header_filter_pt ngx_http_next_header_filter; |
261 static ngx_http_output_body_filter_pt ngx_http_next_body_filter; | 261 static ngx_http_output_body_filter_pt ngx_http_next_body_filter; |
262 | 262 |
263 | 263 |
264 static ngx_int_t ngx_http_gzip_header_filter(ngx_http_request_t *r) | 264 static ngx_int_t |
265 ngx_http_gzip_header_filter(ngx_http_request_t *r) | |
265 { | 266 { |
266 ngx_uint_t i, found; | 267 ngx_uint_t i, found; |
267 ngx_http_gzip_ctx_t *ctx; | 268 ngx_http_gzip_ctx_t *ctx; |
268 ngx_http_gzip_conf_t *conf; | 269 ngx_http_gzip_conf_t *conf; |
269 ngx_http_gzip_type_t *type; | 270 ngx_http_gzip_type_t *type; |
355 | 356 |
356 return ngx_http_next_header_filter(r); | 357 return ngx_http_next_header_filter(r); |
357 } | 358 } |
358 | 359 |
359 | 360 |
360 static ngx_int_t ngx_http_gzip_proxied(ngx_http_request_t *r, | 361 static ngx_int_t |
361 ngx_http_gzip_conf_t *conf) | 362 ngx_http_gzip_proxied(ngx_http_request_t *r, ngx_http_gzip_conf_t *conf) |
362 { | 363 { |
363 time_t date, expires; | 364 time_t date, expires; |
364 | 365 |
365 if (r->headers_in.authorization | 366 if (r->headers_in.authorization |
366 && (conf->proxied & NGX_HTTP_GZIP_PROXIED_AUTH)) | 367 && (conf->proxied & NGX_HTTP_GZIP_PROXIED_AUTH)) |
435 | 436 |
436 return NGX_OK; | 437 return NGX_OK; |
437 } | 438 } |
438 | 439 |
439 | 440 |
440 static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r, | 441 static ngx_int_t |
441 ngx_chain_t *in) | 442 ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in) |
442 { | 443 { |
443 int rc, wbits, memlevel; | 444 int rc, wbits, memlevel; |
444 ngx_int_t last; | 445 ngx_int_t last; |
445 struct gztrailer *trailer; | 446 struct gztrailer *trailer; |
446 ngx_buf_t *b; | 447 ngx_buf_t *b; |
823 } | 824 } |
824 } | 825 } |
825 } | 826 } |
826 | 827 |
827 | 828 |
828 static void *ngx_http_gzip_filter_alloc(void *opaque, u_int items, u_int size) | 829 static void * |
830 ngx_http_gzip_filter_alloc(void *opaque, u_int items, u_int size) | |
829 { | 831 { |
830 ngx_http_gzip_ctx_t *ctx = opaque; | 832 ngx_http_gzip_ctx_t *ctx = opaque; |
831 | 833 |
832 void *p; | 834 void *p; |
833 ngx_uint_t alloc; | 835 ngx_uint_t alloc; |
864 | 866 |
865 return p; | 867 return p; |
866 } | 868 } |
867 | 869 |
868 | 870 |
869 static void ngx_http_gzip_filter_free(void *opaque, void *address) | 871 static void |
872 ngx_http_gzip_filter_free(void *opaque, void *address) | |
870 { | 873 { |
871 #if 0 | 874 #if 0 |
872 ngx_http_gzip_ctx_t *ctx = opaque; | 875 ngx_http_gzip_ctx_t *ctx = opaque; |
873 | 876 |
874 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ctx->request->connection->log, 0, | 877 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ctx->request->connection->log, 0, |
875 "gzip free: %p", address); | 878 "gzip free: %p", address); |
876 #endif | 879 #endif |
877 } | 880 } |
878 | 881 |
879 | 882 |
880 static u_char *ngx_http_gzip_log_ratio(ngx_http_request_t *r, u_char *buf, | 883 static u_char * |
881 ngx_http_log_op_t *op) | 884 ngx_http_gzip_log_ratio(ngx_http_request_t *r, u_char *buf, |
885 ngx_http_log_op_t *op) | |
882 { | 886 { |
883 ngx_uint_t zint, zfrac; | 887 ngx_uint_t zint, zfrac; |
884 ngx_http_gzip_ctx_t *ctx; | 888 ngx_http_gzip_ctx_t *ctx; |
885 | 889 |
886 ctx = ngx_http_get_module_ctx(r, ngx_http_gzip_filter_module); | 890 ctx = ngx_http_get_module_ctx(r, ngx_http_gzip_filter_module); |
907 | 911 |
908 return ngx_sprintf(buf, "%ui.%02ui", zint, zfrac); | 912 return ngx_sprintf(buf, "%ui.%02ui", zint, zfrac); |
909 } | 913 } |
910 | 914 |
911 | 915 |
912 static void ngx_http_gzip_error(ngx_http_gzip_ctx_t *ctx) | 916 static void |
917 ngx_http_gzip_error(ngx_http_gzip_ctx_t *ctx) | |
913 { | 918 { |
914 deflateEnd(&ctx->zstream); | 919 deflateEnd(&ctx->zstream); |
915 | 920 |
916 if (ctx->preallocated) { | 921 if (ctx->preallocated) { |
917 ngx_pfree(ctx->request->pool, ctx->preallocated); | 922 ngx_pfree(ctx->request->pool, ctx->preallocated); |
924 | 929 |
925 return; | 930 return; |
926 } | 931 } |
927 | 932 |
928 | 933 |
929 static ngx_int_t ngx_http_gzip_add_log_formats(ngx_conf_t *cf) | 934 static ngx_int_t |
935 ngx_http_gzip_add_log_formats(ngx_conf_t *cf) | |
930 { | 936 { |
931 ngx_http_log_op_name_t *op; | 937 ngx_http_log_op_name_t *op; |
932 | 938 |
933 for (op = ngx_http_gzip_log_fmt_ops; op->name.len; op++) { /* void */ } | 939 for (op = ngx_http_gzip_log_fmt_ops; op->name.len; op++) { /* void */ } |
934 op->run = NULL; | 940 op->run = NULL; |
943 | 949 |
944 return NGX_OK; | 950 return NGX_OK; |
945 } | 951 } |
946 | 952 |
947 | 953 |
948 static ngx_int_t ngx_http_gzip_filter_init(ngx_cycle_t *cycle) | 954 static ngx_int_t |
955 ngx_http_gzip_filter_init(ngx_cycle_t *cycle) | |
949 { | 956 { |
950 ngx_http_next_header_filter = ngx_http_top_header_filter; | 957 ngx_http_next_header_filter = ngx_http_top_header_filter; |
951 ngx_http_top_header_filter = ngx_http_gzip_header_filter; | 958 ngx_http_top_header_filter = ngx_http_gzip_header_filter; |
952 | 959 |
953 ngx_http_next_body_filter = ngx_http_top_body_filter; | 960 ngx_http_next_body_filter = ngx_http_top_body_filter; |
955 | 962 |
956 return NGX_OK; | 963 return NGX_OK; |
957 } | 964 } |
958 | 965 |
959 | 966 |
960 static void *ngx_http_gzip_create_conf(ngx_conf_t *cf) | 967 static void * |
968 ngx_http_gzip_create_conf(ngx_conf_t *cf) | |
961 { | 969 { |
962 ngx_http_gzip_conf_t *conf; | 970 ngx_http_gzip_conf_t *conf; |
963 | 971 |
964 if (!(conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_gzip_conf_t)))) { | 972 if (!(conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_gzip_conf_t)))) { |
965 return NGX_CONF_ERROR; | 973 return NGX_CONF_ERROR; |
985 | 993 |
986 return conf; | 994 return conf; |
987 } | 995 } |
988 | 996 |
989 | 997 |
990 static char *ngx_http_gzip_merge_conf(ngx_conf_t *cf, | 998 static char * |
991 void *parent, void *child) | 999 ngx_http_gzip_merge_conf(ngx_conf_t *cf, void *parent, void *child) |
992 { | 1000 { |
993 ngx_http_gzip_conf_t *prev = parent; | 1001 ngx_http_gzip_conf_t *prev = parent; |
994 ngx_http_gzip_conf_t *conf = child; | 1002 ngx_http_gzip_conf_t *conf = child; |
995 | 1003 |
996 ngx_http_gzip_type_t *type; | 1004 ngx_http_gzip_type_t *type; |
998 ngx_conf_merge_value(conf->enable, prev->enable, 0); | 1006 ngx_conf_merge_value(conf->enable, prev->enable, 0); |
999 | 1007 |
1000 ngx_conf_merge_bufs_value(conf->bufs, prev->bufs, 4, ngx_pagesize); | 1008 ngx_conf_merge_bufs_value(conf->bufs, prev->bufs, 4, ngx_pagesize); |
1001 | 1009 |
1002 ngx_conf_merge_unsigned_value(conf->http_version, prev->http_version, | 1010 ngx_conf_merge_unsigned_value(conf->http_version, prev->http_version, |
1003 NGX_HTTP_VERSION_11); | 1011 NGX_HTTP_VERSION_11); |
1004 ngx_conf_merge_bitmask_value(conf->proxied, prev->proxied, | 1012 ngx_conf_merge_bitmask_value(conf->proxied, prev->proxied, |
1005 (NGX_CONF_BITMASK_SET | 1013 (NGX_CONF_BITMASK_SET|NGX_HTTP_GZIP_PROXIED_OFF)); |
1006 |NGX_HTTP_GZIP_PROXIED_OFF)); | |
1007 | 1014 |
1008 ngx_conf_merge_value(conf->level, prev->level, 1); | 1015 ngx_conf_merge_value(conf->level, prev->level, 1); |
1009 ngx_conf_merge_size_value(conf->wbits, prev->wbits, MAX_WBITS); | 1016 ngx_conf_merge_size_value(conf->wbits, prev->wbits, MAX_WBITS); |
1010 ngx_conf_merge_size_value(conf->memlevel, prev->memlevel, | 1017 ngx_conf_merge_size_value(conf->memlevel, prev->memlevel, |
1011 MAX_MEM_LEVEL - 1); | 1018 MAX_MEM_LEVEL - 1); |
1035 | 1042 |
1036 return NGX_CONF_OK; | 1043 return NGX_CONF_OK; |
1037 } | 1044 } |
1038 | 1045 |
1039 | 1046 |
1040 static char *ngx_http_gzip_set_types(ngx_conf_t *cf, ngx_command_t *cmd, | 1047 static char * |
1041 void *conf) | 1048 ngx_http_gzip_set_types(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
1042 { | 1049 { |
1043 ngx_http_gzip_conf_t *gcf = conf; | 1050 ngx_http_gzip_conf_t *gcf = conf; |
1044 | 1051 |
1045 ngx_str_t *value; | 1052 ngx_str_t *value; |
1046 ngx_uint_t i; | 1053 ngx_uint_t i; |
1047 ngx_http_gzip_type_t *type; | 1054 ngx_http_gzip_type_t *type; |
1048 | 1055 |
1049 if (gcf->types == NULL) { | 1056 if (gcf->types == NULL) { |
1050 gcf->types = ngx_array_create(cf->pool, 5, | 1057 gcf->types = ngx_array_create(cf->pool, 4, |
1051 sizeof(ngx_http_gzip_type_t)); | 1058 sizeof(ngx_http_gzip_type_t)); |
1052 if (gcf->types == NULL) { | 1059 if (gcf->types == NULL) { |
1053 return NGX_CONF_ERROR; | 1060 return NGX_CONF_ERROR; |
1054 } | 1061 } |
1055 | 1062 |
1085 | 1092 |
1086 return NGX_CONF_OK; | 1093 return NGX_CONF_OK; |
1087 } | 1094 } |
1088 | 1095 |
1089 | 1096 |
1090 static char *ngx_http_gzip_set_window(ngx_conf_t *cf, void *post, void *data) | 1097 static char * |
1098 ngx_http_gzip_set_window(ngx_conf_t *cf, void *post, void *data) | |
1091 { | 1099 { |
1092 int *np = data; | 1100 int *np = data; |
1093 | 1101 |
1094 int wbits, wsize; | 1102 int wbits, wsize; |
1095 | 1103 |
1108 | 1116 |
1109 return "must be 512, 1k, 2k, 4k, 8k, 16k, or 32k"; | 1117 return "must be 512, 1k, 2k, 4k, 8k, 16k, or 32k"; |
1110 } | 1118 } |
1111 | 1119 |
1112 | 1120 |
1113 static char *ngx_http_gzip_set_hash(ngx_conf_t *cf, void *post, void *data) | 1121 static char * |
1122 ngx_http_gzip_set_hash(ngx_conf_t *cf, void *post, void *data) | |
1114 { | 1123 { |
1115 int *np = data; | 1124 int *np = data; |
1116 | 1125 |
1117 int memlevel, hsize; | 1126 int memlevel, hsize; |
1118 | 1127 |