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