comparison src/http/ngx_http_output_filter.c @ 10:4f3879d9b6f6

nginx-0.0.1-2002-09-11-19:18:33 import
author Igor Sysoev <igor@sysoev.ru>
date Wed, 11 Sep 2002 15:18:33 +0000
parents 6f58641241bb
children 055ed05235ae
comparison
equal deleted inserted replaced
9:6f58641241bb 10:4f3879d9b6f6
1
2 1
3 #include <ngx_core.h> 2 #include <ngx_core.h>
4 #include <ngx_files.h> 3 #include <ngx_files.h>
5 #include <ngx_string.h> 4 #include <ngx_string.h>
6 #include <ngx_hunk.h> 5 #include <ngx_hunk.h>
6 #include <ngx_config_command.h>
7 #include <ngx_http.h> 7 #include <ngx_http.h>
8 #include <ngx_http_config.h>
8 #include <ngx_http_output_filter.h> 9 #include <ngx_http_output_filter.h>
9 10
10 11
11 static int ngx_http_output_filter_copy_hunk(ngx_hunk_t *dst, ngx_hunk_t *src); 12 static int ngx_http_output_filter_copy_hunk(ngx_hunk_t *dst, ngx_hunk_t *src);
12 static int ngx_http_output_filter_init( 13 static int ngx_http_output_filter_init(
13 int (*next_filter)(ngx_http_request_t *r, ngx_chain_t *ch)); 14 int (**next_filter)(ngx_http_request_t *r, ngx_chain_t *ch));
14 static void *ngx_http_output_filter_create_conf(ngx_pool_t *pool); 15 static void *ngx_http_output_filter_create_conf(ngx_pool_t *pool);
15 static void *ngx_http_output_filter_set_hunk_size(ngx_pool_t *pool, void *conf, 16
16 char *size); 17
18 static ngx_command_t ngx_http_output_filter_commands[];
17 19
18 20
19 ngx_http_module_t ngx_http_output_filter_module = { 21 ngx_http_module_t ngx_http_output_filter_module = {
20 NGX_HTTP_MODULE 22 NGX_HTTP_MODULE,
23 NULL, /* create server config */
24 ngx_http_output_filter_create_conf, /* create location config */
25 ngx_http_output_filter_commands, /* module directives */
26 NULL, /* init module */
27 ngx_http_output_filter_init /* init output body filter */
28 };
29
30
31 static ngx_command_t ngx_http_output_filter_commands[] = {
32
33 {"output_buffer", ngx_conf_set_size_slot,
34 offsetof(ngx_http_output_filter_conf_t, hunk_size),
35 NGX_HTTP_LOC_CONF, NGX_CONF_TAKE1,
36 "set output filter buffer size"},
37
38 {NULL}
39
21 }; 40 };
22 41
23 42
24 static int (*ngx_http_output_next_filter)(ngx_http_request_t *r, 43 static int (*ngx_http_output_next_filter)(ngx_http_request_t *r,
25 ngx_chain_t *ch); 44 ngx_chain_t *ch);
26
27 /* STUB */
28 int ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *ch);
29
30 int ngx_http_output_filter_stub_init(ngx_pool_t *pool, void *loc_conf)
31 {
32 ngx_http_output_filter_conf_t *conf;
33
34 ngx_http_output_filter_init(ngx_http_write_filter);
35 conf = ngx_http_output_filter_create_conf(pool);
36 ngx_http_output_filter_set_hunk_size(pool, conf, "32");
37
38 loc_conf = conf;
39 }
40 /* */
41 45
42 46
43 int ngx_http_output_filter(ngx_http_request_t *r, ngx_hunk_t *hunk) 47 int ngx_http_output_filter(ngx_http_request_t *r, ngx_hunk_t *hunk)
44 { 48 {
45 int rc, once; 49 int rc, once;
52 ctx = (ngx_http_output_filter_ctx_t *) 56 ctx = (ngx_http_output_filter_ctx_t *)
53 ngx_get_module_ctx(r->main ? r->main : r, 57 ngx_get_module_ctx(r->main ? r->main : r,
54 ngx_http_output_filter_module); 58 ngx_http_output_filter_module);
55 59
56 if (ctx == NULL) { 60 if (ctx == NULL) {
57 ngx_test_null(ctx, 61 ngx_http_create_ctx(r, ctx,
58 ngx_pcalloc(r->pool, sizeof(ngx_http_output_filter_ctx_t)), 62 ngx_http_output_filter_module,
59 NGX_ERROR); 63 sizeof(ngx_http_output_filter_ctx_t));
60 64
61 ctx->next_filter = ngx_http_output_next_filter; 65 ctx->next_filter = ngx_http_output_next_filter;
62 } 66 }
63 67
64 ngx_log_debug(r->connection->log, "HUNK: x%x CTX-IN: x%x CTX->HUNK: x%x" _ 68 ngx_log_debug(r->connection->log, "HUNK: x%x CTX-IN: x%x CTX->HUNK: x%x" _
65 hunk _ ctx->in _ ctx->hunk); 69 hunk _ ctx->in _ ctx->hunk);
66 70
67 if (hunk && (hunk->type & NGX_HUNK_LAST)) 71 if (hunk && (hunk->type & NGX_HUNK_LAST))
68 ctx->last = 1; 72 ctx->last = 1;
69 73
70 for (once = 1; once || ctx->in; once--) { 74 for (once = 1; once || ctx->in; once = 0) {
71 75
72 /* input chain is not empty */ 76 /* input chain is not empty */
73 if (ctx->in) { 77 if (ctx->in) {
74 78
75 /* add hunk to input chain */ 79 /* add hunk to input chain */
265 269
266 return NGX_OK; 270 return NGX_OK;
267 } 271 }
268 272
269 273
270 static int ngx_http_output_filter_init(
271 int (*next_filter)(ngx_http_request_t *r, ngx_chain_t *ch))
272 {
273 ngx_http_output_next_filter = next_filter;
274
275 return NGX_OK;
276 }
277
278 static void *ngx_http_output_filter_create_conf(ngx_pool_t *pool) 274 static void *ngx_http_output_filter_create_conf(ngx_pool_t *pool)
279 { 275 {
280 ngx_http_output_filter_conf_t *conf; 276 ngx_http_output_filter_conf_t *conf;
281 277
282 ngx_test_null(conf, 278 ngx_test_null(conf,
283 ngx_pcalloc(pool, sizeof(ngx_http_output_filter_conf_t)), 279 ngx_pcalloc(pool, sizeof(ngx_http_output_filter_conf_t)),
284 NULL); 280 NULL);
285 281
286 conf->hunk_size = 16384; 282 conf->hunk_size = NGX_CONF_UNSET;
287 } 283
288 284 return conf;
289 static void *ngx_http_output_filter_set_hunk_size(ngx_pool_t *pool, void *conf, 285 }
290 char *size) 286
291 { 287 static int ngx_http_output_filter_init(
292 ngx_http_output_filter_conf_t *cf = (ngx_http_output_filter_conf_t *) conf; 288 int (**next_filter)(ngx_http_request_t *r, ngx_chain_t *ch))
293 289 {
294 cf->hunk_size = atoi(size); 290 ngx_http_output_next_filter = *next_filter;
295 if (cf->hunk_size <= 0) 291 *next_filter = NULL;
296 return "Error"; 292
297 293 return NGX_OK;
298 cf->hunk_size *= 1024; 294 }
299 return NULL;
300 }