annotate src/http/modules/ngx_http_addition_filter_module.c @ 178:87699398f955 NGINX_0_3_36

nginx 0.3.36 *) Feature: the ngx_http_addition_filter_module. *) Feature: the "proxy_pass" and "fastcgi_pass" directives may be used inside the "if" block. *) Feature: the "proxy_ignore_client_abort" and "fastcgi_ignore_client_abort" directives. *) Feature: the "$request_completion" variable. *) Feature: the ngx_http_perl_module supports the $r->request_method and $r->remote_addr. *) Feature: the ngx_http_ssi_module supports the "elif" command. *) Bugfix: the "\/" string in the expression of the "if" command of the ngx_http_ssi_module was treated incorrectly. *) Bugfix: in the regular expressions in the "if" command of the ngx_http_ssi_module. *) Bugfix: if the relative path was specified in the "client_body_temp_path", "proxy_temp_path", "fastcgi_temp_path", and "perl_modules" directives, then the directory was used relatively to a current path but not to a server prefix.
author Igor Sysoev <http://sysoev.ru>
date Wed, 05 Apr 2006 00:00:00 +0400
parents
children 4cd3e70c4d60
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
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
4 */
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 #include <ngx_config.h>
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
8 #include <ngx_core.h>
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
9 #include <ngx_http.h>
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
10
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 typedef struct {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
13 ngx_str_t before_body;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
14 ngx_str_t after_body;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
15 } ngx_http_addition_conf_t;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
16
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
17
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
18 typedef struct {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
19 unsigned before_body_sent:1;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
20 unsigned after_body_sent:1;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
21 } ngx_http_addition_ctx_t;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
22
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
23
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
24 static ngx_int_t ngx_http_addition_filter_init(ngx_cycle_t *cycle);
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
25 static void *ngx_http_addition_create_conf(ngx_conf_t *cf);
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
26 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
27 void *child);
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
28
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
29
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
30 static ngx_command_t ngx_http_addition_commands[] = {
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 { ngx_string("add_before_body"),
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
33 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
34 ngx_conf_set_str_slot,
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
35 NGX_HTTP_LOC_CONF_OFFSET,
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
36 offsetof(ngx_http_addition_conf_t, before_body),
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
37 NULL },
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
38
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
39 { ngx_string("add_after_body"),
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
40 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
41 ngx_conf_set_str_slot,
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
42 NGX_HTTP_LOC_CONF_OFFSET,
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
43 offsetof(ngx_http_addition_conf_t, after_body),
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
44 NULL },
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
45
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
46 ngx_null_command
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
47 };
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
48
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
49
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
50 static ngx_http_module_t ngx_http_addition_filter_module_ctx = {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
51 NULL, /* preconfiguration */
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
52 NULL, /* postconfiguration */
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
53
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
54 NULL, /* create main configuration */
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
55 NULL, /* init main configuration */
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
56
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
57 NULL, /* create server configuration */
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
58 NULL, /* merge server configuration */
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 ngx_http_addition_create_conf, /* create location configuration */
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
61 ngx_http_addition_merge_conf /* merge location configuration */
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
62 };
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
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
65 ngx_module_t ngx_http_addition_filter_module = {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
66 NGX_MODULE_V1,
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
67 &ngx_http_addition_filter_module_ctx, /* module context */
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
68 ngx_http_addition_commands, /* module directives */
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
69 NGX_HTTP_MODULE, /* module type */
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
70 NULL, /* init master */
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
71 ngx_http_addition_filter_init, /* init module */
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
72 NULL, /* init process */
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
73 NULL, /* init thread */
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
74 NULL, /* exit thread */
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
75 NULL, /* exit process */
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
76 NULL, /* exit master */
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
77 NGX_MODULE_V1_PADDING
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
78 };
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
79
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
80
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
81 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
82 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
83
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
84
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
85 static ngx_int_t
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
86 ngx_http_addition_header_filter(ngx_http_request_t *r)
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
87 {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
88 ngx_http_addition_ctx_t *ctx;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
89 ngx_http_addition_conf_t *conf;
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 if (r->headers_out.status != NGX_HTTP_OK || r != r->main) {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
92 return ngx_http_next_header_filter(r);
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 if (ngx_strncasecmp(r->headers_out.content_type.data, "text/html",
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
96 sizeof("text/html") - 1)
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
97 != 0)
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
98 {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
99 return ngx_http_next_header_filter(r);
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
100 }
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
101
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
102 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
103
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
104 if (conf->before_body.len == 0 && conf->after_body.len == 0) {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
105 return ngx_http_next_header_filter(r);
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
106 }
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
107
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
108 ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_addition_ctx_t));
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
109 if (ctx == NULL) {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
110 return NGX_ERROR;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
111 }
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
112
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
113 ngx_http_set_ctx(r, ctx, ngx_http_addition_filter_module);
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 ngx_http_clear_content_length(r);
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
116 ngx_http_clear_accept_ranges(r);
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
117
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
118 return ngx_http_next_header_filter(r);
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
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 static ngx_int_t
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
123 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
124 {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
125 ngx_int_t rc;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
126 ngx_uint_t last;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
127 ngx_chain_t *cl;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
128 ngx_http_addition_ctx_t *ctx;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
129 ngx_http_addition_conf_t *conf;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
130
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
131 if (in == NULL || r->header_only) {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
132 return ngx_http_next_body_filter(r, in);
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
133 }
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
134
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
135 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
136
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
137 if (ctx == NULL) {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
138 return ngx_http_next_body_filter(r, in);
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
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
141 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
142
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
143 if (!ctx->before_body_sent) {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
144 ctx->before_body_sent = 1;
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 (conf->before_body.len) {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
147 if (ngx_http_subrequest(r, &conf->before_body, NULL, 0) != NGX_OK) {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
148 return NGX_ERROR;
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 }
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
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
153 last = 0;
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 for (cl = in; cl; cl = cl->next) {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
156 if (cl->buf->last_buf) {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
157 cl->buf->last_buf = 0;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
158 last = 1;
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 rc = ngx_http_next_body_filter(r, in);
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
163
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
164 if (rc == NGX_ERROR
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
165 || !last
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
166 || ctx->after_body_sent
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
167 || conf->after_body.len == 0)
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
168 {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
169 return rc;
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
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
172 if (ngx_http_subrequest(r, &conf->after_body, NULL, 0) != NGX_OK) {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
173 return NGX_ERROR;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
174 }
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 ctx->after_body_sent = 1;
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 return ngx_http_send_special(r, NGX_HTTP_LAST);
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
179 }
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
180
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
181
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
182 static ngx_int_t
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
183 ngx_http_addition_filter_init(ngx_cycle_t *cycle)
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
184 {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
185 ngx_http_next_header_filter = ngx_http_top_header_filter;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
186 ngx_http_top_header_filter = ngx_http_addition_header_filter;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
187
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
188 ngx_http_next_body_filter = ngx_http_top_body_filter;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
189 ngx_http_top_body_filter = ngx_http_addition_body_filter;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
190
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
191 return NGX_OK;
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
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 static void *
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
196 ngx_http_addition_create_conf(ngx_conf_t *cf)
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
197 {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
198 ngx_http_addition_conf_t *conf;
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 conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_addition_conf_t));
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
201 if (conf == NULL) {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
202 return NGX_CONF_ERROR;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
203 }
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 /*
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
206 * set by ngx_pcalloc():
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 * conf->before_body.len = 0;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
209 * conf->before_body.date = NULL;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
210 * conf->after_body.len = 0;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
211 * conf->after_body.date = NULL;
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
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
214 return conf;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
215 }
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
216
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 static char *
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
219 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
220 {
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
221 ngx_http_addition_conf_t *prev = parent;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
222 ngx_http_addition_conf_t *conf = child;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
223
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
224 ngx_conf_merge_str_value(conf->before_body, prev->before_body, "");
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
225 ngx_conf_merge_str_value(conf->after_body, prev->after_body, "");
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 return NGX_CONF_OK;
87699398f955 nginx 0.3.36
Igor Sysoev <http://sysoev.ru>
parents:
diff changeset
228 }