annotate src/http/modules/ngx_http_gzip_filter_module.c @ 695:09a8f76a129b default tip

Added tag NGINX_1_3_10 for changeset 88a1b4797f2e
author Igor Sysoev <http://sysoev.ru>
date Tue, 25 Dec 2012 00:00:00 +0400
parents 88a1b4797f2e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2 /*
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
3 * Copyright (C) Igor Sysoev
660
d0f7a625f27c nginx 1.1.14
Igor Sysoev <http://sysoev.ru>
parents: 640
diff changeset
4 * Copyright (C) Nginx, Inc.
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
5 */
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
6
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
7
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
8 #include <ngx_config.h>
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
9 #include <ngx_core.h>
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
10 #include <ngx_http.h>
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
11
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
12 #include <zlib.h>
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
13
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
14
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
15 typedef struct {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
16 ngx_flag_t enable;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
17 ngx_flag_t no_buffer;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
18
394
05981f639d21 nginx 0.7.9
Igor Sysoev <http://sysoev.ru>
parents: 382
diff changeset
19 ngx_hash_t types;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
20
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
21 ngx_bufs_t bufs;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
22
454
a8424ffa495c nginx 0.7.39
Igor Sysoev <http://sysoev.ru>
parents: 440
diff changeset
23 size_t postpone_gzipping;
138
8e6d4d96ec4c nginx 0.3.16
Igor Sysoev <http://sysoev.ru>
parents: 132
diff changeset
24 ngx_int_t level;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
25 size_t wbits;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
26 size_t memlevel;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
27 ssize_t min_length;
394
05981f639d21 nginx 0.7.9
Igor Sysoev <http://sysoev.ru>
parents: 382
diff changeset
28
05981f639d21 nginx 0.7.9
Igor Sysoev <http://sysoev.ru>
parents: 382
diff changeset
29 ngx_array_t *types_keys;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
30 } ngx_http_gzip_conf_t;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
31
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
32
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
33 typedef struct {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
34 ngx_chain_t *in;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
35 ngx_chain_t *free;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
36 ngx_chain_t *busy;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
37 ngx_chain_t *out;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
38 ngx_chain_t **last_out;
432
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
39
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
40 ngx_chain_t *copied;
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
41 ngx_chain_t *copy_buf;
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
42
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
43 ngx_buf_t *in_buf;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
44 ngx_buf_t *out_buf;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
45 ngx_int_t bufs;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
46
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
47 void *preallocated;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
48 char *free_mem;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
49 ngx_uint_t allocated;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
50
432
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
51 int wbits;
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
52 int memlevel;
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
53
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
54 unsigned flush:4;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
55 unsigned redo:1;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
56 unsigned done:1;
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
57 unsigned nomem:1;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
58 unsigned gzheader:1;
432
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
59 unsigned buffering:1;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
60
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
61 size_t zin;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
62 size_t zout;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
63
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
64 uint32_t crc32;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
65 z_stream zstream;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
66 ngx_http_request_t *request;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
67 } ngx_http_gzip_ctx_t;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
68
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
69
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
70 #if (NGX_HAVE_LITTLE_ENDIAN && NGX_HAVE_NONALIGNED)
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
71
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
72 struct gztrailer {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
73 uint32_t crc32;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
74 uint32_t zlen;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
75 };
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
76
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
77 #else /* NGX_HAVE_BIG_ENDIAN || !NGX_HAVE_NONALIGNED */
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
78
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
79 struct gztrailer {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
80 u_char crc32[4];
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
81 u_char zlen[4];
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
82 };
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
83
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
84 #endif
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
85
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
86
432
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
87 static void ngx_http_gzip_filter_memory(ngx_http_request_t *r,
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
88 ngx_http_gzip_ctx_t *ctx);
454
a8424ffa495c nginx 0.7.39
Igor Sysoev <http://sysoev.ru>
parents: 440
diff changeset
89 static ngx_int_t ngx_http_gzip_filter_buffer(ngx_http_gzip_ctx_t *ctx,
432
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
90 ngx_chain_t *in);
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
91 static ngx_int_t ngx_http_gzip_filter_deflate_start(ngx_http_request_t *r,
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
92 ngx_http_gzip_ctx_t *ctx);
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
93 static ngx_int_t ngx_http_gzip_filter_gzheader(ngx_http_request_t *r,
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
94 ngx_http_gzip_ctx_t *ctx);
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
95 static ngx_int_t ngx_http_gzip_filter_add_data(ngx_http_request_t *r,
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
96 ngx_http_gzip_ctx_t *ctx);
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
97 static ngx_int_t ngx_http_gzip_filter_get_buf(ngx_http_request_t *r,
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
98 ngx_http_gzip_ctx_t *ctx);
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
99 static ngx_int_t ngx_http_gzip_filter_deflate(ngx_http_request_t *r,
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
100 ngx_http_gzip_ctx_t *ctx);
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
101 static ngx_int_t ngx_http_gzip_filter_deflate_end(ngx_http_request_t *r,
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
102 ngx_http_gzip_ctx_t *ctx);
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
103
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
104 static void *ngx_http_gzip_filter_alloc(void *opaque, u_int items,
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
105 u_int size);
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
106 static void ngx_http_gzip_filter_free(void *opaque, void *address);
432
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
107 static void ngx_http_gzip_filter_free_copy_buf(ngx_http_request_t *r,
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
108 ngx_http_gzip_ctx_t *ctx);
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
109
122
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
110 static ngx_int_t ngx_http_gzip_add_variables(ngx_conf_t *cf);
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
111 static ngx_int_t ngx_http_gzip_ratio_variable(ngx_http_request_t *r,
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
112 ngx_http_variable_value_t *v, uintptr_t data);
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
113
230
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 212
diff changeset
114 static ngx_int_t ngx_http_gzip_filter_init(ngx_conf_t *cf);
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
115 static void *ngx_http_gzip_create_conf(ngx_conf_t *cf);
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
116 static char *ngx_http_gzip_merge_conf(ngx_conf_t *cf,
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
117 void *parent, void *child);
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents: 62
diff changeset
118 static char *ngx_http_gzip_window(ngx_conf_t *cf, void *post, void *data);
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents: 62
diff changeset
119 static char *ngx_http_gzip_hash(ngx_conf_t *cf, void *post, void *data);
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
120
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
121
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
122 static ngx_conf_num_bounds_t ngx_http_gzip_comp_level_bounds = {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
123 ngx_conf_check_num_bounds, 1, 9
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
124 };
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
125
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents: 62
diff changeset
126 static ngx_conf_post_handler_pt ngx_http_gzip_window_p = ngx_http_gzip_window;
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents: 62
diff changeset
127 static ngx_conf_post_handler_pt ngx_http_gzip_hash_p = ngx_http_gzip_hash;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
128
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
129
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
130 static ngx_command_t ngx_http_gzip_filter_commands[] = {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
131
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
132 { ngx_string("gzip"),
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
133 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
134 |NGX_CONF_FLAG,
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
135 ngx_conf_set_flag_slot,
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
136 NGX_HTTP_LOC_CONF_OFFSET,
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
137 offsetof(ngx_http_gzip_conf_t, enable),
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
138 NULL },
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
139
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
140 { ngx_string("gzip_buffers"),
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
141 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2,
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
142 ngx_conf_set_bufs_slot,
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
143 NGX_HTTP_LOC_CONF_OFFSET,
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
144 offsetof(ngx_http_gzip_conf_t, bufs),
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
145 NULL },
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
146
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
147 { ngx_string("gzip_types"),
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
148 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
394
05981f639d21 nginx 0.7.9
Igor Sysoev <http://sysoev.ru>
parents: 382
diff changeset
149 ngx_http_types_slot,
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
150 NGX_HTTP_LOC_CONF_OFFSET,
394
05981f639d21 nginx 0.7.9
Igor Sysoev <http://sysoev.ru>
parents: 382
diff changeset
151 offsetof(ngx_http_gzip_conf_t, types_keys),
05981f639d21 nginx 0.7.9
Igor Sysoev <http://sysoev.ru>
parents: 382
diff changeset
152 &ngx_http_html_default_types[0] },
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
153
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
154 { ngx_string("gzip_comp_level"),
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
155 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
156 ngx_conf_set_num_slot,
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
157 NGX_HTTP_LOC_CONF_OFFSET,
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
158 offsetof(ngx_http_gzip_conf_t, level),
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
159 &ngx_http_gzip_comp_level_bounds },
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
160
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
161 { ngx_string("gzip_window"),
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
162 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
163 ngx_conf_set_size_slot,
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
164 NGX_HTTP_LOC_CONF_OFFSET,
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
165 offsetof(ngx_http_gzip_conf_t, wbits),
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents: 62
diff changeset
166 &ngx_http_gzip_window_p },
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
167
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
168 { ngx_string("gzip_hash"),
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
169 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
170 ngx_conf_set_size_slot,
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
171 NGX_HTTP_LOC_CONF_OFFSET,
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
172 offsetof(ngx_http_gzip_conf_t, memlevel),
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents: 62
diff changeset
173 &ngx_http_gzip_hash_p },
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
174
454
a8424ffa495c nginx 0.7.39
Igor Sysoev <http://sysoev.ru>
parents: 440
diff changeset
175 { ngx_string("postpone_gzipping"),
a8424ffa495c nginx 0.7.39
Igor Sysoev <http://sysoev.ru>
parents: 440
diff changeset
176 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
a8424ffa495c nginx 0.7.39
Igor Sysoev <http://sysoev.ru>
parents: 440
diff changeset
177 ngx_conf_set_size_slot,
a8424ffa495c nginx 0.7.39
Igor Sysoev <http://sysoev.ru>
parents: 440
diff changeset
178 NGX_HTTP_LOC_CONF_OFFSET,
a8424ffa495c nginx 0.7.39
Igor Sysoev <http://sysoev.ru>
parents: 440
diff changeset
179 offsetof(ngx_http_gzip_conf_t, postpone_gzipping),
a8424ffa495c nginx 0.7.39
Igor Sysoev <http://sysoev.ru>
parents: 440
diff changeset
180 NULL },
a8424ffa495c nginx 0.7.39
Igor Sysoev <http://sysoev.ru>
parents: 440
diff changeset
181
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
182 { ngx_string("gzip_no_buffer"),
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
183 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
184 ngx_conf_set_flag_slot,
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
185 NGX_HTTP_LOC_CONF_OFFSET,
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
186 offsetof(ngx_http_gzip_conf_t, no_buffer),
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
187 NULL },
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
188
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
189 { ngx_string("gzip_min_length"),
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
190 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
191 ngx_conf_set_size_slot,
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
192 NGX_HTTP_LOC_CONF_OFFSET,
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
193 offsetof(ngx_http_gzip_conf_t, min_length),
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
194 NULL },
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
195
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
196 ngx_null_command
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
197 };
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
198
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
199
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
200 static ngx_http_module_t ngx_http_gzip_filter_module_ctx = {
122
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
201 ngx_http_gzip_add_variables, /* preconfiguration */
230
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 212
diff changeset
202 ngx_http_gzip_filter_init, /* postconfiguration */
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
203
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
204 NULL, /* create main configuration */
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
205 NULL, /* init main configuration */
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
206
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
207 NULL, /* create server configuration */
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
208 NULL, /* merge server configuration */
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
209
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
210 ngx_http_gzip_create_conf, /* create location configuration */
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
211 ngx_http_gzip_merge_conf /* merge location configuration */
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
212 };
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
213
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
214
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
215 ngx_module_t ngx_http_gzip_filter_module = {
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
216 NGX_MODULE_V1,
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
217 &ngx_http_gzip_filter_module_ctx, /* module context */
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
218 ngx_http_gzip_filter_commands, /* module directives */
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
219 NGX_HTTP_MODULE, /* module type */
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
220 NULL, /* init master */
230
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 212
diff changeset
221 NULL, /* init module */
90
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
222 NULL, /* init process */
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
223 NULL, /* init thread */
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
224 NULL, /* exit thread */
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
225 NULL, /* exit process */
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
226 NULL, /* exit master */
71c46860eb55 nginx 0.1.45
Igor Sysoev <http://sysoev.ru>
parents: 78
diff changeset
227 NGX_MODULE_V1_PADDING
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
228 };
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
229
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
230
122
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
231 static ngx_str_t ngx_http_gzip_ratio = ngx_string("gzip_ratio");
58
b55cbf18157e nginx 0.1.29
Igor Sysoev <http://sysoev.ru>
parents: 50
diff changeset
232
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
233 static ngx_http_output_header_filter_pt ngx_http_next_header_filter;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
234 static ngx_http_output_body_filter_pt ngx_http_next_body_filter;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
235
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
236
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
237 static ngx_int_t
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
238 ngx_http_gzip_header_filter(ngx_http_request_t *r)
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
239 {
382
984bb0b1399b nginx 0.7.3
Igor Sysoev <http://sysoev.ru>
parents: 358
diff changeset
240 ngx_table_elt_t *h;
984bb0b1399b nginx 0.7.3
Igor Sysoev <http://sysoev.ru>
parents: 358
diff changeset
241 ngx_http_gzip_ctx_t *ctx;
984bb0b1399b nginx 0.7.3
Igor Sysoev <http://sysoev.ru>
parents: 358
diff changeset
242 ngx_http_gzip_conf_t *conf;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
243
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
244 conf = ngx_http_get_module_loc_conf(r, ngx_http_gzip_filter_module);
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
245
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
246 if (!conf->enable
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
247 || (r->headers_out.status != NGX_HTTP_OK
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
248 && r->headers_out.status != NGX_HTTP_FORBIDDEN
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
249 && r->headers_out.status != NGX_HTTP_NOT_FOUND)
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
250 || (r->headers_out.content_encoding
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
251 && r->headers_out.content_encoding->value.len)
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
252 || (r->headers_out.content_length_n != -1
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
253 && r->headers_out.content_length_n < conf->min_length)
556
25255878df91 nginx 0.8.30
Igor Sysoev <http://sysoev.ru>
parents: 554
diff changeset
254 || ngx_http_test_content_type(r, &conf->types) == NULL
25255878df91 nginx 0.8.30
Igor Sysoev <http://sysoev.ru>
parents: 554
diff changeset
255 || r->header_only)
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
256 {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
257 return ngx_http_next_header_filter(r);
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
258 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
259
546
e19e5f542878 nginx 0.8.25
Igor Sysoev <http://sysoev.ru>
parents: 496
diff changeset
260 r->gzip_vary = 1;
e19e5f542878 nginx 0.8.25
Igor Sysoev <http://sysoev.ru>
parents: 496
diff changeset
261
602
c5122335e41d nginx 0.8.53
Igor Sysoev <http://sysoev.ru>
parents: 570
diff changeset
262 #if (NGX_HTTP_DEGRADATION)
c5122335e41d nginx 0.8.53
Igor Sysoev <http://sysoev.ru>
parents: 570
diff changeset
263 {
c5122335e41d nginx 0.8.53
Igor Sysoev <http://sysoev.ru>
parents: 570
diff changeset
264 ngx_http_core_loc_conf_t *clcf;
c5122335e41d nginx 0.8.53
Igor Sysoev <http://sysoev.ru>
parents: 570
diff changeset
265
c5122335e41d nginx 0.8.53
Igor Sysoev <http://sysoev.ru>
parents: 570
diff changeset
266 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
c5122335e41d nginx 0.8.53
Igor Sysoev <http://sysoev.ru>
parents: 570
diff changeset
267
c5122335e41d nginx 0.8.53
Igor Sysoev <http://sysoev.ru>
parents: 570
diff changeset
268 if (clcf->gzip_disable_degradation && ngx_http_degraded(r)) {
c5122335e41d nginx 0.8.53
Igor Sysoev <http://sysoev.ru>
parents: 570
diff changeset
269 return ngx_http_next_header_filter(r);
c5122335e41d nginx 0.8.53
Igor Sysoev <http://sysoev.ru>
parents: 570
diff changeset
270 }
c5122335e41d nginx 0.8.53
Igor Sysoev <http://sysoev.ru>
parents: 570
diff changeset
271 }
c5122335e41d nginx 0.8.53
Igor Sysoev <http://sysoev.ru>
parents: 570
diff changeset
272 #endif
c5122335e41d nginx 0.8.53
Igor Sysoev <http://sysoev.ru>
parents: 570
diff changeset
273
546
e19e5f542878 nginx 0.8.25
Igor Sysoev <http://sysoev.ru>
parents: 496
diff changeset
274 if (!r->gzip_tested) {
e19e5f542878 nginx 0.8.25
Igor Sysoev <http://sysoev.ru>
parents: 496
diff changeset
275 if (ngx_http_gzip_ok(r) != NGX_OK) {
e19e5f542878 nginx 0.8.25
Igor Sysoev <http://sysoev.ru>
parents: 496
diff changeset
276 return ngx_http_next_header_filter(r);
e19e5f542878 nginx 0.8.25
Igor Sysoev <http://sysoev.ru>
parents: 496
diff changeset
277 }
e19e5f542878 nginx 0.8.25
Igor Sysoev <http://sysoev.ru>
parents: 496
diff changeset
278
e19e5f542878 nginx 0.8.25
Igor Sysoev <http://sysoev.ru>
parents: 496
diff changeset
279 } else if (!r->gzip_ok) {
e19e5f542878 nginx 0.8.25
Igor Sysoev <http://sysoev.ru>
parents: 496
diff changeset
280 return ngx_http_next_header_filter(r);
e19e5f542878 nginx 0.8.25
Igor Sysoev <http://sysoev.ru>
parents: 496
diff changeset
281 }
e19e5f542878 nginx 0.8.25
Igor Sysoev <http://sysoev.ru>
parents: 496
diff changeset
282
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
283 ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_gzip_ctx_t));
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
284 if (ctx == NULL) {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
285 return NGX_ERROR;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
286 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
287
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
288 ngx_http_set_ctx(r, ctx, ngx_http_gzip_filter_module);
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
289
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
290 ctx->request = r;
454
a8424ffa495c nginx 0.7.39
Igor Sysoev <http://sysoev.ru>
parents: 440
diff changeset
291 ctx->buffering = (conf->postpone_gzipping != 0);
432
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
292
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
293 ngx_http_gzip_filter_memory(r, ctx);
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
294
358
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents: 346
diff changeset
295 h = ngx_list_push(&r->headers_out.headers);
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents: 346
diff changeset
296 if (h == NULL) {
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
297 return NGX_ERROR;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
298 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
299
358
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents: 346
diff changeset
300 h->hash = 1;
570
8246d8a2c2be nginx 0.8.37
Igor Sysoev <http://sysoev.ru>
parents: 556
diff changeset
301 ngx_str_set(&h->key, "Content-Encoding");
8246d8a2c2be nginx 0.8.37
Igor Sysoev <http://sysoev.ru>
parents: 556
diff changeset
302 ngx_str_set(&h->value, "gzip");
358
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents: 346
diff changeset
303 r->headers_out.content_encoding = h;
9121a0a91f47 nginx 0.6.23
Igor Sysoev <http://sysoev.ru>
parents: 346
diff changeset
304
62
0790a8599248 nginx 0.1.31
Igor Sysoev <http://sysoev.ru>
parents: 58
diff changeset
305 r->main_filter_need_in_memory = 1;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
306
126
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 122
diff changeset
307 ngx_http_clear_content_length(r);
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 122
diff changeset
308 ngx_http_clear_accept_ranges(r);
680
597573166f34 nginx 1.3.3
Igor Sysoev <http://sysoev.ru>
parents: 662
diff changeset
309 ngx_http_clear_etag(r);
126
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 122
diff changeset
310
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
311 return ngx_http_next_header_filter(r);
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
312 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
313
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
314
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
315 static ngx_int_t
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
316 ngx_http_gzip_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
317 {
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
318 int rc;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
319 ngx_chain_t *cl;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
320 ngx_http_gzip_ctx_t *ctx;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
321
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
322 ctx = ngx_http_get_module_ctx(r, ngx_http_gzip_filter_module);
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
323
694
88a1b4797f2e nginx 1.3.10
Igor Sysoev <http://sysoev.ru>
parents: 680
diff changeset
324 if (ctx == NULL || ctx->done || r->header_only) {
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
325 return ngx_http_next_body_filter(r, in);
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
326 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
327
432
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
328 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
329 "http gzip filter");
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
330
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
331 if (ctx->buffering) {
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
332
454
a8424ffa495c nginx 0.7.39
Igor Sysoev <http://sysoev.ru>
parents: 440
diff changeset
333 /*
a8424ffa495c nginx 0.7.39
Igor Sysoev <http://sysoev.ru>
parents: 440
diff changeset
334 * With default memory settings zlib starts to output gzipped data
a8424ffa495c nginx 0.7.39
Igor Sysoev <http://sysoev.ru>
parents: 440
diff changeset
335 * only after it has got about 90K, so it makes sense to allocate
a8424ffa495c nginx 0.7.39
Igor Sysoev <http://sysoev.ru>
parents: 440
diff changeset
336 * zlib memory (200-400K) only after we have enough data to compress.
a8424ffa495c nginx 0.7.39
Igor Sysoev <http://sysoev.ru>
parents: 440
diff changeset
337 * Although we copy buffers, nevertheless for not big responses
a8424ffa495c nginx 0.7.39
Igor Sysoev <http://sysoev.ru>
parents: 440
diff changeset
338 * this allows to allocate zlib memory, to compress and to output
a8424ffa495c nginx 0.7.39
Igor Sysoev <http://sysoev.ru>
parents: 440
diff changeset
339 * the response in one step using hot CPU cache.
a8424ffa495c nginx 0.7.39
Igor Sysoev <http://sysoev.ru>
parents: 440
diff changeset
340 */
a8424ffa495c nginx 0.7.39
Igor Sysoev <http://sysoev.ru>
parents: 440
diff changeset
341
432
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
342 if (in) {
454
a8424ffa495c nginx 0.7.39
Igor Sysoev <http://sysoev.ru>
parents: 440
diff changeset
343 switch (ngx_http_gzip_filter_buffer(ctx, in)) {
432
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
344
440
6281966854a5 nginx 0.7.32
Igor Sysoev <http://sysoev.ru>
parents: 434
diff changeset
345 case NGX_OK:
6281966854a5 nginx 0.7.32
Igor Sysoev <http://sysoev.ru>
parents: 434
diff changeset
346 return NGX_OK;
432
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
347
440
6281966854a5 nginx 0.7.32
Igor Sysoev <http://sysoev.ru>
parents: 434
diff changeset
348 case NGX_DONE:
6281966854a5 nginx 0.7.32
Igor Sysoev <http://sysoev.ru>
parents: 434
diff changeset
349 in = NULL;
6281966854a5 nginx 0.7.32
Igor Sysoev <http://sysoev.ru>
parents: 434
diff changeset
350 break;
432
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
351
440
6281966854a5 nginx 0.7.32
Igor Sysoev <http://sysoev.ru>
parents: 434
diff changeset
352 default: /* NGX_ERROR */
6281966854a5 nginx 0.7.32
Igor Sysoev <http://sysoev.ru>
parents: 434
diff changeset
353 goto failed;
6281966854a5 nginx 0.7.32
Igor Sysoev <http://sysoev.ru>
parents: 434
diff changeset
354 }
432
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
355
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
356 } else {
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
357 ctx->buffering = 0;
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
358 }
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
359 }
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
360
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
361 if (ctx->preallocated == NULL) {
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
362 if (ngx_http_gzip_filter_deflate_start(r, ctx) != NGX_OK) {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
363 goto failed;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
364 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
365 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
366
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
367 if (in) {
454
a8424ffa495c nginx 0.7.39
Igor Sysoev <http://sysoev.ru>
parents: 440
diff changeset
368 if (ngx_chain_add_copy(r->pool, &ctx->in, in) != NGX_OK) {
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
369 goto failed;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
370 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
371 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
372
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
373 if (ctx->nomem) {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
374
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
375 /* flush busy buffers */
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
376
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
377 if (ngx_http_next_body_filter(r, NULL) == NGX_ERROR) {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
378 goto failed;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
379 }
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
380
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
381 cl = NULL;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
382
640
eb208e0cf44d nginx 1.1.4
Igor Sysoev <http://sysoev.ru>
parents: 602
diff changeset
383 ngx_chain_update_chains(r->pool, &ctx->free, &ctx->busy, &cl,
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
384 (ngx_buf_tag_t) &ngx_http_gzip_filter_module);
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
385 ctx->nomem = 0;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
386 }
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
387
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
388 for ( ;; ) {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
389
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
390 /* cycle while we can write to a client */
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
391
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
392 for ( ;; ) {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
393
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
394 /* cycle while there is data to feed zlib and ... */
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
395
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
396 rc = ngx_http_gzip_filter_add_data(r, ctx);
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
397
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
398 if (rc == NGX_DECLINED) {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
399 break;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
400 }
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
401
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
402 if (rc == NGX_AGAIN) {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
403 continue;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
404 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
405
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
406
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
407 /* ... there are buffers to write zlib output */
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
408
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
409 rc = ngx_http_gzip_filter_get_buf(r, ctx);
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
410
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
411 if (rc == NGX_DECLINED) {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
412 break;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
413 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
414
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
415 if (rc == NGX_ERROR) {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
416 goto failed;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
417 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
418
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
419
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
420 rc = ngx_http_gzip_filter_deflate(r, ctx);
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
421
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
422 if (rc == NGX_OK) {
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
423 break;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
424 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
425
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
426 if (rc == NGX_ERROR) {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
427 goto failed;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
428 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
429
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
430 /* rc == NGX_AGAIN */
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
431 }
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
432
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
433 if (ctx->out == NULL) {
432
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
434 ngx_http_gzip_filter_free_copy_buf(r, ctx);
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
435
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
436 return ctx->busy ? NGX_AGAIN : NGX_OK;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
437 }
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
438
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
439 if (!ctx->gzheader) {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
440 if (ngx_http_gzip_filter_gzheader(r, ctx) != NGX_OK) {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
441 goto failed;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
442 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
443 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
444
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
445 rc = ngx_http_next_body_filter(r, ctx->out);
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
446
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
447 if (rc == NGX_ERROR) {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
448 goto failed;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
449 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
450
432
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
451 ngx_http_gzip_filter_free_copy_buf(r, ctx);
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
452
640
eb208e0cf44d nginx 1.1.4
Igor Sysoev <http://sysoev.ru>
parents: 602
diff changeset
453 ngx_chain_update_chains(r->pool, &ctx->free, &ctx->busy, &ctx->out,
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
454 (ngx_buf_tag_t) &ngx_http_gzip_filter_module);
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
455 ctx->last_out = &ctx->out;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
456
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
457 ctx->nomem = 0;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
458
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
459 if (ctx->done) {
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
460 return rc;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
461 }
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
462 }
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
463
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
464 /* unreachable */
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
465
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
466 failed:
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
467
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
468 ctx->done = 1;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
469
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
470 if (ctx->preallocated) {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
471 deflateEnd(&ctx->zstream);
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
472
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
473 ngx_pfree(r->pool, ctx->preallocated);
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
474 }
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
475
432
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
476 ngx_http_gzip_filter_free_copy_buf(r, ctx);
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
477
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
478 return NGX_ERROR;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
479 }
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
480
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
481
432
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
482 static void
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
483 ngx_http_gzip_filter_memory(ngx_http_request_t *r, ngx_http_gzip_ctx_t *ctx)
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
484 {
432
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
485 int wbits, memlevel;
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
486 ngx_http_gzip_conf_t *conf;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
487
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
488 conf = ngx_http_get_module_loc_conf(r, ngx_http_gzip_filter_module);
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
489
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
490 wbits = conf->wbits;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
491 memlevel = conf->memlevel;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
492
432
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
493 if (r->headers_out.content_length_n > 0) {
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
494
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
495 /* the actual zlib window size is smaller by 262 bytes */
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
496
432
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
497 while (r->headers_out.content_length_n < ((1 << (wbits - 1)) - 262)) {
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
498 wbits--;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
499 memlevel--;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
500 }
694
88a1b4797f2e nginx 1.3.10
Igor Sysoev <http://sysoev.ru>
parents: 680
diff changeset
501
88a1b4797f2e nginx 1.3.10
Igor Sysoev <http://sysoev.ru>
parents: 680
diff changeset
502 if (memlevel < 1) {
88a1b4797f2e nginx 1.3.10
Igor Sysoev <http://sysoev.ru>
parents: 680
diff changeset
503 memlevel = 1;
88a1b4797f2e nginx 1.3.10
Igor Sysoev <http://sysoev.ru>
parents: 680
diff changeset
504 }
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
505 }
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
506
432
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
507 ctx->wbits = wbits;
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
508 ctx->memlevel = memlevel;
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
509
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
510 /*
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
511 * We preallocate a memory for zlib in one buffer (200K-400K), this
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
512 * decreases a number of malloc() and free() calls and also probably
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
513 * decreases a number of syscalls (sbrk()/mmap() and so on).
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
514 * Besides we free the memory as soon as a gzipping will complete
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
515 * and do not wait while a whole response will be sent to a client.
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
516 *
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
517 * 8K is for zlib deflate_state, it takes
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
518 * *) 5816 bytes on i386 and sparc64 (32-bit mode)
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
519 * *) 5920 bytes on amd64 and sparc64
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
520 */
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
521
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
522 ctx->allocated = 8192 + (1 << (wbits + 2)) + (1 << (memlevel + 9));
432
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
523 }
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
524
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
525
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
526 static ngx_int_t
454
a8424ffa495c nginx 0.7.39
Igor Sysoev <http://sysoev.ru>
parents: 440
diff changeset
527 ngx_http_gzip_filter_buffer(ngx_http_gzip_ctx_t *ctx, ngx_chain_t *in)
432
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
528 {
454
a8424ffa495c nginx 0.7.39
Igor Sysoev <http://sysoev.ru>
parents: 440
diff changeset
529 size_t size, buffered;
a8424ffa495c nginx 0.7.39
Igor Sysoev <http://sysoev.ru>
parents: 440
diff changeset
530 ngx_buf_t *b, *buf;
a8424ffa495c nginx 0.7.39
Igor Sysoev <http://sysoev.ru>
parents: 440
diff changeset
531 ngx_chain_t *cl, **ll;
a8424ffa495c nginx 0.7.39
Igor Sysoev <http://sysoev.ru>
parents: 440
diff changeset
532 ngx_http_request_t *r;
a8424ffa495c nginx 0.7.39
Igor Sysoev <http://sysoev.ru>
parents: 440
diff changeset
533 ngx_http_gzip_conf_t *conf;
432
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
534
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
535 r = ctx->request;
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
536
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
537 r->connection->buffered |= NGX_HTTP_GZIP_BUFFERED;
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
538
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
539 buffered = 0;
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
540 ll = &ctx->in;
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
541
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
542 for (cl = ctx->in; cl; cl = cl->next) {
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
543 buffered += cl->buf->last - cl->buf->pos;
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
544 ll = &cl->next;
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
545 }
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
546
454
a8424ffa495c nginx 0.7.39
Igor Sysoev <http://sysoev.ru>
parents: 440
diff changeset
547 conf = ngx_http_get_module_loc_conf(r, ngx_http_gzip_filter_module);
a8424ffa495c nginx 0.7.39
Igor Sysoev <http://sysoev.ru>
parents: 440
diff changeset
548
432
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
549 while (in) {
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
550 cl = ngx_alloc_chain_link(r->pool);
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
551 if (cl == NULL) {
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
552 return NGX_ERROR;
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
553 }
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
554
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
555 b = in->buf;
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
556
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
557 size = b->last - b->pos;
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
558 buffered += size;
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
559
454
a8424ffa495c nginx 0.7.39
Igor Sysoev <http://sysoev.ru>
parents: 440
diff changeset
560 if (b->flush || b->last_buf || buffered > conf->postpone_gzipping) {
432
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
561 ctx->buffering = 0;
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
562 }
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
563
454
a8424ffa495c nginx 0.7.39
Igor Sysoev <http://sysoev.ru>
parents: 440
diff changeset
564 if (ctx->buffering && size) {
432
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
565
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
566 buf = ngx_create_temp_buf(r->pool, size);
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
567 if (buf == NULL) {
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
568 return NGX_ERROR;
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
569 }
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
570
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
571 buf->last = ngx_cpymem(buf->pos, b->pos, size);
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
572 b->pos = b->last;
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
573
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
574 buf->last_buf = b->last_buf;
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
575 buf->tag = (ngx_buf_tag_t) &ngx_http_gzip_filter_module;
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
576
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
577 cl->buf = buf;
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
578
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
579 } else {
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
580 cl->buf = b;
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
581 }
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
582
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
583 *ll = cl;
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
584 ll = &cl->next;
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
585 in = in->next;
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
586 }
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
587
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
588 *ll = NULL;
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
589
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
590 return ctx->buffering ? NGX_OK : NGX_DONE;
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
591 }
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
592
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
593
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
594 static ngx_int_t
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
595 ngx_http_gzip_filter_deflate_start(ngx_http_request_t *r,
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
596 ngx_http_gzip_ctx_t *ctx)
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
597 {
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
598 int rc;
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
599 ngx_http_gzip_conf_t *conf;
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
600
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
601 conf = ngx_http_get_module_loc_conf(r, ngx_http_gzip_filter_module);
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
602
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
603 ctx->preallocated = ngx_palloc(r->pool, ctx->allocated);
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
604 if (ctx->preallocated == NULL) {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
605 return NGX_ERROR;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
606 }
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
607
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
608 ctx->free_mem = ctx->preallocated;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
609
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
610 ctx->zstream.zalloc = ngx_http_gzip_filter_alloc;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
611 ctx->zstream.zfree = ngx_http_gzip_filter_free;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
612 ctx->zstream.opaque = ctx;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
613
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
614 rc = deflateInit2(&ctx->zstream, (int) conf->level, Z_DEFLATED,
432
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
615 - ctx->wbits, ctx->memlevel, Z_DEFAULT_STRATEGY);
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
616
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
617 if (rc != Z_OK) {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
618 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
619 "deflateInit2() failed: %d", rc);
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
620 return NGX_ERROR;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
621 }
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
622
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
623 ctx->last_out = &ctx->out;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
624 ctx->crc32 = crc32(0L, Z_NULL, 0);
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
625 ctx->flush = Z_NO_FLUSH;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
626
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
627 return NGX_OK;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
628 }
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
629
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
630
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
631 static ngx_int_t
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
632 ngx_http_gzip_filter_gzheader(ngx_http_request_t *r, ngx_http_gzip_ctx_t *ctx)
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
633 {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
634 ngx_buf_t *b;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
635 ngx_chain_t *cl;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
636 static u_char gzheader[10] =
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
637 { 0x1f, 0x8b, Z_DEFLATED, 0, 0, 0, 0, 0, 0, 3 };
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
638
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
639 b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t));
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
640 if (b == NULL) {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
641 return NGX_ERROR;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
642 }
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
643
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
644 b->memory = 1;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
645 b->pos = gzheader;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
646 b->last = b->pos + 10;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
647
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
648 cl = ngx_alloc_chain_link(r->pool);
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
649 if (cl == NULL) {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
650 return NGX_ERROR;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
651 }
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
652
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
653 cl->buf = b;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
654 cl->next = ctx->out;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
655 ctx->out = cl;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
656
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
657 ctx->gzheader = 1;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
658
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
659 return NGX_OK;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
660 }
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
661
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
662
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
663 static ngx_int_t
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
664 ngx_http_gzip_filter_add_data(ngx_http_request_t *r, ngx_http_gzip_ctx_t *ctx)
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
665 {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
666 if (ctx->zstream.avail_in || ctx->flush != Z_NO_FLUSH || ctx->redo) {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
667 return NGX_OK;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
668 }
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
669
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
670 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
671 "gzip in: %p", ctx->in);
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
672
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
673 if (ctx->in == NULL) {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
674 return NGX_DECLINED;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
675 }
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
676
432
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
677 if (ctx->copy_buf) {
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
678
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
679 /*
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
680 * to avoid CPU cache trashing we do not free() just quit buf,
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
681 * but postpone free()ing after zlib compressing and data output
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
682 */
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
683
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
684 ctx->copy_buf->next = ctx->copied;
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
685 ctx->copied = ctx->copy_buf;
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
686 ctx->copy_buf = NULL;
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
687 }
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
688
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
689 ctx->in_buf = ctx->in->buf;
432
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
690
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
691 if (ctx->in_buf->tag == (ngx_buf_tag_t) &ngx_http_gzip_filter_module) {
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
692 ctx->copy_buf = ctx->in;
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
693 }
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
694
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
695 ctx->in = ctx->in->next;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
696
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
697 ctx->zstream.next_in = ctx->in_buf->pos;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
698 ctx->zstream.avail_in = ctx->in_buf->last - ctx->in_buf->pos;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
699
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
700 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
701 "gzip in_buf:%p ni:%p ai:%ud",
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
702 ctx->in_buf,
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
703 ctx->zstream.next_in, ctx->zstream.avail_in);
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
704
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
705 if (ctx->in_buf->last_buf) {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
706 ctx->flush = Z_FINISH;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
707
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
708 } else if (ctx->in_buf->flush) {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
709 ctx->flush = Z_SYNC_FLUSH;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
710 }
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
711
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
712 if (ctx->zstream.avail_in) {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
713
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
714 ctx->crc32 = crc32(ctx->crc32, ctx->zstream.next_in,
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
715 ctx->zstream.avail_in);
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
716
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
717 } else if (ctx->flush == Z_NO_FLUSH) {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
718 return NGX_AGAIN;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
719 }
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
720
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
721 return NGX_OK;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
722 }
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
723
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
724
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
725 static ngx_int_t
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
726 ngx_http_gzip_filter_get_buf(ngx_http_request_t *r, ngx_http_gzip_ctx_t *ctx)
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
727 {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
728 ngx_http_gzip_conf_t *conf;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
729
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
730 if (ctx->zstream.avail_out) {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
731 return NGX_OK;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
732 }
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
733
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
734 conf = ngx_http_get_module_loc_conf(r, ngx_http_gzip_filter_module);
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
735
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
736 if (ctx->free) {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
737 ctx->out_buf = ctx->free->buf;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
738 ctx->free = ctx->free->next;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
739
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
740 } else if (ctx->bufs < conf->bufs.num) {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
741
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
742 ctx->out_buf = ngx_create_temp_buf(r->pool, conf->bufs.size);
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
743 if (ctx->out_buf == NULL) {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
744 return NGX_ERROR;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
745 }
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
746
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
747 ctx->out_buf->tag = (ngx_buf_tag_t) &ngx_http_gzip_filter_module;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
748 ctx->out_buf->recycled = 1;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
749 ctx->bufs++;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
750
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
751 } else {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
752 ctx->nomem = 1;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
753 return NGX_DECLINED;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
754 }
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
755
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
756 ctx->zstream.next_out = ctx->out_buf->pos;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
757 ctx->zstream.avail_out = conf->bufs.size;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
758
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
759 return NGX_OK;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
760 }
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
761
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
762
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
763 static ngx_int_t
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
764 ngx_http_gzip_filter_deflate(ngx_http_request_t *r, ngx_http_gzip_ctx_t *ctx)
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
765 {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
766 int rc;
662
e5fa0a4a7d27 nginx 1.1.15
Igor Sysoev <http://sysoev.ru>
parents: 660
diff changeset
767 ngx_buf_t *b;
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
768 ngx_chain_t *cl;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
769 ngx_http_gzip_conf_t *conf;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
770
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
771 ngx_log_debug6(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
772 "deflate in: ni:%p no:%p ai:%ud ao:%ud fl:%d redo:%d",
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
773 ctx->zstream.next_in, ctx->zstream.next_out,
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
774 ctx->zstream.avail_in, ctx->zstream.avail_out,
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
775 ctx->flush, ctx->redo);
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
776
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
777 rc = deflate(&ctx->zstream, ctx->flush);
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
778
662
e5fa0a4a7d27 nginx 1.1.15
Igor Sysoev <http://sysoev.ru>
parents: 660
diff changeset
779 if (rc != Z_OK && rc != Z_STREAM_END && rc != Z_BUF_ERROR) {
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
780 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
781 "deflate() failed: %d, %d", ctx->flush, rc);
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
782 return NGX_ERROR;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
783 }
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
784
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
785 ngx_log_debug5(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
786 "deflate out: ni:%p no:%p ai:%ud ao:%ud rc:%d",
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
787 ctx->zstream.next_in, ctx->zstream.next_out,
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
788 ctx->zstream.avail_in, ctx->zstream.avail_out,
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
789 rc);
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
790
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
791 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
792 "gzip in_buf:%p pos:%p",
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
793 ctx->in_buf, ctx->in_buf->pos);
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
794
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
795 if (ctx->zstream.next_in) {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
796 ctx->in_buf->pos = ctx->zstream.next_in;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
797
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
798 if (ctx->zstream.avail_in == 0) {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
799 ctx->zstream.next_in = NULL;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
800 }
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
801 }
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
802
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
803 ctx->out_buf->last = ctx->zstream.next_out;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
804
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
805 if (ctx->zstream.avail_out == 0) {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
806
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
807 /* zlib wants to output some more gzipped data */
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
808
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
809 cl = ngx_alloc_chain_link(r->pool);
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
810 if (cl == NULL) {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
811 return NGX_ERROR;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
812 }
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
813
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
814 cl->buf = ctx->out_buf;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
815 cl->next = NULL;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
816 *ctx->last_out = cl;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
817 ctx->last_out = &cl->next;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
818
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
819 ctx->redo = 1;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
820
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
821 return NGX_AGAIN;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
822 }
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
823
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
824 ctx->redo = 0;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
825
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
826 if (ctx->flush == Z_SYNC_FLUSH) {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
827
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
828 ctx->flush = Z_NO_FLUSH;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
829
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
830 cl = ngx_alloc_chain_link(r->pool);
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
831 if (cl == NULL) {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
832 return NGX_ERROR;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
833 }
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
834
662
e5fa0a4a7d27 nginx 1.1.15
Igor Sysoev <http://sysoev.ru>
parents: 660
diff changeset
835 b = ctx->out_buf;
e5fa0a4a7d27 nginx 1.1.15
Igor Sysoev <http://sysoev.ru>
parents: 660
diff changeset
836
e5fa0a4a7d27 nginx 1.1.15
Igor Sysoev <http://sysoev.ru>
parents: 660
diff changeset
837 if (ngx_buf_size(b) == 0) {
e5fa0a4a7d27 nginx 1.1.15
Igor Sysoev <http://sysoev.ru>
parents: 660
diff changeset
838
e5fa0a4a7d27 nginx 1.1.15
Igor Sysoev <http://sysoev.ru>
parents: 660
diff changeset
839 b = ngx_calloc_buf(ctx->request->pool);
e5fa0a4a7d27 nginx 1.1.15
Igor Sysoev <http://sysoev.ru>
parents: 660
diff changeset
840 if (b == NULL) {
e5fa0a4a7d27 nginx 1.1.15
Igor Sysoev <http://sysoev.ru>
parents: 660
diff changeset
841 return NGX_ERROR;
e5fa0a4a7d27 nginx 1.1.15
Igor Sysoev <http://sysoev.ru>
parents: 660
diff changeset
842 }
e5fa0a4a7d27 nginx 1.1.15
Igor Sysoev <http://sysoev.ru>
parents: 660
diff changeset
843
e5fa0a4a7d27 nginx 1.1.15
Igor Sysoev <http://sysoev.ru>
parents: 660
diff changeset
844 } else {
e5fa0a4a7d27 nginx 1.1.15
Igor Sysoev <http://sysoev.ru>
parents: 660
diff changeset
845 ctx->zstream.avail_out = 0;
e5fa0a4a7d27 nginx 1.1.15
Igor Sysoev <http://sysoev.ru>
parents: 660
diff changeset
846 }
e5fa0a4a7d27 nginx 1.1.15
Igor Sysoev <http://sysoev.ru>
parents: 660
diff changeset
847
e5fa0a4a7d27 nginx 1.1.15
Igor Sysoev <http://sysoev.ru>
parents: 660
diff changeset
848 b->flush = 1;
e5fa0a4a7d27 nginx 1.1.15
Igor Sysoev <http://sysoev.ru>
parents: 660
diff changeset
849
e5fa0a4a7d27 nginx 1.1.15
Igor Sysoev <http://sysoev.ru>
parents: 660
diff changeset
850 cl->buf = b;
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
851 cl->next = NULL;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
852 *ctx->last_out = cl;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
853 ctx->last_out = &cl->next;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
854
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
855 return NGX_OK;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
856 }
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
857
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
858 if (rc == Z_STREAM_END) {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
859
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
860 if (ngx_http_gzip_filter_deflate_end(r, ctx) != NGX_OK) {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
861 return NGX_ERROR;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
862 }
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
863
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
864 return NGX_OK;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
865 }
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
866
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
867 conf = ngx_http_get_module_loc_conf(r, ngx_http_gzip_filter_module);
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
868
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
869 if (conf->no_buffer && ctx->in == NULL) {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
870
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
871 cl = ngx_alloc_chain_link(r->pool);
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
872 if (cl == NULL) {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
873 return NGX_ERROR;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
874 }
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
875
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
876 cl->buf = ctx->out_buf;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
877 cl->next = NULL;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
878 *ctx->last_out = cl;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
879 ctx->last_out = &cl->next;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
880
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
881 return NGX_OK;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
882 }
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
883
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
884 return NGX_AGAIN;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
885 }
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
886
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
887
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
888 static ngx_int_t
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
889 ngx_http_gzip_filter_deflate_end(ngx_http_request_t *r,
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
890 ngx_http_gzip_ctx_t *ctx)
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
891 {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
892 int rc;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
893 ngx_buf_t *b;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
894 ngx_chain_t *cl;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
895 struct gztrailer *trailer;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
896
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
897 ctx->zin = ctx->zstream.total_in;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
898 ctx->zout = 10 + ctx->zstream.total_out + 8;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
899
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
900 rc = deflateEnd(&ctx->zstream);
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
901
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
902 if (rc != Z_OK) {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
903 ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
904 "deflateEnd() failed: %d", rc);
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
905 return NGX_ERROR;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
906 }
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
907
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
908 ngx_pfree(r->pool, ctx->preallocated);
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
909
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
910 cl = ngx_alloc_chain_link(r->pool);
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
911 if (cl == NULL) {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
912 return NGX_ERROR;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
913 }
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
914
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
915 cl->buf = ctx->out_buf;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
916 cl->next = NULL;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
917 *ctx->last_out = cl;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
918 ctx->last_out = &cl->next;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
919
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
920 if (ctx->zstream.avail_out >= 8) {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
921 trailer = (struct gztrailer *) ctx->out_buf->last;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
922 ctx->out_buf->last += 8;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
923 ctx->out_buf->last_buf = 1;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
924
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
925 } else {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
926 b = ngx_create_temp_buf(r->pool, 8);
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
927 if (b == NULL) {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
928 return NGX_ERROR;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
929 }
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
930
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
931 b->last_buf = 1;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
932
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
933 cl = ngx_alloc_chain_link(r->pool);
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
934 if (cl == NULL) {
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
935 return NGX_ERROR;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
936 }
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
937
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
938 cl->buf = b;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
939 cl->next = NULL;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
940 *ctx->last_out = cl;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
941 ctx->last_out = &cl->next;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
942 trailer = (struct gztrailer *) b->pos;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
943 b->last += 8;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
944 }
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
945
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
946 #if (NGX_HAVE_LITTLE_ENDIAN && NGX_HAVE_NONALIGNED)
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
947
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
948 trailer->crc32 = ctx->crc32;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
949 trailer->zlen = ctx->zin;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
950
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
951 #else
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
952
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
953 trailer->crc32[0] = (u_char) (ctx->crc32 & 0xff);
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
954 trailer->crc32[1] = (u_char) ((ctx->crc32 >> 8) & 0xff);
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
955 trailer->crc32[2] = (u_char) ((ctx->crc32 >> 16) & 0xff);
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
956 trailer->crc32[3] = (u_char) ((ctx->crc32 >> 24) & 0xff);
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
957
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
958 trailer->zlen[0] = (u_char) (ctx->zin & 0xff);
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
959 trailer->zlen[1] = (u_char) ((ctx->zin >> 8) & 0xff);
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
960 trailer->zlen[2] = (u_char) ((ctx->zin >> 16) & 0xff);
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
961 trailer->zlen[3] = (u_char) ((ctx->zin >> 24) & 0xff);
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
962
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
963 #endif
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
964
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
965 ctx->zstream.avail_in = 0;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
966 ctx->zstream.avail_out = 0;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
967
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
968 ctx->done = 1;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
969
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
970 r->connection->buffered &= ~NGX_HTTP_GZIP_BUFFERED;
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
971
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
972 return NGX_OK;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
973 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
974
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
975
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
976 static void *
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
977 ngx_http_gzip_filter_alloc(void *opaque, u_int items, u_int size)
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
978 {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
979 ngx_http_gzip_ctx_t *ctx = opaque;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
980
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
981 void *p;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
982 ngx_uint_t alloc;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
983
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
984 alloc = items * size;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
985
434
49a0eb7ce20c nginx 0.7.29
Igor Sysoev <http://sysoev.ru>
parents: 432
diff changeset
986 if (alloc % 512 != 0 && alloc < 8192) {
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
987
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
988 /*
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
989 * The zlib deflate_state allocation, it takes about 6K,
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
990 * we allocate 8K. Other allocations are divisible by 512.
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
991 */
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
992
434
49a0eb7ce20c nginx 0.7.29
Igor Sysoev <http://sysoev.ru>
parents: 432
diff changeset
993 alloc = 8192;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
994 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
995
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
996 if (alloc <= ctx->allocated) {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
997 p = ctx->free_mem;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
998 ctx->free_mem += alloc;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
999 ctx->allocated -= alloc;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1000
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1001 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, ctx->request->connection->log, 0,
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1002 "gzip alloc: n:%ud s:%ud a:%ud p:%p",
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1003 items, size, alloc, p);
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1004
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1005 return p;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1006 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1007
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1008 ngx_log_error(NGX_LOG_ALERT, ctx->request->connection->log, 0,
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1009 "gzip filter failed to use preallocated memory: %ud of %ud",
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1010 items * size, ctx->allocated);
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1011
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1012 p = ngx_palloc(ctx->request->pool, items * size);
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1013
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1014 return p;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1015 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1016
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1017
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1018 static void
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1019 ngx_http_gzip_filter_free(void *opaque, void *address)
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1020 {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1021 #if 0
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1022 ngx_http_gzip_ctx_t *ctx = opaque;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1023
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1024 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ctx->request->connection->log, 0,
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1025 "gzip free: %p", address);
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1026 #endif
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1027 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1028
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1029
432
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
1030 static void
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
1031 ngx_http_gzip_filter_free_copy_buf(ngx_http_request_t *r,
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
1032 ngx_http_gzip_ctx_t *ctx)
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
1033 {
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
1034 ngx_chain_t *cl;
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
1035
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
1036 for (cl = ctx->copied; cl; cl = cl->next) {
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
1037 ngx_pfree(r->pool, cl->buf->start);
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
1038 }
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
1039
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
1040 ctx->copied = NULL;
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
1041 }
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
1042
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
1043
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1044 static ngx_int_t
122
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
1045 ngx_http_gzip_add_variables(ngx_conf_t *cf)
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1046 {
260
0effe91f6083 nginx 0.5.0
Igor Sysoev <http://sysoev.ru>
parents: 230
diff changeset
1047 ngx_http_variable_t *var;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1048
132
91372f004adf nginx 0.3.13
Igor Sysoev <http://sysoev.ru>
parents: 126
diff changeset
1049 var = ngx_http_add_variable(cf, &ngx_http_gzip_ratio, NGX_HTTP_VAR_NOHASH);
122
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
1050 if (var == NULL) {
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
1051 return NGX_ERROR;
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
1052 }
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
1053
186
54aabf2b0bc6 nginx 0.3.40
Igor Sysoev <http://sysoev.ru>
parents: 146
diff changeset
1054 var->get_handler = ngx_http_gzip_ratio_variable;
122
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
1055
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1056 return NGX_OK;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1057 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1058
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1059
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1060 static ngx_int_t
122
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
1061 ngx_http_gzip_ratio_variable(ngx_http_request_t *r,
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
1062 ngx_http_variable_value_t *v, uintptr_t data)
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
1063 {
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
1064 ngx_uint_t zint, zfrac;
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
1065 ngx_http_gzip_ctx_t *ctx;
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
1066
126
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 122
diff changeset
1067 v->valid = 1;
340
10cc350ed8a1 nginx 0.6.14
Igor Sysoev <http://sysoev.ru>
parents: 260
diff changeset
1068 v->no_cacheable = 0;
122
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
1069 v->not_found = 0;
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
1070
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
1071 ctx = ngx_http_get_module_ctx(r, ngx_http_gzip_filter_module);
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
1072
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
1073 if (ctx == NULL || ctx->zout == 0) {
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
1074 v->not_found = 1;
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
1075 return NGX_OK;
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
1076 }
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
1077
382
984bb0b1399b nginx 0.7.3
Igor Sysoev <http://sysoev.ru>
parents: 358
diff changeset
1078 v->data = ngx_pnalloc(r->pool, NGX_INT32_LEN + 3);
122
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
1079 if (v->data == NULL) {
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
1080 return NGX_ERROR;
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
1081 }
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
1082
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
1083 zint = (ngx_uint_t) (ctx->zin / ctx->zout);
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
1084 zfrac = (ngx_uint_t) ((ctx->zin * 100 / ctx->zout) % 100);
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
1085
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
1086 if ((ctx->zin * 1000 / ctx->zout) % 10 > 4) {
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
1087
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
1088 /* the rounding, e.g., 2.125 to 2.13 */
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
1089
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
1090 zfrac++;
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
1091
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
1092 if (zfrac > 99) {
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
1093 zint++;
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
1094 zfrac = 0;
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
1095 }
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
1096 }
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
1097
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
1098 v->len = ngx_sprintf(v->data, "%ui.%02ui", zint, zfrac) - v->data;
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
1099
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
1100 return NGX_OK;
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
1101 }
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
1102
d25a1d6034f1 nginx 0.3.8
Igor Sysoev <http://sysoev.ru>
parents: 102
diff changeset
1103
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1104 static void *
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1105 ngx_http_gzip_create_conf(ngx_conf_t *cf)
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1106 {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1107 ngx_http_gzip_conf_t *conf;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1108
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1109 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_gzip_conf_t));
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1110 if (conf == NULL) {
496
f39b9e29530d nginx 0.8.0
Igor Sysoev <http://sysoev.ru>
parents: 454
diff changeset
1111 return NULL;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1112 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1113
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1114 /*
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1115 * set by ngx_pcalloc():
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1116 *
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1117 * conf->bufs.num = 0;
394
05981f639d21 nginx 0.7.9
Igor Sysoev <http://sysoev.ru>
parents: 382
diff changeset
1118 * conf->types = { NULL };
05981f639d21 nginx 0.7.9
Igor Sysoev <http://sysoev.ru>
parents: 382
diff changeset
1119 * conf->types_keys = NULL;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1120 */
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1121
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1122 conf->enable = NGX_CONF_UNSET;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1123 conf->no_buffer = NGX_CONF_UNSET;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1124
454
a8424ffa495c nginx 0.7.39
Igor Sysoev <http://sysoev.ru>
parents: 440
diff changeset
1125 conf->postpone_gzipping = NGX_CONF_UNSET_SIZE;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1126 conf->level = NGX_CONF_UNSET;
454
a8424ffa495c nginx 0.7.39
Igor Sysoev <http://sysoev.ru>
parents: 440
diff changeset
1127 conf->wbits = NGX_CONF_UNSET_SIZE;
a8424ffa495c nginx 0.7.39
Igor Sysoev <http://sysoev.ru>
parents: 440
diff changeset
1128 conf->memlevel = NGX_CONF_UNSET_SIZE;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1129 conf->min_length = NGX_CONF_UNSET;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1130
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1131 return conf;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1132 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1133
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1134
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1135 static char *
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1136 ngx_http_gzip_merge_conf(ngx_conf_t *cf, void *parent, void *child)
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1137 {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1138 ngx_http_gzip_conf_t *prev = parent;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1139 ngx_http_gzip_conf_t *conf = child;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1140
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1141 ngx_conf_merge_value(conf->enable, prev->enable, 0);
454
a8424ffa495c nginx 0.7.39
Igor Sysoev <http://sysoev.ru>
parents: 440
diff changeset
1142 ngx_conf_merge_value(conf->no_buffer, prev->no_buffer, 0);
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1143
432
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
1144 ngx_conf_merge_bufs_value(conf->bufs, prev->bufs,
fd759445d8a8 nginx 0.7.28
Igor Sysoev <http://sysoev.ru>
parents: 416
diff changeset
1145 (128 * 1024) / ngx_pagesize, ngx_pagesize);
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1146
454
a8424ffa495c nginx 0.7.39
Igor Sysoev <http://sysoev.ru>
parents: 440
diff changeset
1147 ngx_conf_merge_size_value(conf->postpone_gzipping, prev->postpone_gzipping,
a8424ffa495c nginx 0.7.39
Igor Sysoev <http://sysoev.ru>
parents: 440
diff changeset
1148 0);
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1149 ngx_conf_merge_value(conf->level, prev->level, 1);
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1150 ngx_conf_merge_size_value(conf->wbits, prev->wbits, MAX_WBITS);
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1151 ngx_conf_merge_size_value(conf->memlevel, prev->memlevel,
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1152 MAX_MEM_LEVEL - 1);
126
df17fbafec8f nginx 0.3.10
Igor Sysoev <http://sysoev.ru>
parents: 122
diff changeset
1153 ngx_conf_merge_value(conf->min_length, prev->min_length, 20);
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1154
554
5c576ea5dbd9 nginx 0.8.29
Igor Sysoev <http://sysoev.ru>
parents: 546
diff changeset
1155 if (ngx_http_merge_types(cf, &conf->types_keys, &conf->types,
5c576ea5dbd9 nginx 0.8.29
Igor Sysoev <http://sysoev.ru>
parents: 546
diff changeset
1156 &prev->types_keys, &prev->types,
394
05981f639d21 nginx 0.7.9
Igor Sysoev <http://sysoev.ru>
parents: 382
diff changeset
1157 ngx_http_html_default_types)
05981f639d21 nginx 0.7.9
Igor Sysoev <http://sysoev.ru>
parents: 382
diff changeset
1158 != NGX_OK)
05981f639d21 nginx 0.7.9
Igor Sysoev <http://sysoev.ru>
parents: 382
diff changeset
1159 {
05981f639d21 nginx 0.7.9
Igor Sysoev <http://sysoev.ru>
parents: 382
diff changeset
1160 return NGX_CONF_ERROR;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1161 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1162
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1163 return NGX_CONF_OK;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1164 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1165
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1166
230
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 212
diff changeset
1167 static ngx_int_t
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 212
diff changeset
1168 ngx_http_gzip_filter_init(ngx_conf_t *cf)
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 212
diff changeset
1169 {
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 212
diff changeset
1170 ngx_http_next_header_filter = ngx_http_top_header_filter;
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 212
diff changeset
1171 ngx_http_top_header_filter = ngx_http_gzip_header_filter;
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 212
diff changeset
1172
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 212
diff changeset
1173 ngx_http_next_body_filter = ngx_http_top_body_filter;
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 212
diff changeset
1174 ngx_http_top_body_filter = ngx_http_gzip_body_filter;
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 212
diff changeset
1175
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 212
diff changeset
1176 return NGX_OK;
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 212
diff changeset
1177 }
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 212
diff changeset
1178
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 212
diff changeset
1179
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1180 static char *
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents: 62
diff changeset
1181 ngx_http_gzip_window(ngx_conf_t *cf, void *post, void *data)
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1182 {
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
1183 size_t *np = data;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1184
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
1185 size_t wbits, wsize;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1186
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1187 wbits = 15;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1188
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1189 for (wsize = 32 * 1024; wsize > 256; wsize >>= 1) {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1190
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1191 if (wsize == *np) {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1192 *np = wbits;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1193
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1194 return NGX_CONF_OK;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1195 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1196
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1197 wbits--;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1198 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1199
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1200 return "must be 512, 1k, 2k, 4k, 8k, 16k, or 32k";
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1201 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1202
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1203
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1204 static char *
76
da9a3b14312d nginx 0.1.38
Igor Sysoev <http://sysoev.ru>
parents: 62
diff changeset
1205 ngx_http_gzip_hash(ngx_conf_t *cf, void *post, void *data)
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1206 {
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
1207 size_t *np = data;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1208
416
b4f69f2ef02c nginx 0.7.20
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
1209 size_t memlevel, hsize;
50
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1210
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1211 memlevel = 9;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1212
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1213 for (hsize = 128 * 1024; hsize > 256; hsize >>= 1) {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1214
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1215 if (hsize == *np) {
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1216 *np = memlevel;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1217
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1218 return NGX_CONF_OK;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1219 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1220
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1221 memlevel--;
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1222 }
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1223
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1224 return "must be 512, 1k, 2k, 4k, 8k, 16k, 32k, 64k, or 128k";
72eb30262aac nginx 0.1.25
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1225 }