comparison src/http/ngx_http_copy_filter.c @ 0:f0b350454894 NGINX_0_1_0

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