comparison src/http/ngx_http_output_filter.c @ 26:53cb81681040

nginx-0.0.1-2002-12-15-09:25:09 import
author Igor Sysoev <igor@sysoev.ru>
date Sun, 15 Dec 2002 06:25:09 +0000
parents 77c7629a2627
children d45effe5854c
comparison
equal deleted inserted replaced
25:a8b156554dfe 26:53cb81681040
7 #include <ngx_http.h> 7 #include <ngx_http.h>
8 #include <ngx_http_config.h> 8 #include <ngx_http_config.h>
9 #include <ngx_http_output_filter.h> 9 #include <ngx_http_output_filter.h>
10 10
11 11
12 int ngx_http_output_filter(ngx_http_request_t *r, ngx_hunk_t *hunk);
12 static int ngx_http_output_filter_copy_hunk(ngx_hunk_t *dst, ngx_hunk_t *src); 13 static int ngx_http_output_filter_copy_hunk(ngx_hunk_t *dst, ngx_hunk_t *src);
14 #if 0
13 static int ngx_http_output_filter_init( 15 static int ngx_http_output_filter_init(
14 int (**next_filter)(ngx_http_request_t *r, ngx_chain_t *ch)); 16 int (**next_filter)(ngx_http_request_t *r, ngx_chain_t *ch));
17 #endif
15 static void *ngx_http_output_filter_create_conf(ngx_pool_t *pool); 18 static void *ngx_http_output_filter_create_conf(ngx_pool_t *pool);
16
17
18 static ngx_command_t ngx_http_output_filter_commands[];
19
20
21 ngx_http_module_t ngx_http_output_filter_module = {
22 NGX_HTTP_MODULE,
23
24 NULL, /* create server config */
25 ngx_http_output_filter_create_conf, /* create location config */
26 ngx_http_output_filter_commands, /* module directives */
27
28 NULL, /* init module */
29 NULL, /* translate handler */
30
31 ngx_http_output_filter_init /* init output body filter */
32 };
33 19
34 20
35 static ngx_command_t ngx_http_output_filter_commands[] = { 21 static ngx_command_t ngx_http_output_filter_commands[] = {
36 22
37 {"output_buffer", ngx_conf_set_size_slot, 23 {"output_buffer", ngx_conf_set_size_slot,
42 {NULL} 28 {NULL}
43 29
44 }; 30 };
45 31
46 32
33 ngx_http_module_t ngx_http_output_filter_module = {
34 NGX_HTTP_MODULE,
35
36 NULL, /* create server config */
37 ngx_http_output_filter_create_conf, /* create location config */
38 ngx_http_output_filter_commands, /* module directives */
39
40 NULL, /* init module */
41 NULL, /* translate handler */
42
43 NULL, /* output header filter */
44 NULL, /* next output header filter */
45 ngx_http_output_filter, /* output body filter */
46 NULL /* next output body filter */
47 };
48
49
50 #if 0
47 static int (*ngx_http_output_next_filter)(ngx_http_request_t *r, 51 static int (*ngx_http_output_next_filter)(ngx_http_request_t *r,
48 ngx_chain_t *ch); 52 ngx_chain_t *ch);
53 #endif
49 54
50 55
51 int ngx_http_output_filter(ngx_http_request_t *r, ngx_hunk_t *hunk) 56 int ngx_http_output_filter(ngx_http_request_t *r, ngx_hunk_t *hunk)
52 { 57 {
53 int rc, once; 58 int rc, once;
64 if (ctx == NULL) { 69 if (ctx == NULL) {
65 ngx_http_create_ctx(r, ctx, 70 ngx_http_create_ctx(r, ctx,
66 ngx_http_output_filter_module, 71 ngx_http_output_filter_module,
67 sizeof(ngx_http_output_filter_ctx_t)); 72 sizeof(ngx_http_output_filter_ctx_t));
68 73
74 #if 0
69 ctx->next_filter = ngx_http_output_next_filter; 75 ctx->next_filter = ngx_http_output_next_filter;
76 #endif
70 } 77 }
71 78
72 if (hunk && (hunk->type & NGX_HUNK_LAST)) 79 if (hunk && (hunk->type & NGX_HUNK_LAST))
73 ctx->last = 1; 80 ctx->last = 1;
74 81
85 ngx_add_hunk_to_chain(ce->next, hunk, r->pool, NGX_ERROR); 92 ngx_add_hunk_to_chain(ce->next, hunk, r->pool, NGX_ERROR);
86 } 93 }
87 94
88 /* our hunk is still busy */ 95 /* our hunk is still busy */
89 if (ctx->hunk->pos.mem < ctx->hunk->last.mem) { 96 if (ctx->hunk->pos.mem < ctx->hunk->last.mem) {
97 rc = ngx_http_output_filter_module.
98 next_output_body_filter(r, NULL);
99 #if 0
90 rc = ctx->next_filter(r, NULL); 100 rc = ctx->next_filter(r, NULL);
101 #endif
91 102
92 /* our hunk is free */ 103 /* our hunk is free */
93 } else { 104 } else {
94 ctx->out.hunk = ctx->hunk; 105 ctx->out.hunk = ctx->hunk;
95 106
108 119
109 for (ce = ctx->in->next; ce; ce = ce->next) { 120 for (ce = ctx->in->next; ce; ce = ce->next) {
110 if (ce->hunk->type & NGX_HUNK_FILE) 121 if (ce->hunk->type & NGX_HUNK_FILE)
111 break; 122 break;
112 123
113 if ((ce->hunk->type & NGX_HUNK_MEMORY|NGX_HUNK_MMAP) 124 if ((ce->hunk->type & (NGX_HUNK_MEMORY|NGX_HUNK_MMAP))
114 && (r->filter & NGX_HTTP_FILTER_NEED_TEMP)) 125 && (r->filter & NGX_HTTP_FILTER_NEED_TEMP))
115 break; 126 break;
116 } 127 }
117 128
118 ctx->out.next = ce; 129 ctx->out.next = ce;
119 130
120 } else { 131 } else {
121 ctx->out.next = NULL; 132 ctx->out.next = NULL;
122 } 133 }
123 134
135 rc = ngx_http_output_filter_module.
136 next_output_body_filter(r, &ctx->out);
137 #if 0
124 rc = ctx->next_filter(r, &ctx->out); 138 rc = ctx->next_filter(r, &ctx->out);
139 #endif;
125 } 140 }
126 141
127 /* delete completed hunks from input chain */ 142 /* delete completed hunks from input chain */
128 for (ce = ctx->in; ce; ce = ce->next) { 143 for (ce = ctx->in; ce; ce = ce->next) {
129 if (ce->hunk->pos.file == ce->hunk->last.file) 144 if (ce->hunk->pos.file == ce->hunk->last.file)
137 152
138 /* input chain is empty */ 153 /* input chain is empty */
139 } else { 154 } else {
140 155
141 if (hunk == NULL) { 156 if (hunk == NULL) {
157 rc = ngx_http_output_filter_module.
158 next_output_body_filter(r, NULL);
159 #if 0
142 rc = ctx->next_filter(r, NULL); 160 rc = ctx->next_filter(r, NULL);
161 #endif;
143 162
144 } else { 163 } else {
145 164
146 /* we need to copy hunk to our hunk */ 165 /* we need to copy hunk to our hunk */
147 if (((r->filter & NGX_HTTP_FILTER_NEED_IN_MEMORY) 166 if (((r->filter & NGX_HTTP_FILTER_NEED_IN_MEMORY)
148 && (hunk->type & NGX_HUNK_FILE)) 167 && (hunk->type & NGX_HUNK_FILE))
149 || ((r->filter & NGX_HTTP_FILTER_NEED_TEMP) 168 || ((r->filter & NGX_HTTP_FILTER_NEED_TEMP)
150 && (hunk->type & NGX_HUNK_MEMORY|NGX_HUNK_MMAP)) 169 && (hunk->type & (NGX_HUNK_MEMORY|NGX_HUNK_MMAP)))
151 ) { 170 ) {
152 171
153 /* out hunk is still busy */ 172 /* out hunk is still busy */
154 if (ctx->hunk && ctx->hunk->pos.mem < ctx->hunk->last.mem) { 173 if (ctx->hunk && ctx->hunk->pos.mem < ctx->hunk->last.mem) {
155 ngx_add_hunk_to_chain(ctx->in, hunk, r->pool, 174 ngx_add_hunk_to_chain(ctx->in, hunk, r->pool,
156 NGX_ERROR); 175 NGX_ERROR);
157 176
177 rc = ngx_http_output_filter_module.
178 next_output_body_filter(r, NULL);
179 #if 0
158 rc = ctx->next_filter(r, NULL); 180 rc = ctx->next_filter(r, NULL);
181 #endif
159 182
160 } else { 183 } else {
161 if (ctx->hunk == NULL) { 184 if (ctx->hunk == NULL) {
162 185
163 if (hunk->type & NGX_HUNK_LAST) { 186 if (hunk->type & NGX_HUNK_LAST) {
199 NGX_ERROR); 222 NGX_ERROR);
200 223
201 ctx->out.hunk = ctx->hunk; 224 ctx->out.hunk = ctx->hunk;
202 ctx->out.next = NULL; 225 ctx->out.next = NULL;
203 226
227 rc = ngx_http_output_filter_module.
228 next_output_body_filter(r, &ctx->out);
229 #if 0
204 rc = ctx->next_filter(r, &ctx->out); 230 rc = ctx->next_filter(r, &ctx->out);
231 #endif
205 } 232 }
206 } 233 }
207 234
208 } else { 235 } else {
209 ctx->out.hunk = hunk; 236 ctx->out.hunk = hunk;
210 ctx->out.next = NULL; 237 ctx->out.next = NULL;
211 238
239 rc = ngx_http_output_filter_module.
240 next_output_body_filter(r, &ctx->out);
241 #if 0
212 rc = ctx->next_filter(r, &ctx->out); 242 rc = ctx->next_filter(r, &ctx->out);
243 #endif
213 } 244 }
214 } 245 }
215 } 246 }
216 247
217 if (rc == NGX_OK && ctx->hunk) 248 if (rc == NGX_OK && ctx->hunk)
267 298
268 src->pos.mem += size; 299 src->pos.mem += size;
269 dst->last.mem += size; 300 dst->last.mem += size;
270 } 301 }
271 302
303 #if 1
304 if (src->type & NGX_HUNK_LAST)
305 dst->type |= NGX_HUNK_LAST;
306 #endif
307
272 return NGX_OK; 308 return NGX_OK;
273 } 309 }
274 310
275 311
276 static void *ngx_http_output_filter_create_conf(ngx_pool_t *pool) 312 static void *ngx_http_output_filter_create_conf(ngx_pool_t *pool)
284 conf->hunk_size = NGX_CONF_UNSET; 320 conf->hunk_size = NGX_CONF_UNSET;
285 321
286 return conf; 322 return conf;
287 } 323 }
288 324
325 #if 0
289 static int ngx_http_output_filter_init( 326 static int ngx_http_output_filter_init(
290 int (**next_filter)(ngx_http_request_t *r, ngx_chain_t *ch)) 327 int (**next_filter)(ngx_http_request_t *r, ngx_chain_t *ch))
291 { 328 {
292 ngx_http_output_next_filter = *next_filter; 329 ngx_http_output_next_filter = *next_filter;
293 *next_filter = NULL; 330 *next_filter = NULL;
294 331
295 return NGX_OK; 332 return NGX_OK;
296 } 333 }
334 #endif