Mercurial > hg > nginx-quic
comparison src/http/modules/ngx_http_gzip_filter.c @ 356:2e3cbc1bbe3c
nginx-0.0.7-2004-06-16-19:32:11 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 16 Jun 2004 15:32:11 +0000 |
parents | 0fb6c53fb135 |
children | 54f76b0b8dca |
comparison
equal
deleted
inserted
replaced
355:0fb6c53fb135 | 356:2e3cbc1bbe3c |
---|---|
62 z_stream zstream; | 62 z_stream zstream; |
63 ngx_http_request_t *request; | 63 ngx_http_request_t *request; |
64 } ngx_http_gzip_ctx_t; | 64 } ngx_http_gzip_ctx_t; |
65 | 65 |
66 | 66 |
67 static int ngx_http_gzip_proxied(ngx_http_request_t *r, | 67 static ngx_int_t ngx_http_gzip_proxied(ngx_http_request_t *r, |
68 ngx_http_gzip_conf_t *conf); | 68 ngx_http_gzip_conf_t *conf); |
69 static void *ngx_http_gzip_filter_alloc(void *opaque, u_int items, | 69 static void *ngx_http_gzip_filter_alloc(void *opaque, u_int items, |
70 u_int size); | 70 u_int size); |
71 static void ngx_http_gzip_filter_free(void *opaque, void *address); | 71 static void ngx_http_gzip_filter_free(void *opaque, void *address); |
72 ngx_inline static int ngx_http_gzip_error(ngx_http_gzip_ctx_t *ctx); | 72 ngx_inline static int ngx_http_gzip_error(ngx_http_gzip_ctx_t *ctx); |
73 | 73 |
74 static u_char *ngx_http_gzip_log_ratio(ngx_http_request_t *r, u_char *buf, | 74 static u_char *ngx_http_gzip_log_ratio(ngx_http_request_t *r, u_char *buf, |
75 uintptr_t data); | 75 uintptr_t data); |
76 | 76 |
77 static int ngx_http_gzip_pre_conf(ngx_conf_t *cf); | 77 static ngx_int_t ngx_http_gzip_pre_conf(ngx_conf_t *cf); |
78 static int ngx_http_gzip_filter_init(ngx_cycle_t *cycle); | 78 static ngx_int_t ngx_http_gzip_filter_init(ngx_cycle_t *cycle); |
79 static void *ngx_http_gzip_create_conf(ngx_conf_t *cf); | 79 static void *ngx_http_gzip_create_conf(ngx_conf_t *cf); |
80 static char *ngx_http_gzip_merge_conf(ngx_conf_t *cf, | 80 static char *ngx_http_gzip_merge_conf(ngx_conf_t *cf, |
81 void *parent, void *child); | 81 void *parent, void *child); |
82 static char *ngx_http_gzip_set_window(ngx_conf_t *cf, void *post, void *data); | 82 static char *ngx_http_gzip_set_window(ngx_conf_t *cf, void *post, void *data); |
83 static char *ngx_http_gzip_set_hash(ngx_conf_t *cf, void *post, void *data); | 83 static char *ngx_http_gzip_set_hash(ngx_conf_t *cf, void *post, void *data); |
236 | 236 |
237 static ngx_http_output_header_filter_pt ngx_http_next_header_filter; | 237 static ngx_http_output_header_filter_pt ngx_http_next_header_filter; |
238 static ngx_http_output_body_filter_pt ngx_http_next_body_filter; | 238 static ngx_http_output_body_filter_pt ngx_http_next_body_filter; |
239 | 239 |
240 | 240 |
241 static int ngx_http_gzip_header_filter(ngx_http_request_t *r) | 241 static ngx_int_t ngx_http_gzip_header_filter(ngx_http_request_t *r) |
242 { | 242 { |
243 ngx_http_gzip_ctx_t *ctx; | 243 ngx_http_gzip_ctx_t *ctx; |
244 ngx_http_gzip_conf_t *conf; | 244 ngx_http_gzip_conf_t *conf; |
245 | 245 |
246 conf = ngx_http_get_module_loc_conf(r, ngx_http_gzip_filter_module); | 246 conf = ngx_http_get_module_loc_conf(r, ngx_http_gzip_filter_module); |
286 * if the URL (without the "http://" prefix) is longer than 253 bytes | 286 * if the URL (without the "http://" prefix) is longer than 253 bytes |
287 * then MSIE 4.x can not handle the compressed stream - it waits too long, | 287 * then MSIE 4.x can not handle the compressed stream - it waits too long, |
288 * hangs up or crashes | 288 * hangs up or crashes |
289 */ | 289 */ |
290 | 290 |
291 if (r->headers_in.user_agent | 291 if (r->headers_in.msie4 && r->unparsed_uri.len > 200) { |
292 && r->unparsed_uri.len > 200 | |
293 && ngx_strstr(r->headers_in.user_agent->value.data, "MSIE 4")) | |
294 { | |
295 return ngx_http_next_header_filter(r); | 292 return ngx_http_next_header_filter(r); |
296 } | 293 } |
297 | 294 |
298 | 295 |
299 ngx_http_create_ctx(r, ctx, ngx_http_gzip_filter_module, | 296 ngx_http_create_ctx(r, ctx, ngx_http_gzip_filter_module, |
321 | 318 |
322 return ngx_http_next_header_filter(r); | 319 return ngx_http_next_header_filter(r); |
323 } | 320 } |
324 | 321 |
325 | 322 |
326 static int ngx_http_gzip_proxied(ngx_http_request_t *r, | 323 static ngx_int_t ngx_http_gzip_proxied(ngx_http_request_t *r, |
327 ngx_http_gzip_conf_t *conf) | 324 ngx_http_gzip_conf_t *conf) |
328 { | 325 { |
329 time_t date, expires; | 326 time_t date, expires; |
330 | 327 |
331 if (r->headers_in.authorization | 328 if (r->headers_in.authorization |
332 && (conf->proxied & NGX_HTTP_GZIP_PROXIED_AUTH)) | 329 && (conf->proxied & NGX_HTTP_GZIP_PROXIED_AUTH)) |
401 | 398 |
402 return NGX_OK; | 399 return NGX_OK; |
403 } | 400 } |
404 | 401 |
405 | 402 |
406 static int ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in) | 403 static ngx_int_t ngx_http_gzip_body_filter(ngx_http_request_t *r, |
404 ngx_chain_t *in) | |
407 { | 405 { |
408 int rc, wbits, memlevel, last; | 406 int rc, wbits, memlevel, last; |
409 struct gztrailer *trailer; | 407 struct gztrailer *trailer; |
410 ngx_buf_t *b; | 408 ngx_buf_t *b; |
411 ngx_chain_t *cl; | 409 ngx_chain_t *cl; |
817 zfrac = 0; | 815 zfrac = 0; |
818 } | 816 } |
819 } | 817 } |
820 | 818 |
821 return buf + ngx_snprintf((char *) buf, NGX_INT32_LEN + 4, | 819 return buf + ngx_snprintf((char *) buf, NGX_INT32_LEN + 4, |
822 "%d.%02d", zint, zfrac); | 820 "%" NGX_UINT_T_FMT ".%02" NGX_UINT_T_FMT, |
821 zint, zfrac); | |
823 } | 822 } |
824 | 823 |
825 | 824 |
826 ngx_inline static int ngx_http_gzip_error(ngx_http_gzip_ctx_t *ctx) | 825 ngx_inline static int ngx_http_gzip_error(ngx_http_gzip_ctx_t *ctx) |
827 { | 826 { |
836 | 835 |
837 return NGX_ERROR; | 836 return NGX_ERROR; |
838 } | 837 } |
839 | 838 |
840 | 839 |
841 static int ngx_http_gzip_pre_conf(ngx_conf_t *cf) | 840 static ngx_int_t ngx_http_gzip_pre_conf(ngx_conf_t *cf) |
842 { | 841 { |
843 ngx_http_log_op_name_t *op; | 842 ngx_http_log_op_name_t *op; |
844 | 843 |
845 for (op = ngx_http_gzip_log_fmt_ops; op->name.len; op++) { /* void */ } | 844 for (op = ngx_http_gzip_log_fmt_ops; op->name.len; op++) { /* void */ } |
846 op->op = NULL; | 845 op->op = NULL; |
857 | 856 |
858 return NGX_OK; | 857 return NGX_OK; |
859 } | 858 } |
860 | 859 |
861 | 860 |
862 static int ngx_http_gzip_filter_init(ngx_cycle_t *cycle) | 861 static ngx_int_t ngx_http_gzip_filter_init(ngx_cycle_t *cycle) |
863 { | 862 { |
864 ngx_http_next_header_filter = ngx_http_top_header_filter; | 863 ngx_http_next_header_filter = ngx_http_top_header_filter; |
865 ngx_http_top_header_filter = ngx_http_gzip_header_filter; | 864 ngx_http_top_header_filter = ngx_http_gzip_header_filter; |
866 | 865 |
867 ngx_http_next_body_filter = ngx_http_top_body_filter; | 866 ngx_http_next_body_filter = ngx_http_top_body_filter; |
892 | 891 |
893 | 892 |
894 conf->http_version = NGX_CONF_UNSET_UINT; | 893 conf->http_version = NGX_CONF_UNSET_UINT; |
895 | 894 |
896 conf->level = NGX_CONF_UNSET; | 895 conf->level = NGX_CONF_UNSET; |
897 conf->wbits = NGX_CONF_UNSET_UINT; | 896 conf->wbits = (size_t) NGX_CONF_UNSET; |
898 conf->memlevel = NGX_CONF_UNSET_UINT; | 897 conf->memlevel = (size_t) NGX_CONF_UNSET; |
899 conf->min_length = NGX_CONF_UNSET_UINT; | 898 conf->min_length = NGX_CONF_UNSET; |
900 | 899 |
901 return conf; | 900 return conf; |
902 } | 901 } |
903 | 902 |
904 | 903 |