annotate src/http/modules/ngx_http_gzip_filter_module.c @ 2410:bbfaeb220e90

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