annotate src/http/modules/ngx_http_addition_filter_module.c @ 680:597573166f34 NGINX_1_3_3

nginx 1.3.3 *) Feature: entity tags support and the "etag" directive. *) Bugfix: trailing dot in a source value was not ignored if the "map" directive was used with the "hostnames" parameter. *) Bugfix: incorrect location might be used to process a request if a URI was changed via a "rewrite" directive before an internal redirect to a named location.
author Igor Sysoev <http://sysoev.ru>
date Tue, 10 Jul 2012 00:00:00 +0400
parents d0f7a625f27c
children
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);
680
597573166f34 nginx 1.3.3
Igor Sysoev <http://sysoev.ru>
parents: 660
diff changeset
124 ngx_http_clear_etag(r);
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
125
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
126 return ngx_http_next_header_filter(r);
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
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
130 static ngx_int_t
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
131 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
132 {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
133 ngx_int_t rc;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
134 ngx_uint_t last;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
135 ngx_chain_t *cl;
244
500a3242dff6 nginx 0.4.7
Igor Sysoev <http://sysoev.ru>
parents: 230
diff changeset
136 ngx_http_request_t *sr;
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
137 ngx_http_addition_ctx_t *ctx;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
138 ngx_http_addition_conf_t *conf;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
139
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
140 if (in == NULL || r->header_only) {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
141 return ngx_http_next_body_filter(r, in);
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
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
144 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
145
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
146 if (ctx == NULL) {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
147 return ngx_http_next_body_filter(r, in);
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
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
150 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
151
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
152 if (!ctx->before_body_sent) {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
153 ctx->before_body_sent = 1;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
154
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
155 if (conf->before_body.len) {
426
e7dbea1ee115 nginx 0.7.25
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
156 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
157 != NGX_OK)
e7dbea1ee115 nginx 0.7.25
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
158 {
e7dbea1ee115 nginx 0.7.25
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
159 return NGX_ERROR;
178
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 }
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
163
256
2e9c57a5e50a nginx 0.4.13
Igor Sysoev <http://sysoev.ru>
parents: 248
diff changeset
164 if (conf->after_body.len == 0) {
2e9c57a5e50a nginx 0.4.13
Igor Sysoev <http://sysoev.ru>
parents: 248
diff changeset
165 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
166 return ngx_http_next_body_filter(r, in);
2e9c57a5e50a nginx 0.4.13
Igor Sysoev <http://sysoev.ru>
parents: 248
diff changeset
167 }
2e9c57a5e50a nginx 0.4.13
Igor Sysoev <http://sysoev.ru>
parents: 248
diff changeset
168
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
169 last = 0;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
170
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
171 for (cl = in; cl; cl = cl->next) {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
172 if (cl->buf->last_buf) {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
173 cl->buf->last_buf = 0;
180
4cd3e70c4d60 nginx 0.3.37
Igor Sysoev <http://sysoev.ru>
parents: 178
diff changeset
174 cl->buf->sync = 1;
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
175 last = 1;
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
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
179 rc = ngx_http_next_body_filter(r, in);
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
180
180
4cd3e70c4d60 nginx 0.3.37
Igor Sysoev <http://sysoev.ru>
parents: 178
diff changeset
181 if (rc == NGX_ERROR || !last || conf->after_body.len == 0) {
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
182 return rc;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
183 }
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
184
426
e7dbea1ee115 nginx 0.7.25
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
185 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
186 != NGX_OK)
e7dbea1ee115 nginx 0.7.25
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
187 {
e7dbea1ee115 nginx 0.7.25
Igor Sysoev <http://sysoev.ru>
parents: 394
diff changeset
188 return NGX_ERROR;
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
189 }
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
190
180
4cd3e70c4d60 nginx 0.3.37
Igor Sysoev <http://sysoev.ru>
parents: 178
diff changeset
191 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
192
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
193 return ngx_http_send_special(r, NGX_HTTP_LAST);
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
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
197 static ngx_int_t
230
38e7b94d63ac nginx 0.4.0
Igor Sysoev <http://sysoev.ru>
parents: 216
diff changeset
198 ngx_http_addition_filter_init(ngx_conf_t *cf)
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
199 {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
200 ngx_http_next_header_filter = ngx_http_top_header_filter;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
201 ngx_http_top_header_filter = ngx_http_addition_header_filter;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
202
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
203 ngx_http_next_body_filter = ngx_http_top_body_filter;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
204 ngx_http_top_body_filter = ngx_http_addition_body_filter;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
205
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
206 return NGX_OK;
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
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
210 static void *
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
211 ngx_http_addition_create_conf(ngx_conf_t *cf)
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
212 {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
213 ngx_http_addition_conf_t *conf;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
214
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
215 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_addition_conf_t));
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
216 if (conf == NULL) {
496
f39b9e29530d nginx 0.8.0
Igor Sysoev <http://sysoev.ru>
parents: 426
diff changeset
217 return NULL;
178
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 /*
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
221 * set by ngx_pcalloc():
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
222 *
394
05981f639d21 nginx 0.7.9
Igor Sysoev <http://sysoev.ru>
parents: 286
diff changeset
223 * conf->before_body = { 0, NULL };
05981f639d21 nginx 0.7.9
Igor Sysoev <http://sysoev.ru>
parents: 286
diff changeset
224 * conf->after_body = { 0, NULL };
05981f639d21 nginx 0.7.9
Igor Sysoev <http://sysoev.ru>
parents: 286
diff changeset
225 * conf->types = { NULL };
05981f639d21 nginx 0.7.9
Igor Sysoev <http://sysoev.ru>
parents: 286
diff changeset
226 * conf->types_keys = NULL;
178
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
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
229 return conf;
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
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
233 static char *
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
234 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
235 {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
236 ngx_http_addition_conf_t *prev = parent;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
237 ngx_http_addition_conf_t *conf = child;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
238
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
239 ngx_conf_merge_str_value(conf->before_body, prev->before_body, "");
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
240 ngx_conf_merge_str_value(conf->after_body, prev->after_body, "");
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
241
554
5c576ea5dbd9 nginx 0.8.29
Igor Sysoev <http://sysoev.ru>
parents: 528
diff changeset
242 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
243 &prev->types_keys, &prev->types,
394
05981f639d21 nginx 0.7.9
Igor Sysoev <http://sysoev.ru>
parents: 286
diff changeset
244 ngx_http_html_default_types)
05981f639d21 nginx 0.7.9
Igor Sysoev <http://sysoev.ru>
parents: 286
diff changeset
245 != NGX_OK)
05981f639d21 nginx 0.7.9
Igor Sysoev <http://sysoev.ru>
parents: 286
diff changeset
246 {
05981f639d21 nginx 0.7.9
Igor Sysoev <http://sysoev.ru>
parents: 286
diff changeset
247 return NGX_CONF_ERROR;
05981f639d21 nginx 0.7.9
Igor Sysoev <http://sysoev.ru>
parents: 286
diff changeset
248 }
05981f639d21 nginx 0.7.9
Igor Sysoev <http://sysoev.ru>
parents: 286
diff changeset
249
178
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
250 return NGX_CONF_OK;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
251 }