annotate src/http/modules/ngx_http_addition_filter_module.c @ 660:d0f7a625f27c NGINX_1_1_14

nginx 1.1.14 *) Feature: multiple "limit_req" limits may be used simultaneously. *) Bugfix: in error handling while connecting to a backend. Thanks to Piotr Sikora. *) Bugfix: in AIO error handling on FreeBSD. *) Bugfix: in the OpenSSL library initialization. *) Bugfix: the "proxy_redirect" directives might not be correctly inherited. *) Bugfix: memory leak during reconfiguration if the "pcre_jit" directive was used.
author Igor Sysoev <http://sysoev.ru>
date Mon, 30 Jan 2012 00:00:00 +0400
parents 5c576ea5dbd9
children 597573166f34
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
1
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
2 /*
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
3 * Copyright (C) Igor Sysoev
660
d0f7a625f27c nginx 1.1.14
Igor Sysoev <http://sysoev.ru>
parents: 554
diff changeset
4 * Copyright (C) Nginx, Inc.
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
5 */
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
6
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
7
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
8 #include <ngx_config.h>
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
9 #include <ngx_core.h>
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
10 #include <ngx_http.h>
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
11
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
12
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
13 typedef struct {
394
05981f639d21 nginx 0.7.9
Igor Sysoev <http://sysoev.ru>
parents: 286
diff changeset
14 ngx_str_t before_body;
05981f639d21 nginx 0.7.9
Igor Sysoev <http://sysoev.ru>
parents: 286
diff changeset
15 ngx_str_t after_body;
05981f639d21 nginx 0.7.9
Igor Sysoev <http://sysoev.ru>
parents: 286
diff changeset
16
05981f639d21 nginx 0.7.9
Igor Sysoev <http://sysoev.ru>
parents: 286
diff changeset
17 ngx_hash_t types;
05981f639d21 nginx 0.7.9
Igor Sysoev <http://sysoev.ru>
parents: 286
diff changeset
18 ngx_array_t *types_keys;
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
19 } ngx_http_addition_conf_t;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
20
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
21
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
22 typedef struct {
394
05981f639d21 nginx 0.7.9
Igor Sysoev <http://sysoev.ru>
parents: 286
diff changeset
23 ngx_uint_t before_body_sent;
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
24 } ngx_http_addition_ctx_t;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
25
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
26
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
27 static void *ngx_http_addition_create_conf(ngx_conf_t *cf);
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
28 static char *ngx_http_addition_merge_conf(ngx_conf_t *cf, void *parent,
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
29 void *child);
230
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 216
diff changeset
30 static ngx_int_t ngx_http_addition_filter_init(ngx_conf_t *cf);
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
31
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
32
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
33 static ngx_command_t ngx_http_addition_commands[] = {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
34
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
35 { ngx_string("add_before_body"),
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
36 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
37 ngx_conf_set_str_slot,
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
38 NGX_HTTP_LOC_CONF_OFFSET,
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
39 offsetof(ngx_http_addition_conf_t, before_body),
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
40 NULL },
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
41
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
42 { ngx_string("add_after_body"),
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
43 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
44 ngx_conf_set_str_slot,
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
45 NGX_HTTP_LOC_CONF_OFFSET,
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
46 offsetof(ngx_http_addition_conf_t, after_body),
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
47 NULL },
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
48
528
005a70f9573b nginx 0.8.16
Igor Sysoev <http://sysoev.ru>
parents: 496
diff changeset
49 { ngx_string("addition_types"),
394
05981f639d21 nginx 0.7.9
Igor Sysoev <http://sysoev.ru>
parents: 286
diff changeset
50 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_1MORE,
05981f639d21 nginx 0.7.9
Igor Sysoev <http://sysoev.ru>
parents: 286
diff changeset
51 ngx_http_types_slot,
05981f639d21 nginx 0.7.9
Igor Sysoev <http://sysoev.ru>
parents: 286
diff changeset
52 NGX_HTTP_LOC_CONF_OFFSET,
05981f639d21 nginx 0.7.9
Igor Sysoev <http://sysoev.ru>
parents: 286
diff changeset
53 offsetof(ngx_http_addition_conf_t, types_keys),
05981f639d21 nginx 0.7.9
Igor Sysoev <http://sysoev.ru>
parents: 286
diff changeset
54 &ngx_http_html_default_types[0] },
05981f639d21 nginx 0.7.9
Igor Sysoev <http://sysoev.ru>
parents: 286
diff changeset
55
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
56 ngx_null_command
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
57 };
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
58
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
59
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
60 static ngx_http_module_t ngx_http_addition_filter_module_ctx = {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
61 NULL, /* preconfiguration */
230
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 216
diff changeset
62 ngx_http_addition_filter_init, /* postconfiguration */
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
63
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
64 NULL, /* create main configuration */
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
65 NULL, /* init main configuration */
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
66
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
67 NULL, /* create server configuration */
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
68 NULL, /* merge server configuration */
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
69
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
70 ngx_http_addition_create_conf, /* create location configuration */
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
71 ngx_http_addition_merge_conf /* merge location configuration */
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
72 };
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
73
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
74
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
75 ngx_module_t ngx_http_addition_filter_module = {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
76 NGX_MODULE_V1,
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
77 &ngx_http_addition_filter_module_ctx, /* module context */
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
78 ngx_http_addition_commands, /* module directives */
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
79 NGX_HTTP_MODULE, /* module type */
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
80 NULL, /* init master */
230
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 216
diff changeset
81 NULL, /* init module */
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
82 NULL, /* init process */
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
83 NULL, /* init thread */
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
84 NULL, /* exit thread */
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
85 NULL, /* exit process */
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
86 NULL, /* exit master */
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
87 NGX_MODULE_V1_PADDING
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
88 };
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
89
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
90
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
91 static ngx_http_output_header_filter_pt ngx_http_next_header_filter;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
92 static ngx_http_output_body_filter_pt ngx_http_next_body_filter;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
93
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
94
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
95 static ngx_int_t
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
96 ngx_http_addition_header_filter(ngx_http_request_t *r)
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
97 {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
98 ngx_http_addition_ctx_t *ctx;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
99 ngx_http_addition_conf_t *conf;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
100
394
05981f639d21 nginx 0.7.9
Igor Sysoev <http://sysoev.ru>
parents: 286
diff changeset
101 if (r->headers_out.status != NGX_HTTP_OK || r != r->main) {
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
102 return ngx_http_next_header_filter(r);
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
103 }
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
104
180
4cd3e70c4d60 nginx 0.3.37
Igor Sysoev <http://sysoev.ru>
parents: 178
diff changeset
105 conf = ngx_http_get_module_loc_conf(r, ngx_http_addition_filter_module);
4cd3e70c4d60 nginx 0.3.37
Igor Sysoev <http://sysoev.ru>
parents: 178
diff changeset
106
4cd3e70c4d60 nginx 0.3.37
Igor Sysoev <http://sysoev.ru>
parents: 178
diff changeset
107 if (conf->before_body.len == 0 && conf->after_body.len == 0) {
4cd3e70c4d60 nginx 0.3.37
Igor Sysoev <http://sysoev.ru>
parents: 178
diff changeset
108 return ngx_http_next_header_filter(r);
4cd3e70c4d60 nginx 0.3.37
Igor Sysoev <http://sysoev.ru>
parents: 178
diff changeset
109 }
4cd3e70c4d60 nginx 0.3.37
Igor Sysoev <http://sysoev.ru>
parents: 178
diff changeset
110
394
05981f639d21 nginx 0.7.9
Igor Sysoev <http://sysoev.ru>
parents: 286
diff changeset
111 if (ngx_http_test_content_type(r, &conf->types) == NULL) {
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
112 return ngx_http_next_header_filter(r);
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
113 }
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
114
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
115 ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_addition_ctx_t));
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
116 if (ctx == NULL) {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
117 return NGX_ERROR;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
118 }
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
119
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
120 ngx_http_set_ctx(r, ctx, ngx_http_addition_filter_module);
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
121
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
122 ngx_http_clear_content_length(r);
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
123 ngx_http_clear_accept_ranges(r);
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
124
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
125 return ngx_http_next_header_filter(r);
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
126 }
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
127
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
128
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
129 static ngx_int_t
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
130 ngx_http_addition_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
131 {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
132 ngx_int_t rc;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
133 ngx_uint_t last;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
134 ngx_chain_t *cl;
244
500a3242dff6 nginx 0.4.7
Igor Sysoev <http://sysoev.ru>
parents: 230
diff changeset
135 ngx_http_request_t *sr;
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
136 ngx_http_addition_ctx_t *ctx;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
137 ngx_http_addition_conf_t *conf;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
138
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
139 if (in == NULL || r->header_only) {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
140 return ngx_http_next_body_filter(r, in);
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
141 }
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
142
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
143 ctx = ngx_http_get_module_ctx(r, ngx_http_addition_filter_module);
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
144
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
145 if (ctx == NULL) {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
146 return ngx_http_next_body_filter(r, in);
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
147 }
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
148
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
149 conf = ngx_http_get_module_loc_conf(r, ngx_http_addition_filter_module);
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
150
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
151 if (!ctx->before_body_sent) {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
152 ctx->before_body_sent = 1;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
153
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
154 if (conf->before_body.len) {
426
e7dbea1ee115 nginx 0.7.25
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
155 if (ngx_http_subrequest(r, &conf->before_body, NULL, &sr, NULL, 0)
e7dbea1ee115 nginx 0.7.25
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
156 != NGX_OK)
e7dbea1ee115 nginx 0.7.25
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
157 {
e7dbea1ee115 nginx 0.7.25
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
158 return NGX_ERROR;
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
159 }
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
160 }
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
161 }
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
162
256
2e9c57a5e50a nginx 0.4.13
Igor Sysoev <http://sysoev.ru>
parents: 248
diff changeset
163 if (conf->after_body.len == 0) {
2e9c57a5e50a nginx 0.4.13
Igor Sysoev <http://sysoev.ru>
parents: 248
diff changeset
164 ngx_http_set_ctx(r, NULL, ngx_http_addition_filter_module);
2e9c57a5e50a nginx 0.4.13
Igor Sysoev <http://sysoev.ru>
parents: 248
diff changeset
165 return ngx_http_next_body_filter(r, in);
2e9c57a5e50a nginx 0.4.13
Igor Sysoev <http://sysoev.ru>
parents: 248
diff changeset
166 }
2e9c57a5e50a nginx 0.4.13
Igor Sysoev <http://sysoev.ru>
parents: 248
diff changeset
167
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
168 last = 0;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
169
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
170 for (cl = in; cl; cl = cl->next) {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
171 if (cl->buf->last_buf) {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
172 cl->buf->last_buf = 0;
180
4cd3e70c4d60 nginx 0.3.37
Igor Sysoev <http://sysoev.ru>
parents: 178
diff changeset
173 cl->buf->sync = 1;
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
174 last = 1;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
175 }
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
176 }
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
177
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
178 rc = ngx_http_next_body_filter(r, in);
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
179
180
4cd3e70c4d60 nginx 0.3.37
Igor Sysoev <http://sysoev.ru>
parents: 178
diff changeset
180 if (rc == NGX_ERROR || !last || conf->after_body.len == 0) {
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
181 return rc;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
182 }
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
183
426
e7dbea1ee115 nginx 0.7.25
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
184 if (ngx_http_subrequest(r, &conf->after_body, NULL, &sr, NULL, 0)
e7dbea1ee115 nginx 0.7.25
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
185 != NGX_OK)
e7dbea1ee115 nginx 0.7.25
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
186 {
e7dbea1ee115 nginx 0.7.25
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
187 return NGX_ERROR;
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
188 }
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
189
180
4cd3e70c4d60 nginx 0.3.37
Igor Sysoev <http://sysoev.ru>
parents: 178
diff changeset
190 ngx_http_set_ctx(r, NULL, ngx_http_addition_filter_module);
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
191
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
192 return ngx_http_send_special(r, NGX_HTTP_LAST);
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
193 }
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
194
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
195
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
196 static ngx_int_t
230
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 216
diff changeset
197 ngx_http_addition_filter_init(ngx_conf_t *cf)
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
198 {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
199 ngx_http_next_header_filter = ngx_http_top_header_filter;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
200 ngx_http_top_header_filter = ngx_http_addition_header_filter;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
201
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
202 ngx_http_next_body_filter = ngx_http_top_body_filter;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
203 ngx_http_top_body_filter = ngx_http_addition_body_filter;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
204
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
205 return NGX_OK;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
206 }
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
207
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
208
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
209 static void *
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
210 ngx_http_addition_create_conf(ngx_conf_t *cf)
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
211 {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
212 ngx_http_addition_conf_t *conf;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
213
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
214 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_addition_conf_t));
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
215 if (conf == NULL) {
496
f39b9e29530d nginx 0.8.0
Igor Sysoev <http://sysoev.ru>
parents: 426
diff changeset
216 return NULL;
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
217 }
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
218
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
219 /*
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
220 * set by ngx_pcalloc():
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
221 *
394
05981f639d21 nginx 0.7.9
Igor Sysoev <http://sysoev.ru>
parents: 286
diff changeset
222 * conf->before_body = { 0, NULL };
05981f639d21 nginx 0.7.9
Igor Sysoev <http://sysoev.ru>
parents: 286
diff changeset
223 * conf->after_body = { 0, NULL };
05981f639d21 nginx 0.7.9
Igor Sysoev <http://sysoev.ru>
parents: 286
diff changeset
224 * conf->types = { NULL };
05981f639d21 nginx 0.7.9
Igor Sysoev <http://sysoev.ru>
parents: 286
diff changeset
225 * conf->types_keys = NULL;
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
226 */
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
227
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
228 return conf;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
229 }
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
230
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
231
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
232 static char *
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
233 ngx_http_addition_merge_conf(ngx_conf_t *cf, void *parent, void *child)
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
234 {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
235 ngx_http_addition_conf_t *prev = parent;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
236 ngx_http_addition_conf_t *conf = child;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
237
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
238 ngx_conf_merge_str_value(conf->before_body, prev->before_body, "");
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
239 ngx_conf_merge_str_value(conf->after_body, prev->after_body, "");
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
240
554
5c576ea5dbd9 nginx 0.8.29
Igor Sysoev <http://sysoev.ru>
parents: 528
diff changeset
241 if (ngx_http_merge_types(cf, &conf->types_keys, &conf->types,
5c576ea5dbd9 nginx 0.8.29
Igor Sysoev <http://sysoev.ru>
parents: 528
diff changeset
242 &prev->types_keys, &prev->types,
394
05981f639d21 nginx 0.7.9
Igor Sysoev <http://sysoev.ru>
parents: 286
diff changeset
243 ngx_http_html_default_types)
05981f639d21 nginx 0.7.9
Igor Sysoev <http://sysoev.ru>
parents: 286
diff changeset
244 != NGX_OK)
05981f639d21 nginx 0.7.9
Igor Sysoev <http://sysoev.ru>
parents: 286
diff changeset
245 {
05981f639d21 nginx 0.7.9
Igor Sysoev <http://sysoev.ru>
parents: 286
diff changeset
246 return NGX_CONF_ERROR;
05981f639d21 nginx 0.7.9
Igor Sysoev <http://sysoev.ru>
parents: 286
diff changeset
247 }
05981f639d21 nginx 0.7.9
Igor Sysoev <http://sysoev.ru>
parents: 286
diff changeset
248
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
249 return NGX_CONF_OK;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
250 }