Mercurial > hg > nginx-quic
annotate src/http/modules/ngx_http_gzip_filter_module.c @ 8869:f8f6b9fee66a
FastCGI: combining headers with identical names (ticket #1724).
FastCGI responder is expected to receive CGI/1.1 environment variables
in the parameters (see section "6.2 Responder" of the FastCGI specification).
Obviously enough, there cannot be multiple environment variables with
the same name.
Further, CGI specification (RFC 3875, section "4.1.18. Protocol-Specific
Meta-Variables") explicitly requires to combine headers: "If multiple
header fields with the same field-name are received then the server MUST
rewrite them as a single value having the same semantics".
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 30 May 2022 21:25:27 +0300 |
parents | c297c2c252d8 |
children | d26db4f82d7d |
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 |
4412 | 4 * Copyright (C) Nginx, Inc. |
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
|
5 */ |
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
|
6 |
133
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 |
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_config.h> |
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #include <ngx_core.h> |
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 #include <ngx_http.h> |
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
12 #include <zlib.h> |
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 |
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
15 typedef struct { |
290
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 enable; |
87e73f067470
nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
289
diff
changeset
|
17 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
|
18 |
2166
723df5089c05
use hash in gzip_types, ssi_types, and sub_filter_types
Igor Sysoev <igor@sysoev.ru>
parents:
2051
diff
changeset
|
19 ngx_hash_t types; |
452 | 20 |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
21 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
|
22 |
2542
925b5df2e0c2
fix postponed zlib memory allocation, introduced in r2411
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
23 size_t postpone_gzipping; |
589 | 24 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
|
25 size_t wbits; |
7a8ebba985a9
nginx-0.0.3-2004-04-16-19:27:31 import
Igor Sysoev <igor@sysoev.ru>
parents:
315
diff
changeset
|
26 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
|
27 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
|
28 |
723df5089c05
use hash in gzip_types, ssi_types, and sub_filter_types
Igor Sysoev <igor@sysoev.ru>
parents:
2051
diff
changeset
|
29 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
|
30 } 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
|
31 |
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
32 |
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
33 typedef struct { |
156
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 *in; |
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 *free; |
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 *busy; |
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 *out; |
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
38 ngx_chain_t **last_out; |
2410
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
39 |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
40 ngx_chain_t *copied; |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
41 ngx_chain_t *copy_buf; |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
42 |
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
|
43 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
|
44 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
|
45 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
|
46 |
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
47 void *preallocated; |
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
48 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
|
49 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
|
50 |
2410
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
51 int wbits; |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
52 int memlevel; |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
53 |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
54 unsigned flush:4; |
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
55 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
|
56 unsigned done:1; |
2287
baa61933d5ed
use nomem flag to flush busy bufs,
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
57 unsigned nomem:1; |
2410
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
58 unsigned buffering:1; |
8392
1f3d0d9f893f
Gzip: support for zlib-ng.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7545
diff
changeset
|
59 unsigned zlib_ng:1; |
177
4db54fdbcbe7
nginx-0.0.1-2003-11-10-20:17:31 import
Igor Sysoev <igor@sysoev.ru>
parents:
166
diff
changeset
|
60 |
4db54fdbcbe7
nginx-0.0.1-2003-11-10-20:17:31 import
Igor Sysoev <igor@sysoev.ru>
parents:
166
diff
changeset
|
61 size_t zin; |
4db54fdbcbe7
nginx-0.0.1-2003-11-10-20:17:31 import
Igor Sysoev <igor@sysoev.ru>
parents:
166
diff
changeset
|
62 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
|
63 |
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 |
2410
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
69 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
|
70 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
|
71 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
|
72 ngx_chain_t *in); |
2291
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
73 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
|
74 ngx_http_gzip_ctx_t *ctx); |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
75 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
|
76 ngx_http_gzip_ctx_t *ctx); |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
77 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
|
78 ngx_http_gzip_ctx_t *ctx); |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
79 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
|
80 ngx_http_gzip_ctx_t *ctx); |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
81 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
|
82 ngx_http_gzip_ctx_t *ctx); |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
83 |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
84 static void *ngx_http_gzip_filter_alloc(void *opaque, u_int items, |
497 | 85 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
|
86 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
|
87 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
|
88 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
|
89 |
573 | 90 static ngx_int_t ngx_http_gzip_add_variables(ngx_conf_t *cf); |
91 static ngx_int_t ngx_http_gzip_ratio_variable(ngx_http_request_t *r, | |
92 ngx_http_variable_value_t *v, uintptr_t data); | |
479 | 93 |
681 | 94 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
|
95 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
|
96 static char *ngx_http_gzip_merge_conf(ngx_conf_t *cf, |
497 | 97 void *parent, void *child); |
527 | 98 static char *ngx_http_gzip_window(ngx_conf_t *cf, void *post, void *data); |
99 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
|
100 |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
101 |
158
d377ee423603
nginx-0.0.1-2003-10-24-10:53:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
157
diff
changeset
|
102 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
|
103 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
|
104 }; |
d377ee423603
nginx-0.0.1-2003-10-24-10:53:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
157
diff
changeset
|
105 |
527 | 106 static ngx_conf_post_handler_pt ngx_http_gzip_window_p = ngx_http_gzip_window; |
107 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
|
108 |
134
d57c6835225c
nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
109 |
d57c6835225c
nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
110 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
|
111 |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
177
diff
changeset
|
112 { ngx_string("gzip"), |
485 | 113 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF |
114 |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
|
115 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
|
116 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
|
117 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
|
118 NULL }, |
134
d57c6835225c
nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
119 |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
177
diff
changeset
|
120 { 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
|
121 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
|
122 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
|
123 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
|
124 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
|
125 NULL }, |
134
d57c6835225c
nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
126 |
452 | 127 { ngx_string("gzip_types"), |
128 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
|
129 ngx_http_types_slot, |
452 | 130 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
|
131 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
|
132 &ngx_http_html_default_types[0] }, |
452 | 133 |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
177
diff
changeset
|
134 { 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
|
135 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
|
136 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
|
137 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
|
138 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
|
139 &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
|
140 |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
177
diff
changeset
|
141 { 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
|
142 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
|
143 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
|
144 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
|
145 offsetof(ngx_http_gzip_conf_t, wbits), |
527 | 146 &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
|
147 |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
177
diff
changeset
|
148 { 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
|
149 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
|
150 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
|
151 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
|
152 offsetof(ngx_http_gzip_conf_t, memlevel), |
527 | 153 &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
|
154 |
2542
925b5df2e0c2
fix postponed zlib memory allocation, introduced in r2411
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
155 { ngx_string("postpone_gzipping"), |
925b5df2e0c2
fix postponed zlib memory allocation, introduced in r2411
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
156 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
|
157 ngx_conf_set_size_slot, |
925b5df2e0c2
fix postponed zlib memory allocation, introduced in r2411
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
158 NGX_HTTP_LOC_CONF_OFFSET, |
925b5df2e0c2
fix postponed zlib memory allocation, introduced in r2411
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
159 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
|
160 NULL }, |
925b5df2e0c2
fix postponed zlib memory allocation, introduced in r2411
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
161 |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
177
diff
changeset
|
162 { 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
|
163 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
|
164 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
|
165 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
|
166 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
|
167 NULL }, |
134
d57c6835225c
nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
168 |
320
d621239c30f7
nginx-0.0.3-2004-04-18-23:06:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
319
diff
changeset
|
169 { 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
|
170 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
|
171 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
|
172 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
|
173 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
|
174 NULL }, |
314
d71c87d11b16
nginx-0.0.3-2004-04-14-09:57:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
294
diff
changeset
|
175 |
239
574bea0142be
nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
177
diff
changeset
|
176 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
|
177 }; |
133
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
178 |
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
179 |
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
180 static ngx_http_module_t ngx_http_gzip_filter_module_ctx = { |
573 | 181 ngx_http_gzip_add_variables, /* preconfiguration */ |
681 | 182 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
|
183 |
133
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
184 NULL, /* create main configuration */ |
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
185 NULL, /* init main configuration */ |
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
186 |
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
187 NULL, /* create server configuration */ |
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
188 NULL, /* merge server configuration */ |
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
189 |
134
d57c6835225c
nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
190 ngx_http_gzip_create_conf, /* create location configuration */ |
489 | 191 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
|
192 }; |
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
193 |
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
194 |
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
195 ngx_module_t ngx_http_gzip_filter_module = { |
509 | 196 NGX_MODULE_V1, |
133
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
197 &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
|
198 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
|
199 NGX_HTTP_MODULE, /* module type */ |
541 | 200 NULL, /* init master */ |
681 | 201 NULL, /* init module */ |
541 | 202 NULL, /* init process */ |
203 NULL, /* init thread */ | |
204 NULL, /* exit thread */ | |
205 NULL, /* exit process */ | |
206 NULL, /* exit master */ | |
207 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
|
208 }; |
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
209 |
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
210 |
573 | 211 static ngx_str_t ngx_http_gzip_ratio = ngx_string("gzip_ratio"); |
509 | 212 |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
213 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
|
214 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
|
215 |
8392
1f3d0d9f893f
Gzip: support for zlib-ng.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7545
diff
changeset
|
216 static ngx_uint_t ngx_http_gzip_assume_zlib_ng; |
7155
29e9571b1989
Gzip: support for a zlib variant from Intel.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7033
diff
changeset
|
217 |
133
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
218 |
497 | 219 static ngx_int_t |
220 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
|
221 { |
2051
115e6f029fcc
"gzip_vary on" always sends "Vary: Accept-Encoding" header
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
222 ngx_table_elt_t *h; |
115e6f029fcc
"gzip_vary on" always sends "Vary: Accept-Encoding" header
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
223 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
|
224 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
|
225 |
135
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
134
diff
changeset
|
226 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
|
227 |
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
134
diff
changeset
|
228 if (!conf->enable |
452 | 229 || (r->headers_out.status != NGX_HTTP_OK |
230 && r->headers_out.status != NGX_HTTP_FORBIDDEN | |
231 && 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
|
232 || (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
|
233 && 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
|
234 || (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
|
235 && 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
|
236 || 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
|
237 || 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
|
238 { |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
239 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
|
240 } |
d57c6835225c
nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
241 |
3313 | 242 r->gzip_vary = 1; |
243 | |
3773 | 244 #if (NGX_HTTP_DEGRADATION) |
245 { | |
246 ngx_http_core_loc_conf_t *clcf; | |
247 | |
248 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | |
249 | |
250 if (clcf->gzip_disable_degradation && ngx_http_degraded(r)) { | |
251 return ngx_http_next_header_filter(r); | |
252 } | |
253 } | |
254 #endif | |
255 | |
3313 | 256 if (!r->gzip_tested) { |
257 if (ngx_http_gzip_ok(r) != NGX_OK) { | |
258 return ngx_http_next_header_filter(r); | |
259 } | |
260 | |
261 } else if (!r->gzip_ok) { | |
262 return ngx_http_next_header_filter(r); | |
263 } | |
264 | |
501 | 265 ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_gzip_ctx_t)); |
266 if (ctx == NULL) { | |
267 return NGX_ERROR; | |
268 } | |
314
d71c87d11b16
nginx-0.0.3-2004-04-14-09:57:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
294
diff
changeset
|
269 |
501 | 270 ngx_http_set_ctx(r, ctx, ngx_http_gzip_filter_module); |
271 | |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
272 ctx->request = r; |
2542
925b5df2e0c2
fix postponed zlib memory allocation, introduced in r2411
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
273 ctx->buffering = (conf->postpone_gzipping != 0); |
2410
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
274 |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
275 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
|
276 |
1790
775edc46ee66
ngx_http_gzip_static_module and gzip_disable
Igor Sysoev <igor@sysoev.ru>
parents:
1626
diff
changeset
|
277 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
|
278 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
|
279 return NGX_ERROR; |
84036764e215
nginx-0.0.1-2003-10-29-11:30:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
280 } |
135
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
134
diff
changeset
|
281 |
1790
775edc46ee66
ngx_http_gzip_static_module and gzip_disable
Igor Sysoev <igor@sysoev.ru>
parents:
1626
diff
changeset
|
282 h->hash = 1; |
3516
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3379
diff
changeset
|
283 ngx_str_set(&h->key, "Content-Encoding"); |
dd1570b6f237
ngx_str_set() and ngx_str_null()
Igor Sysoev <igor@sysoev.ru>
parents:
3379
diff
changeset
|
284 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
|
285 r->headers_out.content_encoding = h; |
775edc46ee66
ngx_http_gzip_static_module and gzip_disable
Igor Sysoev <igor@sysoev.ru>
parents:
1626
diff
changeset
|
286 |
513 | 287 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
|
288 |
577 | 289 ngx_http_clear_content_length(r); |
290 ngx_http_clear_accept_ranges(r); | |
5733
e491b26fa5a1
Entity tags: downgrade strong etags to weak ones as needed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5432
diff
changeset
|
291 ngx_http_weak_etag(r); |
577 | 292 |
155
46eb23d9471d
nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents:
154
diff
changeset
|
293 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
|
294 } |
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
295 |
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
296 |
497 | 297 static ngx_int_t |
298 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
|
299 { |
2291
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
300 int rc; |
5876
973fded4f461
Gzip, gunzip: flush busy buffers if any.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5733
diff
changeset
|
301 ngx_uint_t flush; |
2291
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
302 ngx_chain_t *cl; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
303 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
|
304 |
243
bf2faf694c19
nginx-0.0.1-2004-01-28-23:38:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
239
diff
changeset
|
305 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
|
306 |
4990
e2794322ec76
Fixed HEAD requests handling when proxying is used (closes #261).
Valentin Bartenev <vbart@nginx.com>
parents:
4965
diff
changeset
|
307 if (ctx == NULL || ctx->done || r->header_only) { |
177
4db54fdbcbe7
nginx-0.0.1-2003-11-10-20:17:31 import
Igor Sysoev <igor@sysoev.ru>
parents:
166
diff
changeset
|
308 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
|
309 } |
4db54fdbcbe7
nginx-0.0.1-2003-11-10-20:17:31 import
Igor Sysoev <igor@sysoev.ru>
parents:
166
diff
changeset
|
310 |
2410
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
311 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
|
312 "http gzip filter"); |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
313 |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
314 if (ctx->buffering) { |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
315 |
2542
925b5df2e0c2
fix postponed zlib memory allocation, introduced in r2411
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
316 /* |
925b5df2e0c2
fix postponed zlib memory allocation, introduced in r2411
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
317 * 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
|
318 * 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
|
319 * 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
|
320 * 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
|
321 * 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
|
322 * 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
|
323 */ |
925b5df2e0c2
fix postponed zlib memory allocation, introduced in r2411
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
324 |
2410
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
325 if (in) { |
2542
925b5df2e0c2
fix postponed zlib memory allocation, introduced in r2411
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
326 switch (ngx_http_gzip_filter_buffer(ctx, in)) { |
2410
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
327 |
2468 | 328 case NGX_OK: |
329 return NGX_OK; | |
2410
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
330 |
2468 | 331 case NGX_DONE: |
332 in = NULL; | |
333 break; | |
2410
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
334 |
2468 | 335 default: /* NGX_ERROR */ |
336 goto failed; | |
337 } | |
2410
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
338 |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
339 } else { |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
340 ctx->buffering = 0; |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
341 } |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
342 } |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
343 |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
344 if (ctx->preallocated == NULL) { |
2291
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
345 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
|
346 goto failed; |
430
1fa5daf7558e
nginx-0.0.11-2004-09-19-22:27:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
416
diff
changeset
|
347 } |
133
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
348 } |
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
349 |
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
350 if (in) { |
2536
a6d6d762c554
small optimization: " == NGX_ERROR" > " != NGX_OK"
Igor Sysoev <igor@sysoev.ru>
parents:
2468
diff
changeset
|
351 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
|
352 goto failed; |
134
d57c6835225c
nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
353 } |
5291
84155a389bcc
Gzip: clearing of c->buffered if all data are flushed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5107
diff
changeset
|
354 |
84155a389bcc
Gzip: clearing of c->buffered if all data are flushed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5107
diff
changeset
|
355 r->connection->buffered |= NGX_HTTP_GZIP_BUFFERED; |
133
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
356 } |
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
357 |
5876
973fded4f461
Gzip, gunzip: flush busy buffers if any.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5733
diff
changeset
|
358 if (ctx->nomem) { |
2291
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
359 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
360 /* flush busy buffers */ |
2287
baa61933d5ed
use nomem flag to flush busy bufs,
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
361 |
baa61933d5ed
use nomem flag to flush busy bufs,
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
362 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
|
363 goto failed; |
2287
baa61933d5ed
use nomem flag to flush busy bufs,
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
364 } |
baa61933d5ed
use nomem flag to flush busy bufs,
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
365 |
baa61933d5ed
use nomem flag to flush busy bufs,
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
366 cl = NULL; |
baa61933d5ed
use nomem flag to flush busy bufs,
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
367 |
4114
5db098f97e0e
API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3773
diff
changeset
|
368 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
|
369 (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
|
370 ctx->nomem = 0; |
5876
973fded4f461
Gzip, gunzip: flush busy buffers if any.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5733
diff
changeset
|
371 flush = 0; |
973fded4f461
Gzip, gunzip: flush busy buffers if any.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5733
diff
changeset
|
372 |
973fded4f461
Gzip, gunzip: flush busy buffers if any.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5733
diff
changeset
|
373 } else { |
973fded4f461
Gzip, gunzip: flush busy buffers if any.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5733
diff
changeset
|
374 flush = ctx->busy ? 1 : 0; |
2287
baa61933d5ed
use nomem flag to flush busy bufs,
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
375 } |
141
656d468f4ead
nginx-0.0.1-2003-10-08-19:32:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
136
diff
changeset
|
376 |
135
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
134
diff
changeset
|
377 for ( ;; ) { |
e29909bd9b8a
nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents:
134
diff
changeset
|
378 |
2291
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
379 /* cycle while we can write to a client */ |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
380 |
133
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
381 for ( ;; ) { |
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
382 |
2291
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
383 /* 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
|
384 |
2291
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
385 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
|
386 |
2291
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
387 if (rc == NGX_DECLINED) { |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
388 break; |
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 |
2291
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
391 if (rc == NGX_AGAIN) { |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
392 continue; |
133
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
393 } |
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
394 |
430
1fa5daf7558e
nginx-0.0.11-2004-09-19-22:27:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
416
diff
changeset
|
395 |
2291
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
396 /* ... 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
|
397 |
2291
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
398 rc = ngx_http_gzip_filter_get_buf(r, ctx); |
501 | 399 |
2291
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
400 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
|
401 break; |
ba876b26b76d
nginx-0.0.3-2004-04-21-22:54:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
322
diff
changeset
|
402 } |
ba876b26b76d
nginx-0.0.3-2004-04-21-22:54:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
322
diff
changeset
|
403 |
2291
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
404 if (rc == NGX_ERROR) { |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
405 goto failed; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
406 } |
134
d57c6835225c
nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
407 |
479 | 408 |
2291
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
409 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
|
410 |
2291
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
411 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
|
412 break; |
ba876b26b76d
nginx-0.0.3-2004-04-21-22:54:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
322
diff
changeset
|
413 } |
133
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
414 |
2291
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
415 if (rc == NGX_ERROR) { |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
416 goto failed; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
417 } |
501 | 418 |
2291
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
419 /* rc == NGX_AGAIN */ |
133
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
420 } |
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
421 |
5876
973fded4f461
Gzip, gunzip: flush busy buffers if any.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5733
diff
changeset
|
422 if (ctx->out == NULL && !flush) { |
2410
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
423 ngx_http_gzip_filter_free_copy_buf(r, ctx); |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
424 |
2292 | 425 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
|
426 } |
1fa5daf7558e
nginx-0.0.11-2004-09-19-22:27:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
416
diff
changeset
|
427 |
2287
baa61933d5ed
use nomem flag to flush busy bufs,
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
428 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
|
429 |
2287
baa61933d5ed
use nomem flag to flush busy bufs,
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
430 if (rc == NGX_ERROR) { |
2291
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
431 goto failed; |
133
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
432 } |
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
433 |
2410
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
434 ngx_http_gzip_filter_free_copy_buf(r, ctx); |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
435 |
4114
5db098f97e0e
API change: ngx_chain_update_chains() now requires pool.
Maxim Dounin <mdounin@mdounin.ru>
parents:
3773
diff
changeset
|
436 ngx_chain_update_chains(r->pool, &ctx->free, &ctx->busy, &ctx->out, |
501 | 437 (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
|
438 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
|
439 |
2287
baa61933d5ed
use nomem flag to flush busy bufs,
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
440 ctx->nomem = 0; |
5876
973fded4f461
Gzip, gunzip: flush busy buffers if any.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5733
diff
changeset
|
441 flush = 0; |
2287
baa61933d5ed
use nomem flag to flush busy bufs,
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
442 |
327
e0f3f238db09
nginx-0.0.3-2004-04-26-17:40:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
326
diff
changeset
|
443 if (ctx->done) { |
2287
baa61933d5ed
use nomem flag to flush busy bufs,
Igor Sysoev <igor@sysoev.ru>
parents:
2166
diff
changeset
|
444 return rc; |
327
e0f3f238db09
nginx-0.0.3-2004-04-26-17:40:01 import
Igor Sysoev <igor@sysoev.ru>
parents:
326
diff
changeset
|
445 } |
133
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
446 } |
2291
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
447 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
448 /* unreachable */ |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
449 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
450 failed: |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
451 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
452 ctx->done = 1; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
453 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
454 if (ctx->preallocated) { |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
455 deflateEnd(&ctx->zstream); |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
456 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
457 ngx_pfree(r->pool, ctx->preallocated); |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
458 } |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
459 |
2410
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
460 ngx_http_gzip_filter_free_copy_buf(r, ctx); |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
461 |
2291
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
462 return NGX_ERROR; |
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 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
465 |
2410
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
466 static void |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
467 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
|
468 { |
2410
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
469 int wbits, memlevel; |
2291
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
470 ngx_http_gzip_conf_t *conf; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
471 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
472 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
|
473 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
474 wbits = conf->wbits; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
475 memlevel = conf->memlevel; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
476 |
2410
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
477 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
|
478 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
479 /* 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
|
480 |
2410
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
481 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
|
482 wbits--; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
483 memlevel--; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
484 } |
4965
58dfef910ccd
Gzip: fixed zlib memLevel adjusting.
Valentin Bartenev <vbart@nginx.com>
parents:
4746
diff
changeset
|
485 |
58dfef910ccd
Gzip: fixed zlib memLevel adjusting.
Valentin Bartenev <vbart@nginx.com>
parents:
4746
diff
changeset
|
486 if (memlevel < 1) { |
58dfef910ccd
Gzip: fixed zlib memLevel adjusting.
Valentin Bartenev <vbart@nginx.com>
parents:
4746
diff
changeset
|
487 memlevel = 1; |
58dfef910ccd
Gzip: fixed zlib memLevel adjusting.
Valentin Bartenev <vbart@nginx.com>
parents:
4746
diff
changeset
|
488 } |
2291
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
489 } |
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 ctx->wbits = wbits; |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
492 ctx->memlevel = memlevel; |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
493 |
2291
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
494 /* |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
495 * 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
|
496 * 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
|
497 * 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
|
498 * 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
|
499 * 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
|
500 * |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
501 * 8K is for zlib deflate_state, it takes |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
502 * *) 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
|
503 * *) 5920 bytes on amd64 and sparc64 |
8393
c297c2c252d8
Gzip: updated handling of zlib variant from Intel.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8392
diff
changeset
|
504 * |
c297c2c252d8
Gzip: updated handling of zlib variant from Intel.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8392
diff
changeset
|
505 * A zlib variant from Intel (https://github.com/jtkukunas/zlib) |
c297c2c252d8
Gzip: updated handling of zlib variant from Intel.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8392
diff
changeset
|
506 * uses additional 16-byte padding in one of window-sized buffers. |
2291
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
507 */ |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
508 |
8393
c297c2c252d8
Gzip: updated handling of zlib variant from Intel.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8392
diff
changeset
|
509 if (!ngx_http_gzip_assume_zlib_ng) { |
7155
29e9571b1989
Gzip: support for a zlib variant from Intel.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7033
diff
changeset
|
510 ctx->allocated = 8192 + 16 + (1 << (wbits + 2)) |
8393
c297c2c252d8
Gzip: updated handling of zlib variant from Intel.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8392
diff
changeset
|
511 + (1 << (memlevel + 9)); |
8392
1f3d0d9f893f
Gzip: support for zlib-ng.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7545
diff
changeset
|
512 |
1f3d0d9f893f
Gzip: support for zlib-ng.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7545
diff
changeset
|
513 } else { |
1f3d0d9f893f
Gzip: support for zlib-ng.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7545
diff
changeset
|
514 /* |
1f3d0d9f893f
Gzip: support for zlib-ng.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7545
diff
changeset
|
515 * Another zlib variant, https://github.com/zlib-ng/zlib-ng. |
8393
c297c2c252d8
Gzip: updated handling of zlib variant from Intel.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8392
diff
changeset
|
516 * It forces window bits to 13 for fast compression level, |
c297c2c252d8
Gzip: updated handling of zlib variant from Intel.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8392
diff
changeset
|
517 * uses 16-byte padding in one of window-sized buffers, and |
c297c2c252d8
Gzip: updated handling of zlib variant from Intel.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8392
diff
changeset
|
518 * uses 128K hash. |
8392
1f3d0d9f893f
Gzip: support for zlib-ng.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7545
diff
changeset
|
519 */ |
1f3d0d9f893f
Gzip: support for zlib-ng.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7545
diff
changeset
|
520 |
1f3d0d9f893f
Gzip: support for zlib-ng.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7545
diff
changeset
|
521 if (conf->level == 1) { |
1f3d0d9f893f
Gzip: support for zlib-ng.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7545
diff
changeset
|
522 wbits = ngx_max(wbits, 13); |
1f3d0d9f893f
Gzip: support for zlib-ng.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7545
diff
changeset
|
523 } |
1f3d0d9f893f
Gzip: support for zlib-ng.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7545
diff
changeset
|
524 |
1f3d0d9f893f
Gzip: support for zlib-ng.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7545
diff
changeset
|
525 ctx->allocated = 8192 + 16 + (1 << (wbits + 2)) |
1f3d0d9f893f
Gzip: support for zlib-ng.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7545
diff
changeset
|
526 + 131072 + (1 << (memlevel + 8)); |
1f3d0d9f893f
Gzip: support for zlib-ng.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7545
diff
changeset
|
527 ctx->zlib_ng = 1; |
7155
29e9571b1989
Gzip: support for a zlib variant from Intel.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7033
diff
changeset
|
528 } |
2410
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
529 } |
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 |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
532 static ngx_int_t |
2542
925b5df2e0c2
fix postponed zlib memory allocation, introduced in r2411
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
533 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
|
534 { |
2542
925b5df2e0c2
fix postponed zlib memory allocation, introduced in r2411
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
535 size_t size, buffered; |
925b5df2e0c2
fix postponed zlib memory allocation, introduced in r2411
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
536 ngx_buf_t *b, *buf; |
925b5df2e0c2
fix postponed zlib memory allocation, introduced in r2411
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
537 ngx_chain_t *cl, **ll; |
925b5df2e0c2
fix postponed zlib memory allocation, introduced in r2411
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
538 ngx_http_request_t *r; |
925b5df2e0c2
fix postponed zlib memory allocation, introduced in r2411
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
539 ngx_http_gzip_conf_t *conf; |
2410
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
540 |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
541 r = ctx->request; |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
542 |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
543 r->connection->buffered |= NGX_HTTP_GZIP_BUFFERED; |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
544 |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
545 buffered = 0; |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
546 ll = &ctx->in; |
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 for (cl = ctx->in; cl; cl = cl->next) { |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
549 buffered += cl->buf->last - cl->buf->pos; |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
550 ll = &cl->next; |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
551 } |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
552 |
2542
925b5df2e0c2
fix postponed zlib memory allocation, introduced in r2411
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
553 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
|
554 |
2410
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
555 while (in) { |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
556 cl = ngx_alloc_chain_link(r->pool); |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
557 if (cl == NULL) { |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
558 return NGX_ERROR; |
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 |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
561 b = in->buf; |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
562 |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
563 size = b->last - b->pos; |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
564 buffered += size; |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
565 |
2542
925b5df2e0c2
fix postponed zlib memory allocation, introduced in r2411
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
566 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
|
567 ctx->buffering = 0; |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
568 } |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
569 |
2542
925b5df2e0c2
fix postponed zlib memory allocation, introduced in r2411
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
570 if (ctx->buffering && size) { |
2410
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
571 |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
572 buf = ngx_create_temp_buf(r->pool, size); |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
573 if (buf == NULL) { |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
574 return NGX_ERROR; |
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 buf->last = ngx_cpymem(buf->pos, b->pos, size); |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
578 b->pos = b->last; |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
579 |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
580 buf->last_buf = b->last_buf; |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
581 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
|
582 |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
583 cl->buf = buf; |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
584 |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
585 } else { |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
586 cl->buf = b; |
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 |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
589 *ll = cl; |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
590 ll = &cl->next; |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
591 in = in->next; |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
592 } |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
593 |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
594 *ll = NULL; |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
595 |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
596 return ctx->buffering ? NGX_OK : NGX_DONE; |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
597 } |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
598 |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
599 |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
600 static ngx_int_t |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
601 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
|
602 ngx_http_gzip_ctx_t *ctx) |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
603 { |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
604 int rc; |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
605 ngx_http_gzip_conf_t *conf; |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
606 |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
607 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
|
608 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
609 ctx->preallocated = ngx_palloc(r->pool, ctx->allocated); |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
610 if (ctx->preallocated == NULL) { |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
611 return NGX_ERROR; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
612 } |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
613 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
614 ctx->free_mem = ctx->preallocated; |
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 ctx->zstream.zalloc = ngx_http_gzip_filter_alloc; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
617 ctx->zstream.zfree = ngx_http_gzip_filter_free; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
618 ctx->zstream.opaque = ctx; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
619 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
620 rc = deflateInit2(&ctx->zstream, (int) conf->level, Z_DEFLATED, |
7534
ac5a741d39cf
Gzip: use zlib to write header and trailer.
Ilya Leoshkevich <iii@linux.ibm.com>
parents:
7155
diff
changeset
|
621 ctx->wbits + 16, ctx->memlevel, Z_DEFAULT_STRATEGY); |
2291
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 if (rc != Z_OK) { |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
624 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
|
625 "deflateInit2() failed: %d", rc); |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
626 return NGX_ERROR; |
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 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
629 ctx->last_out = &ctx->out; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
630 ctx->flush = Z_NO_FLUSH; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
631 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
632 return NGX_OK; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
633 } |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
634 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
635 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
636 static ngx_int_t |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
637 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
|
638 { |
6910
da46bfc484ef
Gzip: free chain links on the hot path (ticket #1046).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
639 ngx_chain_t *cl; |
da46bfc484ef
Gzip: free chain links on the hot path (ticket #1046).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
640 |
2291
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
641 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
|
642 return NGX_OK; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
643 } |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
644 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
645 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
|
646 "gzip in: %p", ctx->in); |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
647 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
648 if (ctx->in == NULL) { |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
649 return NGX_DECLINED; |
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 |
2410
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
652 if (ctx->copy_buf) { |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
653 |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
654 /* |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
655 * 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
|
656 * but postpone free()ing after zlib compressing and data output |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
657 */ |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
658 |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
659 ctx->copy_buf->next = ctx->copied; |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
660 ctx->copied = ctx->copy_buf; |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
661 ctx->copy_buf = NULL; |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
662 } |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
663 |
6910
da46bfc484ef
Gzip: free chain links on the hot path (ticket #1046).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
664 cl = ctx->in; |
da46bfc484ef
Gzip: free chain links on the hot path (ticket #1046).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
665 ctx->in_buf = cl->buf; |
da46bfc484ef
Gzip: free chain links on the hot path (ticket #1046).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
666 ctx->in = cl->next; |
2410
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
667 |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
668 if (ctx->in_buf->tag == (ngx_buf_tag_t) &ngx_http_gzip_filter_module) { |
6910
da46bfc484ef
Gzip: free chain links on the hot path (ticket #1046).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
669 ctx->copy_buf = cl; |
da46bfc484ef
Gzip: free chain links on the hot path (ticket #1046).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
670 |
da46bfc484ef
Gzip: free chain links on the hot path (ticket #1046).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
671 } else { |
da46bfc484ef
Gzip: free chain links on the hot path (ticket #1046).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
672 ngx_free_chain(r->pool, cl); |
2410
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 |
2291
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
675 ctx->zstream.next_in = ctx->in_buf->pos; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
676 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
|
677 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
678 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
|
679 "gzip in_buf:%p ni:%p ai:%ud", |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
680 ctx->in_buf, |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
681 ctx->zstream.next_in, ctx->zstream.avail_in); |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
682 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
683 if (ctx->in_buf->last_buf) { |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
684 ctx->flush = Z_FINISH; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
685 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
686 } else if (ctx->in_buf->flush) { |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
687 ctx->flush = Z_SYNC_FLUSH; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
688 |
7534
ac5a741d39cf
Gzip: use zlib to write header and trailer.
Ilya Leoshkevich <iii@linux.ibm.com>
parents:
7155
diff
changeset
|
689 } else if (ctx->zstream.avail_in == 0) { |
ac5a741d39cf
Gzip: use zlib to write header and trailer.
Ilya Leoshkevich <iii@linux.ibm.com>
parents:
7155
diff
changeset
|
690 /* ctx->flush == Z_NO_FLUSH */ |
2291
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
691 return NGX_AGAIN; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
692 } |
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 return NGX_OK; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
695 } |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
696 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
697 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
698 static ngx_int_t |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
699 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
|
700 { |
6910
da46bfc484ef
Gzip: free chain links on the hot path (ticket #1046).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
701 ngx_chain_t *cl; |
2291
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
702 ngx_http_gzip_conf_t *conf; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
703 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
704 if (ctx->zstream.avail_out) { |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
705 return NGX_OK; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
706 } |
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 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
|
709 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
710 if (ctx->free) { |
6910
da46bfc484ef
Gzip: free chain links on the hot path (ticket #1046).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
711 |
da46bfc484ef
Gzip: free chain links on the hot path (ticket #1046).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
712 cl = ctx->free; |
da46bfc484ef
Gzip: free chain links on the hot path (ticket #1046).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
713 ctx->out_buf = cl->buf; |
da46bfc484ef
Gzip: free chain links on the hot path (ticket #1046).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
714 ctx->free = cl->next; |
da46bfc484ef
Gzip: free chain links on the hot path (ticket #1046).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
715 |
da46bfc484ef
Gzip: free chain links on the hot path (ticket #1046).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6480
diff
changeset
|
716 ngx_free_chain(r->pool, cl); |
2291
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 } else if (ctx->bufs < conf->bufs.num) { |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
719 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
720 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
|
721 if (ctx->out_buf == NULL) { |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
722 return NGX_ERROR; |
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 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
725 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
|
726 ctx->out_buf->recycled = 1; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
727 ctx->bufs++; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
728 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
729 } else { |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
730 ctx->nomem = 1; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
731 return NGX_DECLINED; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
732 } |
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 ctx->zstream.next_out = ctx->out_buf->pos; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
735 ctx->zstream.avail_out = conf->bufs.size; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
736 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
737 return NGX_OK; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
738 } |
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 static ngx_int_t |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
742 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
|
743 { |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
744 int rc; |
4468
93dd50a9dc70
Gzip filter: handling of empty flush buffers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
745 ngx_buf_t *b; |
2291
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
746 ngx_chain_t *cl; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
747 ngx_http_gzip_conf_t *conf; |
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 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
|
750 "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
|
751 ctx->zstream.next_in, ctx->zstream.next_out, |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
752 ctx->zstream.avail_in, ctx->zstream.avail_out, |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
753 ctx->flush, ctx->redo); |
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 rc = deflate(&ctx->zstream, ctx->flush); |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
756 |
4468
93dd50a9dc70
Gzip filter: handling of empty flush buffers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
757 if (rc != Z_OK && rc != Z_STREAM_END && rc != Z_BUF_ERROR) { |
2291
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
758 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
|
759 "deflate() failed: %d, %d", ctx->flush, rc); |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
760 return NGX_ERROR; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
761 } |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
762 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
763 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
|
764 "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
|
765 ctx->zstream.next_in, ctx->zstream.next_out, |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
766 ctx->zstream.avail_in, ctx->zstream.avail_out, |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
767 rc); |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
768 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
769 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
|
770 "gzip in_buf:%p pos:%p", |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
771 ctx->in_buf, ctx->in_buf->pos); |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
772 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
773 if (ctx->zstream.next_in) { |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
774 ctx->in_buf->pos = ctx->zstream.next_in; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
775 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
776 if (ctx->zstream.avail_in == 0) { |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
777 ctx->zstream.next_in = NULL; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
778 } |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
779 } |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
780 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
781 ctx->out_buf->last = ctx->zstream.next_out; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
782 |
7545
0ef2bc0ec9c9
Gzip: fixed "zero size buf" alerts after ac5a741d39cf.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7534
diff
changeset
|
783 if (ctx->zstream.avail_out == 0 && rc != Z_STREAM_END) { |
2291
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
784 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
785 /* zlib wants to output some more gzipped data */ |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
786 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
787 cl = ngx_alloc_chain_link(r->pool); |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
788 if (cl == NULL) { |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
789 return NGX_ERROR; |
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 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
792 cl->buf = ctx->out_buf; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
793 cl->next = NULL; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
794 *ctx->last_out = cl; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
795 ctx->last_out = &cl->next; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
796 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
797 ctx->redo = 1; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
798 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
799 return NGX_AGAIN; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
800 } |
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 ctx->redo = 0; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
803 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
804 if (ctx->flush == Z_SYNC_FLUSH) { |
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 ctx->flush = Z_NO_FLUSH; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
807 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
808 cl = ngx_alloc_chain_link(r->pool); |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
809 if (cl == NULL) { |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
810 return NGX_ERROR; |
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 |
4468
93dd50a9dc70
Gzip filter: handling of empty flush buffers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
813 b = ctx->out_buf; |
93dd50a9dc70
Gzip filter: handling of empty flush buffers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
814 |
93dd50a9dc70
Gzip filter: handling of empty flush buffers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
815 if (ngx_buf_size(b) == 0) { |
93dd50a9dc70
Gzip filter: handling of empty flush buffers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
816 |
93dd50a9dc70
Gzip filter: handling of empty flush buffers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
817 b = ngx_calloc_buf(ctx->request->pool); |
93dd50a9dc70
Gzip filter: handling of empty flush buffers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
818 if (b == NULL) { |
93dd50a9dc70
Gzip filter: handling of empty flush buffers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
819 return NGX_ERROR; |
93dd50a9dc70
Gzip filter: handling of empty flush buffers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
820 } |
93dd50a9dc70
Gzip filter: handling of empty flush buffers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
821 |
93dd50a9dc70
Gzip filter: handling of empty flush buffers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
822 } else { |
93dd50a9dc70
Gzip filter: handling of empty flush buffers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
823 ctx->zstream.avail_out = 0; |
93dd50a9dc70
Gzip filter: handling of empty flush buffers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
824 } |
93dd50a9dc70
Gzip filter: handling of empty flush buffers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
825 |
93dd50a9dc70
Gzip filter: handling of empty flush buffers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
826 b->flush = 1; |
93dd50a9dc70
Gzip filter: handling of empty flush buffers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
827 |
93dd50a9dc70
Gzip filter: handling of empty flush buffers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4412
diff
changeset
|
828 cl->buf = b; |
2291
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
829 cl->next = NULL; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
830 *ctx->last_out = cl; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
831 ctx->last_out = &cl->next; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
832 |
5291
84155a389bcc
Gzip: clearing of c->buffered if all data are flushed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5107
diff
changeset
|
833 r->connection->buffered &= ~NGX_HTTP_GZIP_BUFFERED; |
84155a389bcc
Gzip: clearing of c->buffered if all data are flushed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5107
diff
changeset
|
834 |
2291
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 { |
7534
ac5a741d39cf
Gzip: use zlib to write header and trailer.
Ilya Leoshkevich <iii@linux.ibm.com>
parents:
7155
diff
changeset
|
872 int rc; |
7545
0ef2bc0ec9c9
Gzip: fixed "zero size buf" alerts after ac5a741d39cf.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7534
diff
changeset
|
873 ngx_buf_t *b; |
7534
ac5a741d39cf
Gzip: use zlib to write header and trailer.
Ilya Leoshkevich <iii@linux.ibm.com>
parents:
7155
diff
changeset
|
874 ngx_chain_t *cl; |
2291
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
875 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
876 ctx->zin = ctx->zstream.total_in; |
7534
ac5a741d39cf
Gzip: use zlib to write header and trailer.
Ilya Leoshkevich <iii@linux.ibm.com>
parents:
7155
diff
changeset
|
877 ctx->zout = ctx->zstream.total_out; |
2291
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
878 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
879 rc = deflateEnd(&ctx->zstream); |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
880 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
881 if (rc != Z_OK) { |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
882 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
|
883 "deflateEnd() failed: %d", rc); |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
884 return NGX_ERROR; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
885 } |
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 ngx_pfree(r->pool, ctx->preallocated); |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
888 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
889 cl = ngx_alloc_chain_link(r->pool); |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
890 if (cl == NULL) { |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
891 return NGX_ERROR; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
892 } |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
893 |
7545
0ef2bc0ec9c9
Gzip: fixed "zero size buf" alerts after ac5a741d39cf.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7534
diff
changeset
|
894 b = ctx->out_buf; |
0ef2bc0ec9c9
Gzip: fixed "zero size buf" alerts after ac5a741d39cf.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7534
diff
changeset
|
895 |
0ef2bc0ec9c9
Gzip: fixed "zero size buf" alerts after ac5a741d39cf.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7534
diff
changeset
|
896 if (ngx_buf_size(b) == 0) { |
0ef2bc0ec9c9
Gzip: fixed "zero size buf" alerts after ac5a741d39cf.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7534
diff
changeset
|
897 b->temporary = 0; |
0ef2bc0ec9c9
Gzip: fixed "zero size buf" alerts after ac5a741d39cf.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7534
diff
changeset
|
898 } |
0ef2bc0ec9c9
Gzip: fixed "zero size buf" alerts after ac5a741d39cf.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7534
diff
changeset
|
899 |
0ef2bc0ec9c9
Gzip: fixed "zero size buf" alerts after ac5a741d39cf.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7534
diff
changeset
|
900 b->last_buf = 1; |
0ef2bc0ec9c9
Gzip: fixed "zero size buf" alerts after ac5a741d39cf.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7534
diff
changeset
|
901 |
0ef2bc0ec9c9
Gzip: fixed "zero size buf" alerts after ac5a741d39cf.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7534
diff
changeset
|
902 cl->buf = b; |
2291
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
903 cl->next = NULL; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
904 *ctx->last_out = cl; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
905 ctx->last_out = &cl->next; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
906 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
907 ctx->zstream.avail_in = 0; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
908 ctx->zstream.avail_out = 0; |
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 ctx->done = 1; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
911 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
912 r->connection->buffered &= ~NGX_HTTP_GZIP_BUFFERED; |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
913 |
e9a1cddf2aaa
*) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents:
2290
diff
changeset
|
914 return NGX_OK; |
133
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
915 } |
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
916 |
b27548f540ad
nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
917 |
497 | 918 static void * |
919 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
|
920 { |
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
921 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
|
922 |
294
5cfd65b8b0a7
nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
923 void *p; |
5cfd65b8b0a7
nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
292
diff
changeset
|
924 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
|
925 |
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
926 alloc = items * size; |
461 | 927 |
7155
29e9571b1989
Gzip: support for a zlib variant from Intel.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7033
diff
changeset
|
928 if (items == 1 && 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
|
929 |
346
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
344
diff
changeset
|
930 /* |
461 | 931 * The zlib deflate_state allocation, it takes about 6K, |
932 * 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
|
933 */ |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
934 |
2425
3d60d55b9ad0
do not try to align to a page size, allocate just 8K,
Igor Sysoev <igor@sysoev.ru>
parents:
2412
diff
changeset
|
935 alloc = 8192; |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
936 } |
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
937 |
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
938 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
|
939 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
|
940 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
|
941 ctx->allocated -= alloc; |
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
942 |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
243
diff
changeset
|
943 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, ctx->request->connection->log, 0, |
6480 | 944 "gzip alloc: n:%ud s:%ud a:%ui p:%p", |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
243
diff
changeset
|
945 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
|
946 |
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
947 return p; |
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
948 } |
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
949 |
8392
1f3d0d9f893f
Gzip: support for zlib-ng.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7545
diff
changeset
|
950 if (ctx->zlib_ng) { |
7155
29e9571b1989
Gzip: support for a zlib variant from Intel.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7033
diff
changeset
|
951 ngx_log_error(NGX_LOG_ALERT, ctx->request->connection->log, 0, |
29e9571b1989
Gzip: support for a zlib variant from Intel.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7033
diff
changeset
|
952 "gzip filter failed to use preallocated memory: " |
29e9571b1989
Gzip: support for a zlib variant from Intel.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7033
diff
changeset
|
953 "%ud of %ui", items * size, ctx->allocated); |
29e9571b1989
Gzip: support for a zlib variant from Intel.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7033
diff
changeset
|
954 |
8393
c297c2c252d8
Gzip: updated handling of zlib variant from Intel.
Maxim Dounin <mdounin@mdounin.ru>
parents:
8392
diff
changeset
|
955 } else { |
8392
1f3d0d9f893f
Gzip: support for zlib-ng.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7545
diff
changeset
|
956 ngx_http_gzip_assume_zlib_ng = 1; |
7155
29e9571b1989
Gzip: support for a zlib variant from Intel.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7033
diff
changeset
|
957 } |
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 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
|
960 |
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
961 return p; |
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
962 } |
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 |
497 | 965 static void |
966 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
|
967 { |
282
30310107dbc9
nginx-0.0.2-2004-03-09-22:47:07 import
Igor Sysoev <igor@sysoev.ru>
parents:
265
diff
changeset
|
968 #if 0 |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
969 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
|
970 |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
243
diff
changeset
|
971 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ctx->request->connection->log, 0, |
461 | 972 "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
|
973 #endif |
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 |
2410
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
977 static void |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
978 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
|
979 ngx_http_gzip_ctx_t *ctx) |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
980 { |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
981 ngx_chain_t *cl; |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
982 |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
983 for (cl = ctx->copied; cl; cl = cl->next) { |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
984 ngx_pfree(r->pool, cl->buf->start); |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
985 } |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
986 |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
987 ctx->copied = NULL; |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
988 } |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
989 |
bbfaeb220e90
postpone zlib memory allocation
Igor Sysoev <igor@sysoev.ru>
parents:
2292
diff
changeset
|
990 |
497 | 991 static ngx_int_t |
573 | 992 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
|
993 { |
880 | 994 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
|
995 |
583 | 996 var = ngx_http_add_variable(cf, &ngx_http_gzip_ratio, NGX_HTTP_VAR_NOHASH); |
573 | 997 if (var == NULL) { |
998 return NGX_ERROR; | |
999 } | |
1000 | |
637 | 1001 var->get_handler = ngx_http_gzip_ratio_variable; |
573 | 1002 |
177
4db54fdbcbe7
nginx-0.0.1-2003-11-10-20:17:31 import
Igor Sysoev <igor@sysoev.ru>
parents:
166
diff
changeset
|
1003 return NGX_OK; |
4db54fdbcbe7
nginx-0.0.1-2003-11-10-20:17:31 import
Igor Sysoev <igor@sysoev.ru>
parents:
166
diff
changeset
|
1004 } |
4db54fdbcbe7
nginx-0.0.1-2003-11-10-20:17:31 import
Igor Sysoev <igor@sysoev.ru>
parents:
166
diff
changeset
|
1005 |
4db54fdbcbe7
nginx-0.0.1-2003-11-10-20:17:31 import
Igor Sysoev <igor@sysoev.ru>
parents:
166
diff
changeset
|
1006 |
497 | 1007 static ngx_int_t |
573 | 1008 ngx_http_gzip_ratio_variable(ngx_http_request_t *r, |
1009 ngx_http_variable_value_t *v, uintptr_t data) | |
1010 { | |
1011 ngx_uint_t zint, zfrac; | |
1012 ngx_http_gzip_ctx_t *ctx; | |
1013 | |
1014 ctx = ngx_http_get_module_ctx(r, ngx_http_gzip_filter_module); | |
1015 | |
1016 if (ctx == NULL || ctx->zout == 0) { | |
1017 v->not_found = 1; | |
1018 return NGX_OK; | |
1019 } | |
1020 | |
7033
ab5117642647
Gzip: fixed style in $gzip_ratio variable handler.
Ruslan Ermilov <ru@nginx.com>
parents:
6973
diff
changeset
|
1021 v->valid = 1; |
ab5117642647
Gzip: fixed style in $gzip_ratio variable handler.
Ruslan Ermilov <ru@nginx.com>
parents:
6973
diff
changeset
|
1022 v->no_cacheable = 0; |
ab5117642647
Gzip: fixed style in $gzip_ratio variable handler.
Ruslan Ermilov <ru@nginx.com>
parents:
6973
diff
changeset
|
1023 v->not_found = 0; |
ab5117642647
Gzip: fixed style in $gzip_ratio variable handler.
Ruslan Ermilov <ru@nginx.com>
parents:
6973
diff
changeset
|
1024 |
2049 | 1025 v->data = ngx_pnalloc(r->pool, NGX_INT32_LEN + 3); |
573 | 1026 if (v->data == NULL) { |
1027 return NGX_ERROR; | |
1028 } | |
1029 | |
1030 zint = (ngx_uint_t) (ctx->zin / ctx->zout); | |
1031 zfrac = (ngx_uint_t) ((ctx->zin * 100 / ctx->zout) % 100); | |
1032 | |
1033 if ((ctx->zin * 1000 / ctx->zout) % 10 > 4) { | |
1034 | |
1035 /* the rounding, e.g., 2.125 to 2.13 */ | |
1036 | |
1037 zfrac++; | |
1038 | |
1039 if (zfrac > 99) { | |
1040 zint++; | |
1041 zfrac = 0; | |
1042 } | |
1043 } | |
1044 | |
1045 v->len = ngx_sprintf(v->data, "%ui.%02ui", zint, zfrac) - v->data; | |
1046 | |
1047 return NGX_OK; | |
1048 } | |
1049 | |
1050 | |
497 | 1051 static void * |
1052 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
|
1053 { |
d57c6835225c
nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
1054 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
|
1055 |
501 | 1056 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_gzip_conf_t)); |
1057 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
|
1058 return NULL; |
430
1fa5daf7558e
nginx-0.0.11-2004-09-19-22:27:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
416
diff
changeset
|
1059 } |
134
d57c6835225c
nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
1060 |
430
1fa5daf7558e
nginx-0.0.11-2004-09-19-22:27:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
416
diff
changeset
|
1061 /* |
479 | 1062 * set by ngx_pcalloc(): |
1063 * | |
1064 * 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
|
1065 * conf->types = { NULL }; |
723df5089c05
use hash in gzip_types, ssi_types, and sub_filter_types
Igor Sysoev <igor@sysoev.ru>
parents:
2051
diff
changeset
|
1066 * 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
|
1067 */ |
320
d621239c30f7
nginx-0.0.3-2004-04-18-23:06:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
319
diff
changeset
|
1068 |
134
d57c6835225c
nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
1069 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
|
1070 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
|
1071 |
2542
925b5df2e0c2
fix postponed zlib memory allocation, introduced in r2411
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1072 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
|
1073 conf->level = NGX_CONF_UNSET; |
2542
925b5df2e0c2
fix postponed zlib memory allocation, introduced in r2411
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1074 conf->wbits = NGX_CONF_UNSET_SIZE; |
925b5df2e0c2
fix postponed zlib memory allocation, introduced in r2411
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1075 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
|
1076 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
|
1077 |
d57c6835225c
nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
1078 return conf; |
d57c6835225c
nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
1079 } |
d57c6835225c
nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
1080 |
d57c6835225c
nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
1081 |
497 | 1082 static char * |
1083 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
|
1084 { |
d57c6835225c
nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
1085 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
|
1086 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
|
1087 |
d57c6835225c
nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
133
diff
changeset
|
1088 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
|
1089 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
|
1090 |
2412
086c20fe2e97
set default gzip_buffers to 32 4k or 16 8k
Igor Sysoev <igor@sysoev.ru>
parents:
2410
diff
changeset
|
1091 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
|
1092 (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
|
1093 |
2542
925b5df2e0c2
fix postponed zlib memory allocation, introduced in r2411
Igor Sysoev <igor@sysoev.ru>
parents:
2536
diff
changeset
|
1094 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
|
1095 0); |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
1096 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
|
1097 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
|
1098 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
|
1099 MAX_MEM_LEVEL - 1); |
577 | 1100 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
|
1101 |
3372
6b8e5c882e47
support "*" in gzip_types, ssi_types, etc
Igor Sysoev <igor@sysoev.ru>
parents:
3314
diff
changeset
|
1102 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
|
1103 &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
|
1104 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
|
1105 != NGX_OK) |
723df5089c05
use hash in gzip_types, ssi_types, and sub_filter_types
Igor Sysoev <igor@sysoev.ru>
parents:
2051
diff
changeset
|
1106 { |
723df5089c05
use hash in gzip_types, ssi_types, and sub_filter_types
Igor Sysoev <igor@sysoev.ru>
parents:
2051
diff
changeset
|
1107 return NGX_CONF_ERROR; |
452 | 1108 } |
1109 | |
1110 return NGX_CONF_OK; | |
1111 } | |
1112 | |
1113 | |
681 | 1114 static ngx_int_t |
1115 ngx_http_gzip_filter_init(ngx_conf_t *cf) | |
1116 { | |
1117 ngx_http_next_header_filter = ngx_http_top_header_filter; | |
1118 ngx_http_top_header_filter = ngx_http_gzip_header_filter; | |
1119 | |
1120 ngx_http_next_body_filter = ngx_http_top_body_filter; | |
1121 ngx_http_top_body_filter = ngx_http_gzip_body_filter; | |
1122 | |
1123 return NGX_OK; | |
1124 } | |
1125 | |
1126 | |
497 | 1127 static char * |
527 | 1128 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
|
1129 { |
2290 | 1130 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
|
1131 |
2290 | 1132 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
|
1133 |
430
1fa5daf7558e
nginx-0.0.11-2004-09-19-22:27:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
416
diff
changeset
|
1134 wbits = 15; |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
1135 |
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
1136 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
|
1137 |
158
d377ee423603
nginx-0.0.1-2003-10-24-10:53:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
157
diff
changeset
|
1138 if (wsize == *np) { |
d377ee423603
nginx-0.0.1-2003-10-24-10:53:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
157
diff
changeset
|
1139 *np = wbits; |
430
1fa5daf7558e
nginx-0.0.11-2004-09-19-22:27:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
416
diff
changeset
|
1140 |
1fa5daf7558e
nginx-0.0.11-2004-09-19-22:27:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
416
diff
changeset
|
1141 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
|
1142 } |
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
1143 |
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
1144 wbits--; |
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
1145 } |
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
1146 |
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
1147 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
|
1148 } |
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
1149 |
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
1150 |
497 | 1151 static char * |
527 | 1152 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
|
1153 { |
2290 | 1154 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
|
1155 |
2290 | 1156 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
|
1157 |
430
1fa5daf7558e
nginx-0.0.11-2004-09-19-22:27:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
416
diff
changeset
|
1158 memlevel = 9; |
156
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
1159 |
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
1160 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
|
1161 |
158
d377ee423603
nginx-0.0.1-2003-10-24-10:53:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
157
diff
changeset
|
1162 if (hsize == *np) { |
d377ee423603
nginx-0.0.1-2003-10-24-10:53:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
157
diff
changeset
|
1163 *np = memlevel; |
430
1fa5daf7558e
nginx-0.0.11-2004-09-19-22:27:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
416
diff
changeset
|
1164 |
1fa5daf7558e
nginx-0.0.11-2004-09-19-22:27:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
416
diff
changeset
|
1165 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
|
1166 } |
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
1167 |
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
1168 memlevel--; |
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
1169 } |
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
1170 |
afc333135a6b
nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
1171 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
|
1172 } |