Mercurial > hg > nginx
comparison src/http/modules/ngx_http_addition_filter_module.c @ 631:5d2b8078c1c2 release-0.3.37
nginx-0.3.37-RELEASE import
*) Feature: the "limit_except" directive.
*) Feature: the "if" directive supports the "!~", "!~*", "-f", and
"!-f" operators.
*) Feature: the ngx_http_perl_module supports the $r->request_body
method.
*) Bugfix: in the ngx_http_addition_filter_module.
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Fri, 07 Apr 2006 14:08:04 +0000 |
parents | 65bf042c0b4f |
children | 4946078f0a79 |
comparison
equal
deleted
inserted
replaced
630:375dab4fd227 | 631:5d2b8078c1c2 |
---|---|
14 ngx_str_t after_body; | 14 ngx_str_t after_body; |
15 } ngx_http_addition_conf_t; | 15 } ngx_http_addition_conf_t; |
16 | 16 |
17 | 17 |
18 typedef struct { | 18 typedef struct { |
19 unsigned before_body_sent:1; | 19 ngx_uint_t before_body_sent; |
20 unsigned after_body_sent:1; | |
21 } ngx_http_addition_ctx_t; | 20 } ngx_http_addition_ctx_t; |
22 | 21 |
23 | 22 |
24 static ngx_int_t ngx_http_addition_filter_init(ngx_cycle_t *cycle); | 23 static ngx_int_t ngx_http_addition_filter_init(ngx_cycle_t *cycle); |
25 static void *ngx_http_addition_create_conf(ngx_conf_t *cf); | 24 static void *ngx_http_addition_create_conf(ngx_conf_t *cf); |
90 | 89 |
91 if (r->headers_out.status != NGX_HTTP_OK || r != r->main) { | 90 if (r->headers_out.status != NGX_HTTP_OK || r != r->main) { |
92 return ngx_http_next_header_filter(r); | 91 return ngx_http_next_header_filter(r); |
93 } | 92 } |
94 | 93 |
94 conf = ngx_http_get_module_loc_conf(r, ngx_http_addition_filter_module); | |
95 | |
96 if (conf->before_body.len == 0 && conf->after_body.len == 0) { | |
97 return ngx_http_next_header_filter(r); | |
98 } | |
99 | |
95 if (ngx_strncasecmp(r->headers_out.content_type.data, "text/html", | 100 if (ngx_strncasecmp(r->headers_out.content_type.data, "text/html", |
96 sizeof("text/html") - 1) | 101 sizeof("text/html") - 1) |
97 != 0) | 102 != 0) |
98 { | 103 { |
99 return ngx_http_next_header_filter(r); | 104 return ngx_http_next_header_filter(r); |
100 } | 105 } |
101 | 106 |
102 conf = ngx_http_get_module_loc_conf(r, ngx_http_addition_filter_module); | |
103 | |
104 if (conf->before_body.len == 0 && conf->after_body.len == 0) { | |
105 return ngx_http_next_header_filter(r); | |
106 } | |
107 | |
108 ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_addition_ctx_t)); | 107 ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_addition_ctx_t)); |
109 if (ctx == NULL) { | 108 if (ctx == NULL) { |
110 return NGX_ERROR; | 109 return NGX_ERROR; |
111 } | 110 } |
112 | 111 |
153 last = 0; | 152 last = 0; |
154 | 153 |
155 for (cl = in; cl; cl = cl->next) { | 154 for (cl = in; cl; cl = cl->next) { |
156 if (cl->buf->last_buf) { | 155 if (cl->buf->last_buf) { |
157 cl->buf->last_buf = 0; | 156 cl->buf->last_buf = 0; |
157 cl->buf->sync = 1; | |
158 last = 1; | 158 last = 1; |
159 } | 159 } |
160 } | 160 } |
161 | 161 |
162 rc = ngx_http_next_body_filter(r, in); | 162 rc = ngx_http_next_body_filter(r, in); |
163 | 163 |
164 if (rc == NGX_ERROR | 164 if (rc == NGX_ERROR || !last || conf->after_body.len == 0) { |
165 || !last | |
166 || ctx->after_body_sent | |
167 || conf->after_body.len == 0) | |
168 { | |
169 return rc; | 165 return rc; |
170 } | 166 } |
171 | 167 |
172 if (ngx_http_subrequest(r, &conf->after_body, NULL, 0) != NGX_OK) { | 168 if (ngx_http_subrequest(r, &conf->after_body, NULL, 0) != NGX_OK) { |
173 return NGX_ERROR; | 169 return NGX_ERROR; |
174 } | 170 } |
175 | 171 |
176 ctx->after_body_sent = 1; | 172 ngx_http_set_ctx(r, NULL, ngx_http_addition_filter_module); |
177 | 173 |
178 return ngx_http_send_special(r, NGX_HTTP_LAST); | 174 return ngx_http_send_special(r, NGX_HTTP_LAST); |
179 } | 175 } |
180 | 176 |
181 | 177 |