comparison src/http/ngx_http_copy_filter.c @ 334:af451db3fe99

nginx-0.0.3-2004-05-12-09:37:55 import
author Igor Sysoev <igor@sysoev.ru>
date Wed, 12 May 2004 05:37:55 +0000
parents src/http/ngx_http_output_filter.c@e0f3f238db09
children 6bdf858bff8c
comparison
equal deleted inserted replaced
333:be40e9893a19 334:af451db3fe99
1
2 #include <ngx_config.h>
3 #include <ngx_core.h>
4 #include <ngx_http.h>
5
6
7 typedef struct {
8 ngx_bufs_t bufs;
9 } ngx_http_copy_filter_conf_t;
10
11
12 static void *ngx_http_copy_filter_create_conf(ngx_conf_t *cf);
13 static char *ngx_http_copy_filter_merge_conf(ngx_conf_t *cf,
14 void *parent, void *child);
15 static ngx_int_t ngx_http_copy_filter_init(ngx_cycle_t *cycle);
16
17
18 static ngx_command_t ngx_http_copy_filter_commands[] = {
19
20 {ngx_string("output_buffers"),
21 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2,
22 ngx_conf_set_bufs_slot,
23 NGX_HTTP_LOC_CONF_OFFSET,
24 offsetof(ngx_http_copy_filter_conf_t, bufs),
25 NULL},
26
27 ngx_null_command
28 };
29
30
31 static ngx_http_module_t ngx_http_copy_filter_module_ctx = {
32 NULL, /* pre conf */
33
34 NULL, /* create main configuration */
35 NULL, /* init main configuration */
36
37 NULL, /* create server configuration */
38 NULL, /* merge server configuration */
39
40 ngx_http_copy_filter_create_conf, /* create location configuration */
41 ngx_http_copy_filter_merge_conf /* merge location configuration */
42 };
43
44
45 ngx_module_t ngx_http_copy_filter_module = {
46 NGX_MODULE,
47 &ngx_http_copy_filter_module_ctx, /* module context */
48 ngx_http_copy_filter_commands, /* module directives */
49 NGX_HTTP_MODULE, /* module type */
50 ngx_http_copy_filter_init, /* init module */
51 NULL /* init process */
52 };
53
54
55 static ngx_http_output_body_filter_pt ngx_http_next_filter;
56
57
58 ngx_int_t ngx_http_copy_filter(ngx_http_request_t *r, ngx_chain_t *in)
59 {
60 ngx_output_chain_ctx_t *ctx;
61 ngx_http_copy_filter_conf_t *conf;
62
63 if (r->connection->write->error) {
64 return NGX_ERROR;
65 }
66
67 ctx = ngx_http_get_module_ctx(r->main ? r->main : r,
68 ngx_http_copy_filter_module);
69
70 if (ctx == NULL) {
71 conf = ngx_http_get_module_loc_conf(r->main ? r->main : r,
72 ngx_http_copy_filter_module);
73
74 ngx_http_create_ctx(r, ctx, ngx_http_copy_filter_module,
75 sizeof(ngx_output_chain_ctx_t), NGX_ERROR);
76
77 ctx->sendfile = r->sendfile;
78 ctx->need_in_memory = r->filter & NGX_HTTP_FILTER_NEED_IN_MEMORY;
79 ctx->need_in_temp = r->filter & NGX_HTTP_FILTER_NEED_TEMP;
80
81 ctx->pool = r->pool;
82 ctx->bufs = conf->bufs;
83 ctx->tag = (ngx_hunk_tag_t) &ngx_http_copy_filter_module;
84
85 ctx->output_filter = (ngx_output_chain_filter_pt) ngx_http_next_filter;
86 ctx->filter_ctx = r;
87
88 }
89
90 return ngx_output_chain(ctx, in);
91 }
92
93
94 static void *ngx_http_copy_filter_create_conf(ngx_conf_t *cf)
95 {
96 ngx_http_copy_filter_conf_t *conf;
97
98 ngx_test_null(conf,
99 ngx_palloc(cf->pool, sizeof(ngx_http_copy_filter_conf_t)),
100 NULL);
101
102 conf->bufs.num = 0;
103
104 return conf;
105 }
106
107
108 static char *ngx_http_copy_filter_merge_conf(ngx_conf_t *cf,
109 void *parent, void *child)
110 {
111 ngx_http_copy_filter_conf_t *prev = parent;
112 ngx_http_copy_filter_conf_t *conf = child;
113
114 ngx_conf_merge_bufs_value(conf->bufs, prev->bufs, 1, 32768);
115
116 return NULL;
117 }
118
119
120 static ngx_int_t ngx_http_copy_filter_init(ngx_cycle_t *cycle)
121 {
122 ngx_http_next_filter = ngx_http_top_body_filter;
123 ngx_http_top_body_filter = ngx_http_copy_filter;
124
125 return NGX_OK;
126 }
127