annotate src/http/modules/ngx_http_gzip_filter_module.c @ 2292:51487a60eba2

fix the previous commit
author Igor Sysoev <igor@sysoev.ru>
date Thu, 06 Nov 2008 19:54:54 +0000
parents e9a1cddf2aaa
children bbfaeb220e90
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;
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
37 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
38 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
39 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
40
afc333135a6b nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
41 off_t length;
134
d57c6835225c nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 133
diff changeset
42
156
afc333135a6b nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
43 void *preallocated;
afc333135a6b nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
44 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
45 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
46
156
afc333135a6b nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
47 unsigned flush:4;
afc333135a6b nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
48 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
49 unsigned done:1;
2287
baa61933d5ed use nomem flag to flush busy bufs,
Igor Sysoev <igor@sysoev.ru>
parents: 2166
diff changeset
50 unsigned nomem:1;
2291
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
51 unsigned gzheader:1;
177
4db54fdbcbe7 nginx-0.0.1-2003-11-10-20:17:31 import
Igor Sysoev <igor@sysoev.ru>
parents: 166
diff changeset
52
4db54fdbcbe7 nginx-0.0.1-2003-11-10-20:17:31 import
Igor Sysoev <igor@sysoev.ru>
parents: 166
diff changeset
53 size_t zin;
4db54fdbcbe7 nginx-0.0.1-2003-11-10-20:17:31 import
Igor Sysoev <igor@sysoev.ru>
parents: 166
diff changeset
54 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
55
290
87e73f067470 nginx-0.0.2-2004-03-16-10:10:12 import
Igor Sysoev <igor@sysoev.ru>
parents: 289
diff changeset
56 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
57 z_stream zstream;
afc333135a6b nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
58 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
59 } 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
60
b27548f540ad nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
61
2291
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
62 #if (NGX_HAVE_LITTLE_ENDIAN && NGX_HAVE_NONALIGNED)
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
63
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
64 struct gztrailer {
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
65 uint32_t crc32;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
66 uint32_t zlen;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
67 };
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
68
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
69 #else /* NGX_HAVE_BIG_ENDIAN || !NGX_HAVE_NONALIGNED */
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
70
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
71 struct gztrailer {
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
72 u_char crc32[4];
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
73 u_char zlen[4];
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
74 };
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
75
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
76 #endif
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
77
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
78
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
79 static ngx_int_t ngx_http_gzip_filter_deflate_start(ngx_http_request_t *r,
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
80 ngx_http_gzip_ctx_t *ctx);
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
81 static ngx_int_t ngx_http_gzip_filter_gzheader(ngx_http_request_t *r,
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
82 ngx_http_gzip_ctx_t *ctx);
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
83 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
84 ngx_http_gzip_ctx_t *ctx);
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
85 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
86 ngx_http_gzip_ctx_t *ctx);
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
87 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
88 ngx_http_gzip_ctx_t *ctx);
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_end(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
156
afc333135a6b nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
92 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
93 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
94 static void ngx_http_gzip_filter_free(void *opaque, void *address);
177
4db54fdbcbe7 nginx-0.0.1-2003-11-10-20:17:31 import
Igor Sysoev <igor@sysoev.ru>
parents: 166
diff changeset
95
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 553
diff changeset
96 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
97 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
98 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
99
681
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 663
diff changeset
100 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
101 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
102 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
103 void *parent, void *child);
527
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 513
diff changeset
104 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
105 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
106
156
afc333135a6b nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
107
158
d377ee423603 nginx-0.0.1-2003-10-24-10:53:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 157
diff changeset
108 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
109 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
110 };
d377ee423603 nginx-0.0.1-2003-10-24-10:53:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 157
diff changeset
111
527
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 513
diff changeset
112 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
113 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
114
134
d57c6835225c nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 133
diff changeset
115
d57c6835225c nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 133
diff changeset
116 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
117
239
574bea0142be nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 177
diff changeset
118 { ngx_string("gzip"),
485
4ebe09b07e30 nginx-0.1.17-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 483
diff changeset
119 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
120 |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
121 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
122 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
123 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
124 NULL },
134
d57c6835225c nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 133
diff changeset
125
239
574bea0142be nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 177
diff changeset
126 { 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
127 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
128 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
129 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
130 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
131 NULL },
134
d57c6835225c nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 133
diff changeset
132
452
23fb87bddda1 nginx-0.1.1-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 444
diff changeset
133 { ngx_string("gzip_types"),
23fb87bddda1 nginx-0.1.1-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 444
diff changeset
134 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
135 ngx_http_types_slot,
452
23fb87bddda1 nginx-0.1.1-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 444
diff changeset
136 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
137 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
138 &ngx_http_html_default_types[0] },
452
23fb87bddda1 nginx-0.1.1-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 444
diff changeset
139
239
574bea0142be nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 177
diff changeset
140 { 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
141 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
142 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
143 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
144 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
145 &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
146
239
574bea0142be nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 177
diff changeset
147 { 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
148 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
149 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
150 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
151 offsetof(ngx_http_gzip_conf_t, wbits),
527
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 513
diff changeset
152 &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
153
239
574bea0142be nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 177
diff changeset
154 { 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
155 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
156 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
157 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
158 offsetof(ngx_http_gzip_conf_t, memlevel),
527
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 513
diff changeset
159 &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
160
239
574bea0142be nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 177
diff changeset
161 { 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
162 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
163 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
164 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
165 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
166 NULL },
134
d57c6835225c nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 133
diff changeset
167
320
d621239c30f7 nginx-0.0.3-2004-04-18-23:06:02 import
Igor Sysoev <igor@sysoev.ru>
parents: 319
diff changeset
168 { 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
169 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
170 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
171 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
172 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
173 NULL },
314
d71c87d11b16 nginx-0.0.3-2004-04-14-09:57:36 import
Igor Sysoev <igor@sysoev.ru>
parents: 294
diff changeset
174
239
574bea0142be nginx-0.0.1-2004-01-26-11:52:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 177
diff changeset
175 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
176 };
133
b27548f540ad nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
177
b27548f540ad nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
178
b27548f540ad nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
179 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
180 ngx_http_gzip_add_variables, /* preconfiguration */
681
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 663
diff changeset
181 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
182
133
b27548f540ad nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
183 NULL, /* create main configuration */
b27548f540ad nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
184 NULL, /* init main configuration */
b27548f540ad nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
185
b27548f540ad nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
186 NULL, /* create server configuration */
b27548f540ad nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
187 NULL, /* merge server configuration */
b27548f540ad nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
188
134
d57c6835225c nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 133
diff changeset
189 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
190 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
191 };
b27548f540ad nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
192
b27548f540ad nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
193
b27548f540ad nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
194 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
195 NGX_MODULE_V1,
133
b27548f540ad nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
196 &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
197 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
198 NGX_HTTP_MODULE, /* module type */
541
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
199 NULL, /* init master */
681
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 663
diff changeset
200 NULL, /* init module */
541
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
201 NULL, /* init process */
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
202 NULL, /* init thread */
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
203 NULL, /* exit thread */
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
204 NULL, /* exit process */
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
205 NULL, /* exit master */
b09ee85d0ac8 nginx-0.1.45-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 529
diff changeset
206 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
207 };
b27548f540ad nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
208
b27548f540ad nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
209
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 553
diff changeset
210 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
211
155
46eb23d9471d nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents: 154
diff changeset
212 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
213 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
214
b27548f540ad nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
215
497
d7c90bb5ce83 nginx-0.1.23-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 489
diff changeset
216 static ngx_int_t
d7c90bb5ce83 nginx-0.1.23-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 489
diff changeset
217 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
218 {
2051
115e6f029fcc "gzip_vary on" always sends "Vary: Accept-Encoding" header
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
219 ngx_table_elt_t *h;
115e6f029fcc "gzip_vary on" always sends "Vary: Accept-Encoding" header
Igor Sysoev <igor@sysoev.ru>
parents: 2049
diff changeset
220 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
221 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
222
135
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents: 134
diff changeset
223 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
224
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents: 134
diff changeset
225 if (!conf->enable
452
23fb87bddda1 nginx-0.1.1-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 444
diff changeset
226 || (r->headers_out.status != NGX_HTTP_OK
23fb87bddda1 nginx-0.1.1-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 444
diff changeset
227 && r->headers_out.status != NGX_HTTP_FORBIDDEN
23fb87bddda1 nginx-0.1.1-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 444
diff changeset
228 && 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
229 || 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
230 || (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
231 && 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
232 || (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
233 && 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
234 || 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
235 || 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
236 {
155
46eb23d9471d nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents: 154
diff changeset
237 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
238 }
d57c6835225c nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 133
diff changeset
239
501
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 497
diff changeset
240 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
241 if (ctx == NULL) {
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 497
diff changeset
242 return NGX_ERROR;
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 497
diff changeset
243 }
314
d71c87d11b16 nginx-0.0.3-2004-04-14-09:57:36 import
Igor Sysoev <igor@sysoev.ru>
parents: 294
diff changeset
244
501
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 497
diff changeset
245 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
246
156
afc333135a6b nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
247 ctx->request = r;
133
b27548f540ad nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
248
1790
775edc46ee66 ngx_http_gzip_static_module and gzip_disable
Igor Sysoev <igor@sysoev.ru>
parents: 1626
diff changeset
249 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
250 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
251 return NGX_ERROR;
84036764e215 nginx-0.0.1-2003-10-29-11:30:44 import
Igor Sysoev <igor@sysoev.ru>
parents: 160
diff changeset
252 }
135
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents: 134
diff changeset
253
1790
775edc46ee66 ngx_http_gzip_static_module and gzip_disable
Igor Sysoev <igor@sysoev.ru>
parents: 1626
diff changeset
254 h->hash = 1;
775edc46ee66 ngx_http_gzip_static_module and gzip_disable
Igor Sysoev <igor@sysoev.ru>
parents: 1626
diff changeset
255 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
256 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
257 h->value.len = sizeof("gzip") - 1;
775edc46ee66 ngx_http_gzip_static_module and gzip_disable
Igor Sysoev <igor@sysoev.ru>
parents: 1626
diff changeset
258 h->value.data = (u_char *) "gzip";
1583
45cbc1aa8652 gzip_vary
Igor Sysoev <igor@sysoev.ru>
parents: 1565
diff changeset
259
1790
775edc46ee66 ngx_http_gzip_static_module and gzip_disable
Igor Sysoev <igor@sysoev.ru>
parents: 1626
diff changeset
260 r->headers_out.content_encoding = h;
775edc46ee66 ngx_http_gzip_static_module and gzip_disable
Igor Sysoev <igor@sysoev.ru>
parents: 1626
diff changeset
261
153
c71aeb75c071 nginx-0.0.1-2003-10-21-20:49:56 import
Igor Sysoev <igor@sysoev.ru>
parents: 144
diff changeset
262 ctx->length = r->headers_out.content_length_n;
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 501
diff changeset
263
513
fbbf16224844 nginx-0.1.31-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
264 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
265
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
266 ngx_http_clear_content_length(r);
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
267 ngx_http_clear_accept_ranges(r);
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
268
155
46eb23d9471d nginx-0.0.1-2003-10-22-20:38:26 import
Igor Sysoev <igor@sysoev.ru>
parents: 154
diff changeset
269 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
270 }
b27548f540ad nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
271
b27548f540ad nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
272
497
d7c90bb5ce83 nginx-0.1.23-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 489
diff changeset
273 static ngx_int_t
d7c90bb5ce83 nginx-0.1.23-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 489
diff changeset
274 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
275 {
2291
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
276 int rc;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
277 ngx_chain_t *cl;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
278 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
279
243
bf2faf694c19 nginx-0.0.1-2004-01-28-23:38:54 import
Igor Sysoev <igor@sysoev.ru>
parents: 239
diff changeset
280 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
281
243
bf2faf694c19 nginx-0.0.1-2004-01-28-23:38:54 import
Igor Sysoev <igor@sysoev.ru>
parents: 239
diff changeset
282 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
283 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
284 }
4db54fdbcbe7 nginx-0.0.1-2003-11-10-20:17:31 import
Igor Sysoev <igor@sysoev.ru>
parents: 166
diff changeset
285
156
afc333135a6b nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
286 if (ctx->preallocated == NULL) {
2291
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
287 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
288 goto failed;
430
1fa5daf7558e nginx-0.0.11-2004-09-19-22:27:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 416
diff changeset
289 }
133
b27548f540ad nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
290 }
b27548f540ad nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
291
b27548f540ad nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
292 if (in) {
134
d57c6835225c nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 133
diff changeset
293 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
294 goto failed;
134
d57c6835225c nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 133
diff changeset
295 }
133
b27548f540ad nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
296 }
b27548f540ad nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
297
2287
baa61933d5ed use nomem flag to flush busy bufs,
Igor Sysoev <igor@sysoev.ru>
parents: 2166
diff changeset
298 if (ctx->nomem) {
2291
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
299
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
300 /* flush busy buffers */
2287
baa61933d5ed use nomem flag to flush busy bufs,
Igor Sysoev <igor@sysoev.ru>
parents: 2166
diff changeset
301
baa61933d5ed use nomem flag to flush busy bufs,
Igor Sysoev <igor@sysoev.ru>
parents: 2166
diff changeset
302 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
303 goto failed;
2287
baa61933d5ed use nomem flag to flush busy bufs,
Igor Sysoev <igor@sysoev.ru>
parents: 2166
diff changeset
304 }
baa61933d5ed use nomem flag to flush busy bufs,
Igor Sysoev <igor@sysoev.ru>
parents: 2166
diff changeset
305
baa61933d5ed use nomem flag to flush busy bufs,
Igor Sysoev <igor@sysoev.ru>
parents: 2166
diff changeset
306 cl = NULL;
baa61933d5ed use nomem flag to flush busy bufs,
Igor Sysoev <igor@sysoev.ru>
parents: 2166
diff changeset
307
baa61933d5ed use nomem flag to flush busy bufs,
Igor Sysoev <igor@sysoev.ru>
parents: 2166
diff changeset
308 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
309 (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
310 ctx->nomem = 0;
baa61933d5ed use nomem flag to flush busy bufs,
Igor Sysoev <igor@sysoev.ru>
parents: 2166
diff changeset
311 }
141
656d468f4ead nginx-0.0.1-2003-10-08-19:32:54 import
Igor Sysoev <igor@sysoev.ru>
parents: 136
diff changeset
312
135
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents: 134
diff changeset
313 for ( ;; ) {
e29909bd9b8a nginx-0.0.1-2003-09-28-23:29:06 import
Igor Sysoev <igor@sysoev.ru>
parents: 134
diff changeset
314
2291
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
315 /* cycle while we can write to a client */
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
316
133
b27548f540ad nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
317 for ( ;; ) {
b27548f540ad nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
318
2291
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
319 /* 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
320
2291
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
321 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
322
2291
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
323 if (rc == NGX_DECLINED) {
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
324 break;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
325 }
133
b27548f540ad nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
326
2291
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
327 if (rc == NGX_AGAIN) {
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
328 continue;
133
b27548f540ad nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
329 }
b27548f540ad nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
330
430
1fa5daf7558e nginx-0.0.11-2004-09-19-22:27:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 416
diff changeset
331
2291
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
332 /* ... 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
333
2291
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
334 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
335
2291
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
336 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
337 break;
ba876b26b76d nginx-0.0.3-2004-04-21-22:54:33 import
Igor Sysoev <igor@sysoev.ru>
parents: 322
diff changeset
338 }
ba876b26b76d nginx-0.0.3-2004-04-21-22:54:33 import
Igor Sysoev <igor@sysoev.ru>
parents: 322
diff changeset
339
2291
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
340 if (rc == NGX_ERROR) {
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
341 goto failed;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
342 }
134
d57c6835225c nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 133
diff changeset
343
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
344
2291
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
345 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
346
2291
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
347 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
348 break;
ba876b26b76d nginx-0.0.3-2004-04-21-22:54:33 import
Igor Sysoev <igor@sysoev.ru>
parents: 322
diff changeset
349 }
133
b27548f540ad nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
350
2291
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
351 if (rc == NGX_ERROR) {
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
352 goto failed;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
353 }
501
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 497
diff changeset
354
2291
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
355 /* rc == NGX_AGAIN */
133
b27548f540ad nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
356 }
b27548f540ad nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
357
1626
7caa66b819df fix gzip and SSL
Igor Sysoev <igor@sysoev.ru>
parents: 1583
diff changeset
358 if (ctx->out == NULL) {
2292
51487a60eba2 fix the previous commit
Igor Sysoev <igor@sysoev.ru>
parents: 2291
diff changeset
359 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
360 }
1fa5daf7558e nginx-0.0.11-2004-09-19-22:27:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 416
diff changeset
361
2291
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
362 if (!ctx->gzheader) {
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
363 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
364 goto failed;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
365 }
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
366 }
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
367
2287
baa61933d5ed use nomem flag to flush busy bufs,
Igor Sysoev <igor@sysoev.ru>
parents: 2166
diff changeset
368 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
369
2287
baa61933d5ed use nomem flag to flush busy bufs,
Igor Sysoev <igor@sysoev.ru>
parents: 2166
diff changeset
370 if (rc == NGX_ERROR) {
2291
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
371 goto failed;
133
b27548f540ad nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
372 }
b27548f540ad nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
373
154
eac26585476e nginx-0.0.1-2003-10-22-11:05:29 import
Igor Sysoev <igor@sysoev.ru>
parents: 153
diff changeset
374 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
375 (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
376 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
377
2287
baa61933d5ed use nomem flag to flush busy bufs,
Igor Sysoev <igor@sysoev.ru>
parents: 2166
diff changeset
378 ctx->nomem = 0;
baa61933d5ed use nomem flag to flush busy bufs,
Igor Sysoev <igor@sysoev.ru>
parents: 2166
diff changeset
379
327
e0f3f238db09 nginx-0.0.3-2004-04-26-17:40:01 import
Igor Sysoev <igor@sysoev.ru>
parents: 326
diff changeset
380 if (ctx->done) {
2287
baa61933d5ed use nomem flag to flush busy bufs,
Igor Sysoev <igor@sysoev.ru>
parents: 2166
diff changeset
381 return rc;
327
e0f3f238db09 nginx-0.0.3-2004-04-26-17:40:01 import
Igor Sysoev <igor@sysoev.ru>
parents: 326
diff changeset
382 }
133
b27548f540ad nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
383 }
2291
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
384
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
385 /* unreachable */
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
386
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
387 failed:
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
388
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
389 ctx->done = 1;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
390
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
391 if (ctx->preallocated) {
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
392 deflateEnd(&ctx->zstream);
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
393
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
394 ngx_pfree(r->pool, ctx->preallocated);
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
395 }
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
396
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
397 return NGX_ERROR;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
398 }
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
399
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
400
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
401 static ngx_int_t
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
402 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
403 ngx_http_gzip_ctx_t *ctx)
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 int rc, wbits, memlevel;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
406 ngx_http_gzip_conf_t *conf;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
407
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
408 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
409
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
410 wbits = conf->wbits;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
411 memlevel = conf->memlevel;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
412
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
413 if (ctx->length > 0) {
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
414
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
415 /* 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
416
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
417 while (ctx->length < ((1 << (wbits - 1)) - 262)) {
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
418 wbits--;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
419 memlevel--;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
420 }
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
421 }
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
422
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
423 /*
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
424 * 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
425 * 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
426 * 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
427 * 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
428 * 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
429 *
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
430 * 8K is for zlib deflate_state, it takes
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
431 * *) 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
432 * *) 5920 bytes on amd64 and sparc64
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
433 */
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 ctx->allocated = 8192 + (1 << (wbits + 2)) + (1 << (memlevel + 9));
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 ctx->preallocated = ngx_palloc(r->pool, ctx->allocated);
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
438 if (ctx->preallocated == NULL) {
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
439 return NGX_ERROR;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
440 }
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
441
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
442 ctx->free_mem = ctx->preallocated;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
443
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
444 ctx->zstream.zalloc = ngx_http_gzip_filter_alloc;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
445 ctx->zstream.zfree = ngx_http_gzip_filter_free;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
446 ctx->zstream.opaque = ctx;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
447
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
448 rc = deflateInit2(&ctx->zstream, (int) conf->level, Z_DEFLATED,
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
449 -wbits, memlevel, Z_DEFAULT_STRATEGY);
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
450
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
451 if (rc != Z_OK) {
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
452 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
453 "deflateInit2() failed: %d", rc);
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
454 return NGX_ERROR;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
455 }
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 r->connection->buffered |= NGX_HTTP_GZIP_BUFFERED;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
458
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
459 ctx->last_out = &ctx->out;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
460 ctx->crc32 = crc32(0L, Z_NULL, 0);
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
461 ctx->flush = Z_NO_FLUSH;
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 return NGX_OK;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
464 }
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
465
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
466
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
467 static ngx_int_t
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
468 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
469 {
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
470 ngx_buf_t *b;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
471 ngx_chain_t *cl;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
472 static u_char gzheader[10] =
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
473 { 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
474
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
475 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
476 if (b == NULL) {
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
477 return NGX_ERROR;
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 b->memory = 1;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
481 b->pos = gzheader;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
482 b->last = b->pos + 10;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
483
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
484 cl = ngx_alloc_chain_link(r->pool);
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
485 if (cl == NULL) {
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
486 return NGX_ERROR;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
487 }
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
488
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
489 cl->buf = b;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
490 cl->next = ctx->out;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
491 ctx->out = cl;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
492
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
493 ctx->gzheader = 1;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
494
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
495 return NGX_OK;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
496 }
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
497
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
498
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
499 static ngx_int_t
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
500 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
501 {
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
502 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
503 return NGX_OK;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
504 }
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
505
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
506 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
507 "gzip in: %p", ctx->in);
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
508
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
509 if (ctx->in == NULL) {
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
510 return NGX_DECLINED;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
511 }
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
512
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
513 ctx->in_buf = ctx->in->buf;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
514 ctx->in = ctx->in->next;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
515
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
516 ctx->zstream.next_in = ctx->in_buf->pos;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
517 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
518
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
519 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
520 "gzip in_buf:%p ni:%p ai:%ud",
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
521 ctx->in_buf,
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
522 ctx->zstream.next_in, ctx->zstream.avail_in);
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
523
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
524 if (ctx->in_buf->last_buf) {
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
525 ctx->flush = Z_FINISH;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
526
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
527 } else if (ctx->in_buf->flush) {
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
528 ctx->flush = Z_SYNC_FLUSH;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
529 }
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
530
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
531 if (ctx->zstream.avail_in) {
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
532
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
533 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
534 ctx->zstream.avail_in);
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
535
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
536 } else if (ctx->flush == Z_NO_FLUSH) {
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
537 return NGX_AGAIN;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
538 }
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
539
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
540 return NGX_OK;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
541 }
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
542
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
543
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
544 static ngx_int_t
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
545 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
546 {
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
547 ngx_http_gzip_conf_t *conf;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
548
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
549 if (ctx->zstream.avail_out) {
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
550 return NGX_OK;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
551 }
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
552
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
553 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
554
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
555 if (ctx->free) {
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
556 ctx->out_buf = ctx->free->buf;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
557 ctx->free = ctx->free->next;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
558
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
559 } else if (ctx->bufs < conf->bufs.num) {
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
560
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
561 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
562 if (ctx->out_buf == NULL) {
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
563 return NGX_ERROR;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
564 }
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
565
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
566 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
567 ctx->out_buf->recycled = 1;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
568 ctx->bufs++;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
569
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
570 } else {
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
571 ctx->nomem = 1;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
572 return NGX_DECLINED;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
573 }
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
574
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
575 ctx->zstream.next_out = ctx->out_buf->pos;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
576 ctx->zstream.avail_out = conf->bufs.size;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
577
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
578 return NGX_OK;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
579 }
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
580
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
581
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
582 static ngx_int_t
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
583 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
584 {
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
585 int rc;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
586 ngx_chain_t *cl;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
587 ngx_http_gzip_conf_t *conf;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
588
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
589 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
590 "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
591 ctx->zstream.next_in, ctx->zstream.next_out,
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
592 ctx->zstream.avail_in, ctx->zstream.avail_out,
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
593 ctx->flush, ctx->redo);
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
594
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
595 rc = deflate(&ctx->zstream, ctx->flush);
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
596
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
597 if (rc != Z_OK && rc != Z_STREAM_END) {
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
598 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
599 "deflate() failed: %d, %d", ctx->flush, rc);
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
600 return NGX_ERROR;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
601 }
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
602
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
603 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
604 "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
605 ctx->zstream.next_in, ctx->zstream.next_out,
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
606 ctx->zstream.avail_in, ctx->zstream.avail_out,
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
607 rc);
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
608
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
609 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
610 "gzip in_buf:%p pos:%p",
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
611 ctx->in_buf, ctx->in_buf->pos);
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 if (ctx->zstream.next_in) {
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
614 ctx->in_buf->pos = ctx->zstream.next_in;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
615
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
616 if (ctx->zstream.avail_in == 0) {
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
617 ctx->zstream.next_in = NULL;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
618 }
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
619 }
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
620
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
621 ctx->out_buf->last = ctx->zstream.next_out;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
622
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
623 if (ctx->zstream.avail_out == 0) {
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
624
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
625 /* zlib wants to output some more gzipped data */
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
626
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
627 cl = ngx_alloc_chain_link(r->pool);
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
628 if (cl == NULL) {
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
629 return NGX_ERROR;
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 cl->buf = ctx->out_buf;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
633 cl->next = NULL;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
634 *ctx->last_out = cl;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
635 ctx->last_out = &cl->next;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
636
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
637 ctx->redo = 1;
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 return NGX_AGAIN;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
640 }
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 ctx->redo = 0;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
643
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
644 if (ctx->flush == Z_SYNC_FLUSH) {
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
645
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
646 ctx->zstream.avail_out = 0;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
647 ctx->out_buf->flush = 1;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
648 ctx->flush = Z_NO_FLUSH;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
649
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
650 cl = ngx_alloc_chain_link(r->pool);
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
651 if (cl == NULL) {
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
652 return NGX_ERROR;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
653 }
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
654
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
655 cl->buf = ctx->out_buf;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
656 cl->next = NULL;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
657 *ctx->last_out = cl;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
658 ctx->last_out = &cl->next;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
659
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
660 return NGX_OK;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
661 }
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
662
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
663 if (rc == Z_STREAM_END) {
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
664
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
665 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
666 return NGX_ERROR;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
667 }
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 return NGX_OK;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
670 }
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
671
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
672 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
673
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
674 if (conf->no_buffer && ctx->in == NULL) {
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
675
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
676 cl = ngx_alloc_chain_link(r->pool);
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
677 if (cl == NULL) {
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
678 return NGX_ERROR;
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 cl->buf = ctx->out_buf;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
682 cl->next = NULL;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
683 *ctx->last_out = cl;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
684 ctx->last_out = &cl->next;
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 return NGX_OK;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
687 }
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 return NGX_AGAIN;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
690 }
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
691
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 static ngx_int_t
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
694 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
695 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 int rc;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
698 ngx_buf_t *b;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
699 ngx_chain_t *cl;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
700 struct gztrailer *trailer;
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 ctx->zin = ctx->zstream.total_in;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
703 ctx->zout = 10 + ctx->zstream.total_out + 8;
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 rc = deflateEnd(&ctx->zstream);
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
706
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
707 if (rc != Z_OK) {
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
708 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
709 "deflateEnd() failed: %d", rc);
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
710 return NGX_ERROR;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
711 }
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
712
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
713 ngx_pfree(r->pool, ctx->preallocated);
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 cl = ngx_alloc_chain_link(r->pool);
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
716 if (cl == NULL) {
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
717 return NGX_ERROR;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
718 }
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
719
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
720 cl->buf = ctx->out_buf;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
721 cl->next = NULL;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
722 *ctx->last_out = cl;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
723 ctx->last_out = &cl->next;
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 if (ctx->zstream.avail_out >= 8) {
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
726 trailer = (struct gztrailer *) ctx->out_buf->last;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
727 ctx->out_buf->last += 8;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
728 ctx->out_buf->last_buf = 1;
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 } else {
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
731 b = ngx_create_temp_buf(r->pool, 8);
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
732 if (b == NULL) {
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
733 return NGX_ERROR;
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
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
736 b->last_buf = 1;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
737
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
738 cl = ngx_alloc_chain_link(r->pool);
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
739 if (cl == NULL) {
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
740 return NGX_ERROR;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
741 }
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
742
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
743 cl->buf = b;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
744 cl->next = NULL;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
745 *ctx->last_out = cl;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
746 ctx->last_out = &cl->next;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
747 trailer = (struct gztrailer *) b->pos;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
748 b->last += 8;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
749 }
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
750
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
751 #if (NGX_HAVE_LITTLE_ENDIAN && NGX_HAVE_NONALIGNED)
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 trailer->crc32 = ctx->crc32;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
754 trailer->zlen = ctx->zin;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
755
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
756 #else
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
757
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
758 trailer->crc32[0] = (u_char) (ctx->crc32 & 0xff);
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
759 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
760 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
761 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
762
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
763 trailer->zlen[0] = (u_char) (ctx->zin & 0xff);
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
764 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
765 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
766 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
767
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
768 #endif
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 ctx->zstream.avail_in = 0;
e9a1cddf2aaa *) split ngx_http_gzip_body_filter()
Igor Sysoev <igor@sysoev.ru>
parents: 2290
diff changeset
771 ctx->zstream.avail_out = 0;
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 ctx->done = 1;
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 r->connection->buffered &= ~NGX_HTTP_GZIP_BUFFERED;
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 return NGX_OK;
133
b27548f540ad nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
778 }
b27548f540ad nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
779
b27548f540ad nginx-0.0.1-2003-09-24-23:51:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
780
497
d7c90bb5ce83 nginx-0.1.23-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 489
diff changeset
781 static void *
d7c90bb5ce83 nginx-0.1.23-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 489
diff changeset
782 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
783 {
afc333135a6b nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
784 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
785
294
5cfd65b8b0a7 nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents: 292
diff changeset
786 void *p;
5cfd65b8b0a7 nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents: 292
diff changeset
787 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
788
afc333135a6b nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
789 alloc = items * size;
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 455
diff changeset
790
156
afc333135a6b nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
791 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
792
346
55e496a8ece3 nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents: 344
diff changeset
793 /*
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 455
diff changeset
794 * 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
795 * 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
796 */
156
afc333135a6b nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
797
346
55e496a8ece3 nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents: 344
diff changeset
798 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
799 }
afc333135a6b nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
800
afc333135a6b nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
801 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
802 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
803 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
804 ctx->allocated -= alloc;
afc333135a6b nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
805
257
70e1c7d2b83d nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 243
diff changeset
806 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
807 "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
808 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
809
afc333135a6b nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
810 return p;
afc333135a6b nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
811 }
afc333135a6b nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
812
afc333135a6b nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
813 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
814 "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
815 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
816
afc333135a6b nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
817 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
818
afc333135a6b nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
819 return p;
afc333135a6b nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
820 }
afc333135a6b nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
821
afc333135a6b nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
822
497
d7c90bb5ce83 nginx-0.1.23-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 489
diff changeset
823 static void
d7c90bb5ce83 nginx-0.1.23-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 489
diff changeset
824 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
825 {
282
30310107dbc9 nginx-0.0.2-2004-03-09-22:47:07 import
Igor Sysoev <igor@sysoev.ru>
parents: 265
diff changeset
826 #if 0
156
afc333135a6b nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
827 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
828
257
70e1c7d2b83d nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents: 243
diff changeset
829 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
830 "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
831 #endif
afc333135a6b nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
832 }
afc333135a6b nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
833
afc333135a6b nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
834
497
d7c90bb5ce83 nginx-0.1.23-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 489
diff changeset
835 static ngx_int_t
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 553
diff changeset
836 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
837 {
880
3b763d36e055 axe old % log format
Igor Sysoev <igor@sysoev.ru>
parents: 681
diff changeset
838 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
839
583
4e296b7d25bf nginx-0.3.13-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
840 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
841 if (var == NULL) {
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 553
diff changeset
842 return NGX_ERROR;
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 553
diff changeset
843 }
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 553
diff changeset
844
637
e60fe4cf1d4e nginx-0.3.40-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 597
diff changeset
845 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
846
177
4db54fdbcbe7 nginx-0.0.1-2003-11-10-20:17:31 import
Igor Sysoev <igor@sysoev.ru>
parents: 166
diff changeset
847 return NGX_OK;
4db54fdbcbe7 nginx-0.0.1-2003-11-10-20:17:31 import
Igor Sysoev <igor@sysoev.ru>
parents: 166
diff changeset
848 }
4db54fdbcbe7 nginx-0.0.1-2003-11-10-20:17:31 import
Igor Sysoev <igor@sysoev.ru>
parents: 166
diff changeset
849
4db54fdbcbe7 nginx-0.0.1-2003-11-10-20:17:31 import
Igor Sysoev <igor@sysoev.ru>
parents: 166
diff changeset
850
497
d7c90bb5ce83 nginx-0.1.23-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 489
diff changeset
851 static ngx_int_t
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 553
diff changeset
852 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
853 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
854 {
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 553
diff changeset
855 ngx_uint_t zint, zfrac;
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 553
diff changeset
856 ngx_http_gzip_ctx_t *ctx;
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 553
diff changeset
857
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
858 v->valid = 1;
1565
4c43e25d11ea fix English grammar
Igor Sysoev <igor@sysoev.ru>
parents: 1554
diff changeset
859 v->no_cacheable = 0;
573
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 553
diff changeset
860 v->not_found = 0;
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 553
diff changeset
861
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 553
diff changeset
862 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
863
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 553
diff changeset
864 if (ctx == NULL || ctx->zout == 0) {
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 553
diff changeset
865 v->not_found = 1;
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 553
diff changeset
866 return NGX_OK;
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 553
diff changeset
867 }
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 553
diff changeset
868
2049
2a92804f4109 *) back out r2040
Igor Sysoev <igor@sysoev.ru>
parents: 1790
diff changeset
869 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
870 if (v->data == NULL) {
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 553
diff changeset
871 return NGX_ERROR;
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 553
diff changeset
872 }
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 553
diff changeset
873
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 553
diff changeset
874 zint = (ngx_uint_t) (ctx->zin / ctx->zout);
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 553
diff changeset
875 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
876
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 553
diff changeset
877 if ((ctx->zin * 1000 / ctx->zout) % 10 > 4) {
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 553
diff changeset
878
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 553
diff changeset
879 /* 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
880
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 553
diff changeset
881 zfrac++;
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 553
diff changeset
882
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 553
diff changeset
883 if (zfrac > 99) {
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 553
diff changeset
884 zint++;
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 553
diff changeset
885 zfrac = 0;
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 553
diff changeset
886 }
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 553
diff changeset
887 }
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 553
diff changeset
888
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 553
diff changeset
889 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
890
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 553
diff changeset
891 return NGX_OK;
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 553
diff changeset
892 }
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 553
diff changeset
893
58475592100c nginx-0.3.8-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 553
diff changeset
894
497
d7c90bb5ce83 nginx-0.1.23-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 489
diff changeset
895 static void *
d7c90bb5ce83 nginx-0.1.23-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 489
diff changeset
896 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
897 {
d57c6835225c nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 133
diff changeset
898 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
899
501
d4ea69372b94 nginx-0.1.25-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 497
diff changeset
900 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
901 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
902 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
903 }
134
d57c6835225c nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 133
diff changeset
904
430
1fa5daf7558e nginx-0.0.11-2004-09-19-22:27:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 416
diff changeset
905 /*
479
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
906 * set by ngx_pcalloc():
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
907 *
c52408583801 nginx-0.1.14-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 469
diff changeset
908 * 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
909 * conf->types = { NULL };
723df5089c05 use hash in gzip_types, ssi_types, and sub_filter_types
Igor Sysoev <igor@sysoev.ru>
parents: 2051
diff changeset
910 * 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
911 */
320
d621239c30f7 nginx-0.0.3-2004-04-18-23:06:02 import
Igor Sysoev <igor@sysoev.ru>
parents: 319
diff changeset
912
134
d57c6835225c nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 133
diff changeset
913 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
914 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
915
156
afc333135a6b nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
916 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
917 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
918 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
919 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
920
d57c6835225c nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 133
diff changeset
921 return conf;
d57c6835225c nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 133
diff changeset
922 }
d57c6835225c nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 133
diff changeset
923
d57c6835225c nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 133
diff changeset
924
497
d7c90bb5ce83 nginx-0.1.23-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 489
diff changeset
925 static char *
d7c90bb5ce83 nginx-0.1.23-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 489
diff changeset
926 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
927 {
d57c6835225c nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 133
diff changeset
928 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
929 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
930
d57c6835225c nginx-0.0.1-2003-09-26-09:45:21 import
Igor Sysoev <igor@sysoev.ru>
parents: 133
diff changeset
931 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
932
346
55e496a8ece3 nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents: 344
diff changeset
933 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
934
156
afc333135a6b nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
935 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
936 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
937 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
938 MAX_MEM_LEVEL - 1);
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 573
diff changeset
939 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
940 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
941
2166
723df5089c05 use hash in gzip_types, ssi_types, and sub_filter_types
Igor Sysoev <igor@sysoev.ru>
parents: 2051
diff changeset
942 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
943 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
944 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
945 != NGX_OK)
723df5089c05 use hash in gzip_types, ssi_types, and sub_filter_types
Igor Sysoev <igor@sysoev.ru>
parents: 2051
diff changeset
946 {
723df5089c05 use hash in gzip_types, ssi_types, and sub_filter_types
Igor Sysoev <igor@sysoev.ru>
parents: 2051
diff changeset
947 return NGX_CONF_ERROR;
452
23fb87bddda1 nginx-0.1.1-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 444
diff changeset
948 }
23fb87bddda1 nginx-0.1.1-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 444
diff changeset
949
23fb87bddda1 nginx-0.1.1-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 444
diff changeset
950 return NGX_CONF_OK;
23fb87bddda1 nginx-0.1.1-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 444
diff changeset
951 }
23fb87bddda1 nginx-0.1.1-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 444
diff changeset
952
23fb87bddda1 nginx-0.1.1-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 444
diff changeset
953
681
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 663
diff changeset
954 static ngx_int_t
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 663
diff changeset
955 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
956 {
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 663
diff changeset
957 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
958 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
959
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 663
diff changeset
960 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
961 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
962
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 663
diff changeset
963 return NGX_OK;
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 663
diff changeset
964 }
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 663
diff changeset
965
7e24168b0853 nginx-0.4.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 663
diff changeset
966
497
d7c90bb5ce83 nginx-0.1.23-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 489
diff changeset
967 static char *
527
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 513
diff changeset
968 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
969 {
2290
1a7567e5b988 change int to size_t
Igor Sysoev <igor@sysoev.ru>
parents: 2288
diff changeset
970 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
971
2290
1a7567e5b988 change int to size_t
Igor Sysoev <igor@sysoev.ru>
parents: 2288
diff changeset
972 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
973
430
1fa5daf7558e nginx-0.0.11-2004-09-19-22:27:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 416
diff changeset
974 wbits = 15;
156
afc333135a6b nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
975
afc333135a6b nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
976 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
977
158
d377ee423603 nginx-0.0.1-2003-10-24-10:53:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 157
diff changeset
978 if (wsize == *np) {
d377ee423603 nginx-0.0.1-2003-10-24-10:53:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 157
diff changeset
979 *np = wbits;
430
1fa5daf7558e nginx-0.0.11-2004-09-19-22:27:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 416
diff changeset
980
1fa5daf7558e nginx-0.0.11-2004-09-19-22:27:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 416
diff changeset
981 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
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 wbits--;
afc333135a6b nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
985 }
afc333135a6b nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
986
afc333135a6b nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
987 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
988 }
afc333135a6b nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
989
afc333135a6b nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
990
497
d7c90bb5ce83 nginx-0.1.23-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 489
diff changeset
991 static char *
527
7fa11e5c6e96 nginx-0.1.38-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 513
diff changeset
992 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
993 {
2290
1a7567e5b988 change int to size_t
Igor Sysoev <igor@sysoev.ru>
parents: 2288
diff changeset
994 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
995
2290
1a7567e5b988 change int to size_t
Igor Sysoev <igor@sysoev.ru>
parents: 2288
diff changeset
996 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
997
430
1fa5daf7558e nginx-0.0.11-2004-09-19-22:27:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 416
diff changeset
998 memlevel = 9;
156
afc333135a6b nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
999
afc333135a6b nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
1000 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
1001
158
d377ee423603 nginx-0.0.1-2003-10-24-10:53:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 157
diff changeset
1002 if (hsize == *np) {
d377ee423603 nginx-0.0.1-2003-10-24-10:53:41 import
Igor Sysoev <igor@sysoev.ru>
parents: 157
diff changeset
1003 *np = memlevel;
430
1fa5daf7558e nginx-0.0.11-2004-09-19-22:27:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 416
diff changeset
1004
1fa5daf7558e nginx-0.0.11-2004-09-19-22:27:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 416
diff changeset
1005 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
1006 }
afc333135a6b nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
1007
afc333135a6b nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
1008 memlevel--;
afc333135a6b nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
1009 }
afc333135a6b nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
1010
afc333135a6b nginx-0.0.1-2003-10-23-10:13:16 import
Igor Sysoev <igor@sysoev.ru>
parents: 155
diff changeset
1011 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
1012 }