Mercurial > hg > nginx
annotate src/http/modules/perl/nginx.xs @ 7530:fd9252844ec1
Perl: avoid returning 500 if header was already sent.
Returning NGX_HTTP_INTERNAL_SERVER_ERROR if a perl code died after
sending header will lead to a "header already sent" alert. To avoid
it, we now check if header was already sent, and return NGX_ERROR
instead if it was.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Fri, 12 Jul 2019 15:39:25 +0300 |
parents | 0cb693b4cbbb |
children | ede052c67512 |
rev | line source |
---|---|
599 | 1 |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4412 | 4 * Copyright (C) Nginx, Inc. |
599 | 5 */ |
6 | |
7 | |
882
26c3e48b9996
the PERL_NO_GET_CONTEXT is actually required, see perlguts
Igor Sysoev <igor@sysoev.ru>
parents:
869
diff
changeset
|
8 #define PERL_NO_GET_CONTEXT |
26c3e48b9996
the PERL_NO_GET_CONTEXT is actually required, see perlguts
Igor Sysoev <igor@sysoev.ru>
parents:
869
diff
changeset
|
9 |
599 | 10 #include <ngx_config.h> |
11 #include <ngx_core.h> | |
12 #include <ngx_http.h> | |
13 #include <ngx_http_perl_module.h> | |
14 | |
603 | 15 #include "XSUB.h" |
16 | |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
17 |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
18 #define ngx_http_perl_set_request(r, ctx) \ |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
19 \ |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
20 ctx = INT2PTR(ngx_http_perl_ctx_t *, SvIV((SV *) SvRV(ST(0)))); \ |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
21 r = ctx->request |
633 | 22 |
23 | |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
24 #define ngx_http_perl_set_targ(p, len) \ |
633 | 25 \ |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
26 SvUPGRADE(TARG, SVt_PV); \ |
633 | 27 SvPOK_on(TARG); \ |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
28 sv_setpvn(TARG, (char *) p, len) |
633 | 29 |
599 | 30 |
31 static ngx_int_t | |
32 ngx_http_perl_sv2str(pTHX_ ngx_http_request_t *r, ngx_str_t *s, SV *sv) | |
33 { | |
34 u_char *p; | |
35 STRLEN len; | |
36 | |
37 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PV) { | |
38 sv = SvRV(sv); | |
39 } | |
40 | |
41 p = (u_char *) SvPV(sv, len); | |
42 | |
43 s->len = len; | |
44 | |
1703
43747661804d
*) copy regex captures $1, $2, etc.
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
45 if (SvREADONLY(sv) && SvPOK(sv)) { |
599 | 46 s->data = p; |
1703
43747661804d
*) copy regex captures $1, $2, etc.
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
47 |
43747661804d
*) copy regex captures $1, $2, etc.
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
48 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
43747661804d
*) copy regex captures $1, $2, etc.
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
49 "perl sv2str: %08XD \"%V\"", sv->sv_flags, s); |
43747661804d
*) copy regex captures $1, $2, etc.
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
50 |
599 | 51 return NGX_OK; |
52 } | |
53 | |
2049 | 54 s->data = ngx_pnalloc(r->pool, len); |
599 | 55 if (s->data == NULL) { |
56 return NGX_ERROR; | |
57 } | |
58 | |
59 ngx_memcpy(s->data, p, len); | |
60 | |
1703
43747661804d
*) copy regex captures $1, $2, etc.
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
61 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
43747661804d
*) copy regex captures $1, $2, etc.
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
62 "perl sv2str: %08XD \"%V\"", sv->sv_flags, s); |
43747661804d
*) copy regex captures $1, $2, etc.
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
63 |
599 | 64 return NGX_OK; |
65 } | |
66 | |
67 | |
68 static ngx_int_t | |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
69 ngx_http_perl_output(ngx_http_request_t *r, ngx_http_perl_ctx_t *ctx, |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
70 ngx_buf_t *b) |
599 | 71 { |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
72 ngx_chain_t out; |
617 | 73 #if (NGX_HTTP_SSI) |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
74 ngx_chain_t *cl; |
599 | 75 |
76 if (ctx->ssi) { | |
77 cl = ngx_alloc_chain_link(r->pool); | |
78 if (cl == NULL) { | |
79 return NGX_ERROR; | |
80 } | |
81 | |
82 cl->buf = b; | |
83 cl->next = NULL; | |
84 *ctx->ssi->last_out = cl; | |
85 ctx->ssi->last_out = &cl->next; | |
86 | |
87 return NGX_OK; | |
88 } | |
617 | 89 #endif |
599 | 90 |
91 out.buf = b; | |
92 out.next = NULL; | |
93 | |
94 return ngx_http_output_filter(r, &out); | |
95 } | |
96 | |
97 | |
98 MODULE = nginx PACKAGE = nginx | |
99 | |
100 | |
6233
c6cc0b79a43d
Perl: prototyping behavior explicitly specified.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6232
diff
changeset
|
101 PROTOTYPES: DISABLE |
c6cc0b79a43d
Perl: prototyping behavior explicitly specified.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6232
diff
changeset
|
102 |
c6cc0b79a43d
Perl: prototyping behavior explicitly specified.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6232
diff
changeset
|
103 |
633 | 104 void |
915 | 105 status(r, code) |
106 CODE: | |
107 | |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
108 ngx_http_request_t *r; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
109 ngx_http_perl_ctx_t *ctx; |
915 | 110 |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
111 ngx_http_perl_set_request(r, ctx); |
915 | 112 |
7528
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
113 if (ctx->variable) { |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
114 croak("status(): cannot be used in variable handler"); |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
115 } |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
116 |
915 | 117 r->headers_out.status = SvIV(ST(1)); |
118 | |
119 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
120 "perl status: %d", r->headers_out.status); | |
121 | |
122 XSRETURN_UNDEF; | |
123 | |
124 | |
125 void | |
599 | 126 send_http_header(r, ...) |
633 | 127 CODE: |
599 | 128 |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
129 ngx_http_request_t *r; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
130 ngx_http_perl_ctx_t *ctx; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
131 SV *sv; |
7525 | 132 ngx_int_t rc; |
599 | 133 |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
134 ngx_http_perl_set_request(r, ctx); |
599 | 135 |
7525 | 136 if (ctx->error) { |
137 croak("send_http_header(): called after error"); | |
138 } | |
139 | |
7528
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
140 if (ctx->variable) { |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
141 croak("send_http_header(): cannot be used in variable handler"); |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
142 } |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
143 |
599 | 144 if (r->headers_out.status == 0) { |
145 r->headers_out.status = NGX_HTTP_OK; | |
146 } | |
147 | |
148 if (items != 1) { | |
149 sv = ST(1); | |
150 | |
151 if (ngx_http_perl_sv2str(aTHX_ r, &r->headers_out.content_type, sv) | |
152 != NGX_OK) | |
153 { | |
7526
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
154 ctx->error = 1; |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
155 croak("ngx_http_perl_sv2str() failed"); |
599 | 156 } |
157 | |
1444
37938e68910b
allow to append charset to the "Content-Type" header
Igor Sysoev <igor@sysoev.ru>
parents:
1372
diff
changeset
|
158 r->headers_out.content_type_len = r->headers_out.content_type.len; |
37938e68910b
allow to append charset to the "Content-Type" header
Igor Sysoev <igor@sysoev.ru>
parents:
1372
diff
changeset
|
159 |
599 | 160 } else { |
673 | 161 if (ngx_http_set_content_type(r) != NGX_OK) { |
7526
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
162 ctx->error = 1; |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
163 croak("ngx_http_set_content_type() failed"); |
599 | 164 } |
165 } | |
166 | |
7530
fd9252844ec1
Perl: avoid returning 500 if header was already sent.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7528
diff
changeset
|
167 ctx->header_sent = 1; |
fd9252844ec1
Perl: avoid returning 500 if header was already sent.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7528
diff
changeset
|
168 |
7516
36c52a0f6ded
Perl: disabled not_modified filter (ticket #1786).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6986
diff
changeset
|
169 r->disable_not_modified = 1; |
36c52a0f6ded
Perl: disabled not_modified filter (ticket #1786).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6986
diff
changeset
|
170 |
7525 | 171 rc = ngx_http_send_header(r); |
172 | |
173 if (rc == NGX_ERROR || rc > NGX_OK) { | |
174 ctx->error = 1; | |
175 ctx->status = rc; | |
176 croak("ngx_http_send_header() failed"); | |
177 } | |
599 | 178 |
179 | |
633 | 180 void |
181 header_only(r) | |
599 | 182 CODE: |
183 | |
633 | 184 dXSTARG; |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
185 ngx_http_request_t *r; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
186 ngx_http_perl_ctx_t *ctx; |
633 | 187 |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
188 ngx_http_perl_set_request(r, ctx); |
599 | 189 |
633 | 190 sv_upgrade(TARG, SVt_IV); |
191 sv_setiv(TARG, r->header_only); | |
599 | 192 |
633 | 193 ST(0) = TARG; |
599 | 194 |
195 | |
633 | 196 void |
197 uri(r) | |
198 CODE: | |
199 | |
200 dXSTARG; | |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
201 ngx_http_request_t *r; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
202 ngx_http_perl_ctx_t *ctx; |
599 | 203 |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
204 ngx_http_perl_set_request(r, ctx); |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
205 ngx_http_perl_set_targ(r->uri.data, r->uri.len); |
633 | 206 |
207 ST(0) = TARG; | |
208 | |
209 | |
210 void | |
211 args(r) | |
599 | 212 CODE: |
213 | |
633 | 214 dXSTARG; |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
215 ngx_http_request_t *r; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
216 ngx_http_perl_ctx_t *ctx; |
599 | 217 |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
218 ngx_http_perl_set_request(r, ctx); |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
219 ngx_http_perl_set_targ(r->args.data, r->args.len); |
599 | 220 |
633 | 221 ST(0) = TARG; |
599 | 222 |
223 | |
633 | 224 void |
629 | 225 request_method(r) |
633 | 226 CODE: |
227 | |
228 dXSTARG; | |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
229 ngx_http_request_t *r; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
230 ngx_http_perl_ctx_t *ctx; |
629 | 231 |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
232 ngx_http_perl_set_request(r, ctx); |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
233 ngx_http_perl_set_targ(r->method_name.data, r->method_name.len); |
633 | 234 |
235 ST(0) = TARG; | |
236 | |
237 | |
238 void | |
239 remote_addr(r) | |
629 | 240 CODE: |
241 | |
633 | 242 dXSTARG; |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
243 ngx_http_request_t *r; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
244 ngx_http_perl_ctx_t *ctx; |
629 | 245 |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
246 ngx_http_perl_set_request(r, ctx); |
633 | 247 ngx_http_perl_set_targ(r->connection->addr_text.data, |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
248 r->connection->addr_text.len); |
629 | 249 |
633 | 250 ST(0) = TARG; |
629 | 251 |
252 | |
633 | 253 void |
254 header_in(r, key) | |
629 | 255 CODE: |
256 | |
633 | 257 dXSTARG; |
667 | 258 ngx_http_request_t *r; |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
259 ngx_http_perl_ctx_t *ctx; |
667 | 260 SV *key; |
5248
f5626ab8cb87
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5198
diff
changeset
|
261 u_char *p, *lowcase_key, *value, sep; |
667 | 262 STRLEN len; |
263 ssize_t size; | |
264 ngx_uint_t i, n, hash; | |
5248
f5626ab8cb87
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5198
diff
changeset
|
265 ngx_array_t *a; |
667 | 266 ngx_list_part_t *part; |
267 ngx_table_elt_t *h, **ph; | |
268 ngx_http_header_t *hh; | |
269 ngx_http_core_main_conf_t *cmcf; | |
629 | 270 |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
271 ngx_http_perl_set_request(r, ctx); |
599 | 272 |
633 | 273 key = ST(1); |
599 | 274 |
275 if (SvROK(key) && SvTYPE(SvRV(key)) == SVt_PV) { | |
276 key = SvRV(key); | |
277 } | |
278 | |
279 p = (u_char *) SvPV(key, len); | |
280 | |
667 | 281 /* look up hashed headers */ |
282 | |
2049 | 283 lowcase_key = ngx_pnalloc(r->pool, len); |
667 | 284 if (lowcase_key == NULL) { |
7526
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
285 ctx->error = 1; |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
286 croak("ngx_pnalloc() failed"); |
667 | 287 } |
288 | |
2136 | 289 hash = ngx_hash_strlow(lowcase_key, p, len); |
667 | 290 |
291 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); | |
292 | |
293 hh = ngx_hash_find(&cmcf->headers_in_hash, hash, lowcase_key, len); | |
294 | |
295 if (hh) { | |
5248
f5626ab8cb87
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5198
diff
changeset
|
296 |
f5626ab8cb87
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5198
diff
changeset
|
297 if (hh->offset == offsetof(ngx_http_headers_in_t, cookies)) { |
f5626ab8cb87
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5198
diff
changeset
|
298 sep = ';'; |
f5626ab8cb87
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5198
diff
changeset
|
299 goto multi; |
f5626ab8cb87
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5198
diff
changeset
|
300 } |
5306
43900b822890
Perl: fixed syntax usage for C preprocessor directives.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5248
diff
changeset
|
301 #if (NGX_HTTP_X_FORWARDED_FOR) |
5248
f5626ab8cb87
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5198
diff
changeset
|
302 if (hh->offset == offsetof(ngx_http_headers_in_t, x_forwarded_for)) { |
f5626ab8cb87
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5198
diff
changeset
|
303 sep = ','; |
f5626ab8cb87
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5198
diff
changeset
|
304 goto multi; |
f5626ab8cb87
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5198
diff
changeset
|
305 } |
5306
43900b822890
Perl: fixed syntax usage for C preprocessor directives.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5248
diff
changeset
|
306 #endif |
5248
f5626ab8cb87
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5198
diff
changeset
|
307 |
6232
5f2a0739da19
Perl: fixed warning about "sep" may be used uninitialized.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5306
diff
changeset
|
308 ph = (ngx_table_elt_t **) ((char *) &r->headers_in + hh->offset); |
667 | 309 |
6232
5f2a0739da19
Perl: fixed warning about "sep" may be used uninitialized.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5306
diff
changeset
|
310 if (*ph) { |
5f2a0739da19
Perl: fixed warning about "sep" may be used uninitialized.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5306
diff
changeset
|
311 ngx_http_perl_set_targ((*ph)->value.data, (*ph)->value.len); |
667 | 312 |
6232
5f2a0739da19
Perl: fixed warning about "sep" may be used uninitialized.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5306
diff
changeset
|
313 goto done; |
5f2a0739da19
Perl: fixed warning about "sep" may be used uninitialized.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5306
diff
changeset
|
314 } |
667 | 315 |
6232
5f2a0739da19
Perl: fixed warning about "sep" may be used uninitialized.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5306
diff
changeset
|
316 XSRETURN_UNDEF; |
667 | 317 |
5248
f5626ab8cb87
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5198
diff
changeset
|
318 multi: |
f5626ab8cb87
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5198
diff
changeset
|
319 |
f5626ab8cb87
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5198
diff
changeset
|
320 /* Cookie, X-Forwarded-For */ |
667 | 321 |
5248
f5626ab8cb87
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5198
diff
changeset
|
322 a = (ngx_array_t *) ((char *) &r->headers_in + hh->offset); |
f5626ab8cb87
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5198
diff
changeset
|
323 |
f5626ab8cb87
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5198
diff
changeset
|
324 n = a->nelts; |
667 | 325 |
326 if (n == 0) { | |
327 XSRETURN_UNDEF; | |
328 } | |
329 | |
5248
f5626ab8cb87
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5198
diff
changeset
|
330 ph = a->elts; |
667 | 331 |
332 if (n == 1) { | |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
333 ngx_http_perl_set_targ((*ph)->value.data, (*ph)->value.len); |
667 | 334 |
335 goto done; | |
336 } | |
337 | |
338 size = - (ssize_t) (sizeof("; ") - 1); | |
339 | |
340 for (i = 0; i < n; i++) { | |
341 size += ph[i]->value.len + sizeof("; ") - 1; | |
342 } | |
343 | |
5248
f5626ab8cb87
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5198
diff
changeset
|
344 value = ngx_pnalloc(r->pool, size); |
f5626ab8cb87
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5198
diff
changeset
|
345 if (value == NULL) { |
7526
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
346 ctx->error = 1; |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
347 croak("ngx_pnalloc() failed"); |
667 | 348 } |
349 | |
5248
f5626ab8cb87
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5198
diff
changeset
|
350 p = value; |
667 | 351 |
352 for (i = 0; /* void */ ; i++) { | |
353 p = ngx_copy(p, ph[i]->value.data, ph[i]->value.len); | |
354 | |
355 if (i == n - 1) { | |
356 break; | |
357 } | |
358 | |
5248
f5626ab8cb87
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5198
diff
changeset
|
359 *p++ = sep; *p++ = ' '; |
667 | 360 } |
361 | |
5248
f5626ab8cb87
Perl: fixed r->header_in("Cookie") (ticket #351).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5198
diff
changeset
|
362 ngx_http_perl_set_targ(value, size); |
667 | 363 |
364 goto done; | |
365 } | |
366 | |
367 /* iterate over all headers */ | |
368 | |
599 | 369 part = &r->headers_in.headers.part; |
667 | 370 h = part->elts; |
599 | 371 |
372 for (i = 0; /* void */ ; i++) { | |
373 | |
374 if (i >= part->nelts) { | |
375 if (part->next == NULL) { | |
376 break; | |
377 } | |
378 | |
379 part = part->next; | |
667 | 380 h = part->elts; |
599 | 381 i = 0; |
382 } | |
383 | |
667 | 384 if (len != h[i].key.len |
385 || ngx_strcasecmp(p, h[i].key.data) != 0) | |
599 | 386 { |
387 continue; | |
388 } | |
389 | |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
390 ngx_http_perl_set_targ(h[i].value.data, h[i].value.len); |
599 | 391 |
392 goto done; | |
393 } | |
394 | |
395 XSRETURN_UNDEF; | |
396 | |
397 done: | |
398 | |
633 | 399 ST(0) = TARG; |
599 | 400 |
401 | |
633 | 402 void |
681 | 403 has_request_body(r, next) |
404 CODE: | |
405 | |
406 dXSTARG; | |
407 ngx_http_request_t *r; | |
408 ngx_http_perl_ctx_t *ctx; | |
7525 | 409 ngx_int_t rc; |
681 | 410 |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
411 ngx_http_perl_set_request(r, ctx); |
681 | 412 |
7528
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
413 if (ctx->variable) { |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
414 croak("has_request_body(): cannot be used in variable handler"); |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
415 } |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
416 |
7527
02cd116ebe2a
Perl: protection against duplicate $r->sleep() calls.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7526
diff
changeset
|
417 if (ctx->next) { |
02cd116ebe2a
Perl: protection against duplicate $r->sleep() calls.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7526
diff
changeset
|
418 croak("has_request_body(): another handler active"); |
02cd116ebe2a
Perl: protection against duplicate $r->sleep() calls.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7526
diff
changeset
|
419 } |
02cd116ebe2a
Perl: protection against duplicate $r->sleep() calls.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7526
diff
changeset
|
420 |
5181
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
421 if (r->headers_in.content_length_n <= 0 && !r->headers_in.chunked) { |
681 | 422 XSRETURN_UNDEF; |
423 } | |
424 | |
909 | 425 ctx->next = SvRV(ST(1)); |
681 | 426 |
427 r->request_body_in_single_buf = 1; | |
428 r->request_body_in_persistent_file = 1; | |
1075
4d203f76b757
undo "client_body_in_file_only any"
Igor Sysoev <igor@sysoev.ru>
parents:
1056
diff
changeset
|
429 r->request_body_in_clean_file = 1; |
681 | 430 |
431 if (r->request_body_in_file_only) { | |
432 r->request_body_file_log_level = 0; | |
433 } | |
434 | |
7525 | 435 rc = ngx_http_read_client_request_body(r, ngx_http_perl_handle_request); |
436 | |
437 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { | |
438 ctx->error = 1; | |
439 ctx->status = rc; | |
440 ctx->next = NULL; | |
441 croak("ngx_http_read_client_request_body() failed"); | |
442 } | |
681 | 443 |
444 sv_upgrade(TARG, SVt_IV); | |
445 sv_setiv(TARG, 1); | |
446 | |
447 ST(0) = TARG; | |
448 | |
449 | |
450 void | |
631 | 451 request_body(r) |
452 CODE: | |
453 | |
633 | 454 dXSTARG; |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
455 ngx_http_request_t *r; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
456 ngx_http_perl_ctx_t *ctx; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
457 u_char *p, *data; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
458 size_t len; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
459 ngx_buf_t *buf; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
460 ngx_chain_t *cl; |
633 | 461 |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
462 ngx_http_perl_set_request(r, ctx); |
631 | 463 |
941 | 464 if (r->request_body == NULL |
465 || r->request_body->temp_file | |
466 || r->request_body->bufs == NULL) | |
467 { | |
633 | 468 XSRETURN_UNDEF; |
469 } | |
631 | 470 |
5181
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
471 cl = r->request_body->bufs; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
472 buf = cl->buf; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
473 |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
474 if (cl->next == NULL) { |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
475 len = buf->last - buf->pos; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
476 data = buf->pos; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
477 goto done; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
478 } |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
479 |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
480 len = buf->last - buf->pos; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
481 cl = cl->next; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
482 |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
483 for ( /* void */ ; cl; cl = cl->next) { |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
484 buf = cl->buf; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
485 len += buf->last - buf->pos; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
486 } |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
487 |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
488 p = ngx_pnalloc(r->pool, len); |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
489 if (p == NULL) { |
7526
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
490 ctx->error = 1; |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
491 croak("ngx_pnalloc() failed"); |
5181
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
492 } |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
493 |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
494 data = p; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
495 cl = r->request_body->bufs; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
496 |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
497 for ( /* void */ ; cl; cl = cl->next) { |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
498 buf = cl->buf; |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
499 p = ngx_cpymem(p, buf->pos, buf->last - buf->pos); |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
500 } |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
501 |
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
502 done: |
631 | 503 |
504 if (len == 0) { | |
505 XSRETURN_UNDEF; | |
506 } | |
507 | |
5181
4d0ac175f6e4
Perl: request body handling fixed.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4644
diff
changeset
|
508 ngx_http_perl_set_targ(data, len); |
631 | 509 |
633 | 510 ST(0) = TARG; |
631 | 511 |
512 | |
633 | 513 void |
514 request_body_file(r) | |
515 CODE: | |
516 | |
517 dXSTARG; | |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
518 ngx_http_request_t *r; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
519 ngx_http_perl_ctx_t *ctx; |
633 | 520 |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
521 ngx_http_perl_set_request(r, ctx); |
633 | 522 |
941 | 523 if (r->request_body == NULL || r->request_body->temp_file == NULL) { |
633 | 524 XSRETURN_UNDEF; |
525 } | |
526 | |
527 ngx_http_perl_set_targ(r->request_body->temp_file->file.name.data, | |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
528 r->request_body->temp_file->file.name.len); |
599 | 529 |
633 | 530 ST(0) = TARG; |
531 | |
532 | |
533 void | |
1371 | 534 discard_request_body(r) |
535 CODE: | |
536 | |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
537 ngx_http_request_t *r; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
538 ngx_http_perl_ctx_t *ctx; |
7525 | 539 ngx_int_t rc; |
1371 | 540 |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
541 ngx_http_perl_set_request(r, ctx); |
1371 | 542 |
7528
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
543 if (ctx->variable) { |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
544 croak("discard_request_body(): cannot be used in variable handler"); |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
545 } |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
546 |
7525 | 547 rc = ngx_http_discard_request_body(r); |
548 | |
549 if (rc != NGX_OK) { | |
550 ctx->error = 1; | |
551 ctx->status = rc; | |
552 croak("ngx_http_discard_request_body() failed"); | |
553 } | |
1371 | 554 |
555 | |
556 void | |
633 | 557 header_out(r, key, value) |
558 CODE: | |
599 | 559 |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
560 ngx_http_request_t *r; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
561 ngx_http_perl_ctx_t *ctx; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
562 SV *key; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
563 SV *value; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
564 ngx_table_elt_t *header; |
599 | 565 |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
566 ngx_http_perl_set_request(r, ctx); |
633 | 567 |
7525 | 568 if (ctx->error) { |
569 croak("header_out(): called after error"); | |
570 } | |
571 | |
7528
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
572 if (ctx->variable) { |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
573 croak("header_out(): cannot be used in variable handler"); |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
574 } |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
575 |
633 | 576 key = ST(1); |
577 value = ST(2); | |
599 | 578 |
579 header = ngx_list_push(&r->headers_out.headers); | |
580 if (header == NULL) { | |
7526
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
581 ctx->error = 1; |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
582 croak("ngx_list_push() failed"); |
599 | 583 } |
584 | |
585 header->hash = 1; | |
586 | |
587 if (ngx_http_perl_sv2str(aTHX_ r, &header->key, key) != NGX_OK) { | |
6986
0cdee26605f3
Cleaned up r->headers_out.headers allocation error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6960
diff
changeset
|
588 header->hash = 0; |
7526
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
589 ctx->error = 1; |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
590 croak("ngx_http_perl_sv2str() failed"); |
599 | 591 } |
592 | |
593 if (ngx_http_perl_sv2str(aTHX_ r, &header->value, value) != NGX_OK) { | |
6986
0cdee26605f3
Cleaned up r->headers_out.headers allocation error handling.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6960
diff
changeset
|
594 header->hash = 0; |
7526
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
595 ctx->error = 1; |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
596 croak("ngx_http_perl_sv2str() failed"); |
599 | 597 } |
598 | |
599 if (header->key.len == sizeof("Content-Length") - 1 | |
3870 | 600 && ngx_strncasecmp(header->key.data, (u_char *) "Content-Length", |
741
63a08390a8a2
$r->headers_out("Content-Length", "NNN") did not work
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
601 sizeof("Content-Length") - 1) == 0) |
599 | 602 { |
741
63a08390a8a2
$r->headers_out("Content-Length", "NNN") did not work
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
603 r->headers_out.content_length_n = (off_t) SvIV(value); |
599 | 604 r->headers_out.content_length = header; |
605 } | |
606 | |
4196
190ae1a7f917
Handling of Content-Encoding set from perl.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4188
diff
changeset
|
607 if (header->key.len == sizeof("Content-Encoding") - 1 |
4644
95763fce86a8
Fixed warning during nginx.xs compilation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4494
diff
changeset
|
608 && ngx_strncasecmp(header->key.data, (u_char *) "Content-Encoding", |
4196
190ae1a7f917
Handling of Content-Encoding set from perl.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4188
diff
changeset
|
609 sizeof("Content-Encoding") - 1) == 0) |
190ae1a7f917
Handling of Content-Encoding set from perl.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4188
diff
changeset
|
610 { |
190ae1a7f917
Handling of Content-Encoding set from perl.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4188
diff
changeset
|
611 r->headers_out.content_encoding = header; |
190ae1a7f917
Handling of Content-Encoding set from perl.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4188
diff
changeset
|
612 } |
190ae1a7f917
Handling of Content-Encoding set from perl.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4188
diff
changeset
|
613 |
599 | 614 |
633 | 615 void |
599 | 616 filename(r) |
633 | 617 CODE: |
599 | 618 |
633 | 619 dXSTARG; |
620 ngx_http_request_t *r; | |
599 | 621 ngx_http_perl_ctx_t *ctx; |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
622 size_t root; |
599 | 623 |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
624 ngx_http_perl_set_request(r, ctx); |
599 | 625 |
633 | 626 if (ctx->filename.data) { |
599 | 627 goto done; |
628 } | |
629 | |
774
589841f06b87
previous commit broke two modules
Igor Sysoev <igor@sysoev.ru>
parents:
741
diff
changeset
|
630 if (ngx_http_map_uri_to_path(r, &ctx->filename, &root, 0) == NULL) { |
7526
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
631 ctx->error = 1; |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
632 croak("ngx_http_map_uri_to_path() failed"); |
599 | 633 } |
634 | |
633 | 635 ctx->filename.len--; |
636 sv_setpv(PL_statname, (char *) ctx->filename.data); | |
599 | 637 |
638 done: | |
639 | |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
640 ngx_http_perl_set_targ(ctx->filename.data, ctx->filename.len); |
599 | 641 |
633 | 642 ST(0) = TARG; |
599 | 643 |
644 | |
633 | 645 void |
599 | 646 print(r, ...) |
647 CODE: | |
648 | |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
649 ngx_http_request_t *r; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
650 ngx_http_perl_ctx_t *ctx; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
651 SV *sv; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
652 int i; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
653 u_char *p; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
654 size_t size; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
655 STRLEN len; |
7525 | 656 ngx_int_t rc; |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
657 ngx_buf_t *b; |
633 | 658 |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
659 ngx_http_perl_set_request(r, ctx); |
599 | 660 |
7525 | 661 if (ctx->error) { |
662 croak("print(): called after error"); | |
663 } | |
664 | |
7528
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
665 if (ctx->variable) { |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
666 croak("print(): cannot be used in variable handler"); |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
667 } |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
668 |
599 | 669 if (items == 2) { |
670 | |
671 /* | |
672 * do zero copy for prolate single read-only SV: | |
673 * $r->print("some text\n"); | |
674 */ | |
675 | |
676 sv = ST(1); | |
677 | |
678 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PV) { | |
679 sv = SvRV(sv); | |
680 } | |
681 | |
1703
43747661804d
*) copy regex captures $1, $2, etc.
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
682 if (SvREADONLY(sv) && SvPOK(sv)) { |
599 | 683 |
684 p = (u_char *) SvPV(sv, len); | |
685 | |
686 if (len == 0) { | |
633 | 687 XSRETURN_EMPTY; |
599 | 688 } |
689 | |
690 b = ngx_calloc_buf(r->pool); | |
691 if (b == NULL) { | |
7526
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
692 ctx->error = 1; |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
693 croak("ngx_calloc_buf() failed"); |
599 | 694 } |
695 | |
696 b->memory = 1; | |
697 b->pos = p; | |
698 b->last = p + len; | |
699 b->start = p; | |
700 b->end = b->last; | |
701 | |
601 | 702 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
703 "$r->print: read-only SV: %z", len); | |
704 | |
599 | 705 goto out; |
706 } | |
707 } | |
708 | |
709 size = 0; | |
710 | |
711 for (i = 1; i < items; i++) { | |
712 | |
713 sv = ST(i); | |
714 | |
715 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PV) { | |
716 sv = SvRV(sv); | |
717 } | |
718 | |
601 | 719 (void) SvPV(sv, len); |
599 | 720 |
601 | 721 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
722 "$r->print: copy SV: %z", len); | |
599 | 723 |
724 size += len; | |
725 } | |
726 | |
727 if (size == 0) { | |
633 | 728 XSRETURN_EMPTY; |
599 | 729 } |
730 | |
731 b = ngx_create_temp_buf(r->pool, size); | |
732 if (b == NULL) { | |
7526
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
733 ctx->error = 1; |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
734 croak("ngx_create_temp_buf() failed"); |
599 | 735 } |
736 | |
737 for (i = 1; i < items; i++) { | |
738 sv = ST(i); | |
739 | |
740 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PV) { | |
741 sv = SvRV(sv); | |
742 } | |
743 | |
744 p = (u_char *) SvPV(sv, len); | |
745 b->last = ngx_cpymem(b->last, p, len); | |
746 } | |
747 | |
748 out: | |
749 | |
7525 | 750 rc = ngx_http_perl_output(r, ctx, b); |
751 | |
752 if (rc == NGX_ERROR) { | |
753 ctx->error = 1; | |
754 croak("ngx_http_perl_output() failed"); | |
755 } | |
599 | 756 |
757 | |
633 | 758 void |
613 | 759 sendfile(r, filename, offset = -1, bytes = 0) |
633 | 760 CODE: |
761 | |
1454 | 762 ngx_http_request_t *r; |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
763 ngx_http_perl_ctx_t *ctx; |
1454 | 764 char *filename; |
2794
92bd6afe8d9c
use off_t in $r->sendfile(), this allows to use 64-bit off_t on platforms
Igor Sysoev <igor@sysoev.ru>
parents:
2756
diff
changeset
|
765 off_t offset; |
1454 | 766 size_t bytes; |
7525 | 767 ngx_int_t rc; |
1454 | 768 ngx_str_t path; |
769 ngx_buf_t *b; | |
770 ngx_open_file_info_t of; | |
771 ngx_http_core_loc_conf_t *clcf; | |
599 | 772 |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
773 ngx_http_perl_set_request(r, ctx); |
633 | 774 |
7525 | 775 if (ctx->error) { |
776 croak("sendfile(): called after error"); | |
777 } | |
778 | |
7528
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
779 if (ctx->variable) { |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
780 croak("sendfile(): cannot be used in variable handler"); |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
781 } |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
782 |
633 | 783 filename = SvPV_nolen(ST(1)); |
599 | 784 |
785 if (filename == NULL) { | |
786 croak("sendfile(): NULL filename"); | |
787 } | |
788 | |
633 | 789 offset = items < 3 ? -1 : SvIV(ST(2)); |
790 bytes = items < 4 ? 0 : SvIV(ST(3)); | |
791 | |
599 | 792 b = ngx_calloc_buf(r->pool); |
793 if (b == NULL) { | |
7526
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
794 ctx->error = 1; |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
795 croak("ngx_calloc_buf() failed"); |
599 | 796 } |
797 | |
798 b->file = ngx_pcalloc(r->pool, sizeof(ngx_file_t)); | |
799 if (b->file == NULL) { | |
7526
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
800 ctx->error = 1; |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
801 croak("ngx_pcalloc() failed"); |
599 | 802 } |
803 | |
1454 | 804 path.len = ngx_strlen(filename); |
805 | |
2061
b0a1c84725cf
change useless ngx_pcalloc() to ngx_pnalloc()
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
806 path.data = ngx_pnalloc(r->pool, path.len + 1); |
1454 | 807 if (path.data == NULL) { |
7526
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
808 ctx->error = 1; |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
809 croak("ngx_pnalloc() failed"); |
599 | 810 } |
811 | |
3870 | 812 (void) ngx_cpystrn(path.data, (u_char *) filename, path.len + 1); |
1560
25ee6eee7573
style fix: remove trailing spaces
Igor Sysoev <igor@sysoev.ru>
parents:
1457
diff
changeset
|
813 |
2063
67a29af877ed
initialize of.uniq in ngx_open_cached_file()
Igor Sysoev <igor@sysoev.ru>
parents:
2061
diff
changeset
|
814 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
67a29af877ed
initialize of.uniq in ngx_open_cached_file()
Igor Sysoev <igor@sysoev.ru>
parents:
2061
diff
changeset
|
815 |
2068
75a8d34459c5
ngx_memzero() ngx_open_file_info_t
Igor Sysoev <igor@sysoev.ru>
parents:
2063
diff
changeset
|
816 ngx_memzero(&of, sizeof(ngx_open_file_info_t)); |
75a8d34459c5
ngx_memzero() ngx_open_file_info_t
Igor Sysoev <igor@sysoev.ru>
parents:
2063
diff
changeset
|
817 |
3178 | 818 of.read_ahead = clcf->read_ahead; |
2129 | 819 of.directio = clcf->directio; |
2063
67a29af877ed
initialize of.uniq in ngx_open_cached_file()
Igor Sysoev <igor@sysoev.ru>
parents:
2061
diff
changeset
|
820 of.valid = clcf->open_file_cache_valid; |
67a29af877ed
initialize of.uniq in ngx_open_cached_file()
Igor Sysoev <igor@sysoev.ru>
parents:
2061
diff
changeset
|
821 of.min_uses = clcf->open_file_cache_min_uses; |
67a29af877ed
initialize of.uniq in ngx_open_cached_file()
Igor Sysoev <igor@sysoev.ru>
parents:
2061
diff
changeset
|
822 of.errors = clcf->open_file_cache_errors; |
67a29af877ed
initialize of.uniq in ngx_open_cached_file()
Igor Sysoev <igor@sysoev.ru>
parents:
2061
diff
changeset
|
823 of.events = clcf->open_file_cache_events; |
4494
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
824 |
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
825 if (ngx_http_set_disable_symlinks(r, clcf, &path, &of) != NGX_OK) { |
7526
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
826 ctx->error = 1; |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
827 croak("ngx_http_set_disable_symlinks() failed"); |
4494
13e09cf11d4e
Disable symlinks: initialization of the "disable_symlinks" field in
Valentin Bartenev <vbart@nginx.com>
parents:
4478
diff
changeset
|
828 } |
2063
67a29af877ed
initialize of.uniq in ngx_open_cached_file()
Igor Sysoev <igor@sysoev.ru>
parents:
2061
diff
changeset
|
829 |
1799 | 830 if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool) |
831 != NGX_OK) | |
832 { | |
1454 | 833 if (of.err == 0) { |
7526
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
834 ctx->error = 1; |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
835 croak("ngx_open_cached_file() failed"); |
1454 | 836 } |
837 | |
599 | 838 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno, |
2756
09cab3f8d92e
*) of.test_only to not open file if only stat() is enough
Igor Sysoev <igor@sysoev.ru>
parents:
2231
diff
changeset
|
839 "%s \"%s\" failed", of.failed, filename); |
7526
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
840 |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
841 ctx->error = 1; |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
842 croak("ngx_open_cached_file() failed"); |
599 | 843 } |
844 | |
613 | 845 if (offset == -1) { |
846 offset = 0; | |
847 } | |
848 | |
849 if (bytes == 0) { | |
1454 | 850 bytes = of.size - offset; |
599 | 851 } |
852 | |
853 b->in_file = 1; | |
613 | 854 |
855 b->file_pos = offset; | |
856 b->file_last = offset + bytes; | |
599 | 857 |
1454 | 858 b->file->fd = of.fd; |
599 | 859 b->file->log = r->connection->log; |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2136
diff
changeset
|
860 b->file->directio = of.is_directio; |
599 | 861 |
7525 | 862 rc = ngx_http_perl_output(r, ctx, b); |
863 | |
864 if (rc == NGX_ERROR) { | |
865 ctx->error = 1; | |
866 croak("ngx_http_perl_output() failed"); | |
867 } | |
599 | 868 |
869 | |
633 | 870 void |
1178
a77f6980de50
rename $r->rflush to $r->flush
Igor Sysoev <igor@sysoev.ru>
parents:
1075
diff
changeset
|
871 flush(r) |
633 | 872 CODE: |
599 | 873 |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
874 ngx_http_request_t *r; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
875 ngx_http_perl_ctx_t *ctx; |
7525 | 876 ngx_int_t rc; |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
877 ngx_buf_t *b; |
599 | 878 |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
879 ngx_http_perl_set_request(r, ctx); |
599 | 880 |
7525 | 881 if (ctx->error) { |
882 croak("flush(): called after error"); | |
883 } | |
884 | |
7528
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
885 if (ctx->variable) { |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
886 croak("flush(): cannot be used in variable handler"); |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
887 } |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
888 |
599 | 889 b = ngx_calloc_buf(r->pool); |
890 if (b == NULL) { | |
7526
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
891 ctx->error = 1; |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
892 croak("ngx_calloc_buf() failed"); |
599 | 893 } |
894 | |
895 b->flush = 1; | |
896 | |
1178
a77f6980de50
rename $r->rflush to $r->flush
Igor Sysoev <igor@sysoev.ru>
parents:
1075
diff
changeset
|
897 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "$r->flush"); |
601 | 898 |
7525 | 899 rc = ngx_http_perl_output(r, ctx, b); |
900 | |
901 if (rc == NGX_ERROR) { | |
902 ctx->error = 1; | |
903 croak("ngx_http_perl_output() failed"); | |
904 } | |
599 | 905 |
633 | 906 XSRETURN_EMPTY; |
599 | 907 |
908 | |
909 void | |
910 internal_redirect(r, uri) | |
633 | 911 CODE: |
599 | 912 |
633 | 913 ngx_http_request_t *r; |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
914 ngx_http_perl_ctx_t *ctx; |
633 | 915 SV *uri; |
599 | 916 ngx_uint_t i; |
917 | |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
918 ngx_http_perl_set_request(r, ctx); |
633 | 919 |
7528
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
920 if (ctx->variable) { |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
921 croak("internal_redirect(): cannot be used in variable handler"); |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
922 } |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
923 |
633 | 924 uri = ST(1); |
599 | 925 |
926 if (ngx_http_perl_sv2str(aTHX_ r, &ctx->redirect_uri, uri) != NGX_OK) { | |
7526
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
927 ctx->error = 1; |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
928 croak("ngx_http_perl_sv2str() failed"); |
599 | 929 } |
930 | |
931 for (i = 0; i < ctx->redirect_uri.len; i++) { | |
932 if (ctx->redirect_uri.data[i] == '?') { | |
933 | |
934 ctx->redirect_args.len = ctx->redirect_uri.len - (i + 1); | |
935 ctx->redirect_args.data = &ctx->redirect_uri.data[i + 1]; | |
936 ctx->redirect_uri.len = i; | |
937 | |
938 XSRETURN_EMPTY; | |
939 } | |
940 } | |
601 | 941 |
942 | |
633 | 943 void |
811 | 944 allow_ranges(r) |
945 CODE: | |
946 | |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
947 ngx_http_request_t *r; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
948 ngx_http_perl_ctx_t *ctx; |
811 | 949 |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
950 ngx_http_perl_set_request(r, ctx); |
811 | 951 |
7528
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
952 if (ctx->variable) { |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
953 croak("allow_ranges(): cannot be used in variable handler"); |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
954 } |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
955 |
811 | 956 r->allow_ranges = 1; |
957 | |
958 | |
959 void | |
601 | 960 unescape(r, text, type = 0) |
961 CODE: | |
962 | |
633 | 963 dXSTARG; |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
964 ngx_http_request_t *r; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
965 ngx_http_perl_ctx_t *ctx; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
966 SV *text; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
967 int type; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
968 u_char *p, *dst, *src; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
969 STRLEN len; |
601 | 970 |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
971 ngx_http_perl_set_request(r, ctx); |
633 | 972 |
973 text = ST(1); | |
974 | |
975 src = (u_char *) SvPV(text, len); | |
976 | |
2049 | 977 p = ngx_pnalloc(r->pool, len + 1); |
601 | 978 if (p == NULL) { |
7526
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
979 ctx->error = 1; |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
980 croak("ngx_pnalloc() failed"); |
601 | 981 } |
982 | |
983 dst = p; | |
984 | |
633 | 985 type = items < 3 ? 0 : SvIV(ST(2)); |
986 | |
987 ngx_unescape_uri(&dst, &src, len, (ngx_uint_t) type); | |
601 | 988 *dst = '\0'; |
989 | |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
990 ngx_http_perl_set_targ(p, dst - p); |
601 | 991 |
633 | 992 ST(0) = TARG; |
833 | 993 |
994 | |
995 void | |
996 variable(r, name, value = NULL) | |
997 CODE: | |
998 | |
999 dXSTARG; | |
1000 ngx_http_request_t *r; | |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
1001 ngx_http_perl_ctx_t *ctx; |
833 | 1002 SV *name, *value; |
1003 u_char *p, *lowcase; | |
1004 STRLEN len; | |
1005 ngx_str_t var, val; | |
1006 ngx_uint_t i, hash; | |
912
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1007 ngx_http_perl_var_t *v; |
833 | 1008 ngx_http_variable_value_t *vv; |
1009 | |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
1010 ngx_http_perl_set_request(r, ctx); |
833 | 1011 |
1012 name = ST(1); | |
1013 | |
1014 if (SvROK(name) && SvTYPE(SvRV(name)) == SVt_PV) { | |
1015 name = SvRV(name); | |
1016 } | |
1017 | |
1018 if (items == 2) { | |
1019 value = NULL; | |
1020 | |
1021 } else { | |
1022 value = ST(2); | |
1023 | |
1024 if (SvROK(value) && SvTYPE(SvRV(value)) == SVt_PV) { | |
1025 value = SvRV(value); | |
1026 } | |
1027 | |
1028 if (ngx_http_perl_sv2str(aTHX_ r, &val, value) != NGX_OK) { | |
7526
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
1029 ctx->error = 1; |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
1030 croak("ngx_http_perl_sv2str() failed"); |
833 | 1031 } |
1032 } | |
1033 | |
1034 p = (u_char *) SvPV(name, len); | |
1035 | |
2049 | 1036 lowcase = ngx_pnalloc(r->pool, len); |
833 | 1037 if (lowcase == NULL) { |
7526
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
1038 ctx->error = 1; |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
1039 croak("ngx_pnalloc() failed"); |
833 | 1040 } |
1041 | |
2136 | 1042 hash = ngx_hash_strlow(lowcase, p, len); |
833 | 1043 |
1044 var.len = len; | |
1045 var.data = lowcase; | |
5306
43900b822890
Perl: fixed syntax usage for C preprocessor directives.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5248
diff
changeset
|
1046 #if (NGX_DEBUG) |
912
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1047 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1048 if (value) { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1049 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1050 "perl variable: \"%V\"=\"%V\"", &var, &val); |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1051 } else { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1052 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1053 "perl variable: \"%V\"", &var); |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1054 } |
5306
43900b822890
Perl: fixed syntax usage for C preprocessor directives.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5248
diff
changeset
|
1055 #endif |
912
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1056 |
3500
0eb46e3c5c02
change processing variables accessed by SSI and perl module:
Igor Sysoev <igor@sysoev.ru>
parents:
3447
diff
changeset
|
1057 vv = ngx_http_get_variable(r, &var, hash); |
833 | 1058 if (vv == NULL) { |
7526
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
1059 ctx->error = 1; |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
1060 croak("ngx_http_get_variable() failed"); |
833 | 1061 } |
1062 | |
1063 if (vv->not_found) { | |
912
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1064 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1065 if (ctx->variables) { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1066 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1067 v = ctx->variables->elts; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1068 for (i = 0; i < ctx->variables->nelts; i++) { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1069 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1070 if (hash != v[i].hash |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1071 || len != v[i].name.len |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1072 || ngx_strncmp(lowcase, v[i].name.data, len) != 0) |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1073 { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1074 continue; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1075 } |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1076 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1077 if (value) { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1078 v[i].value = val; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1079 XSRETURN_UNDEF; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1080 } |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1081 |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
1082 ngx_http_perl_set_targ(v[i].value.data, v[i].value.len); |
912
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1083 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1084 goto done; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1085 } |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1086 } |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1087 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1088 if (value) { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1089 if (ctx->variables == NULL) { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1090 ctx->variables = ngx_array_create(r->pool, 1, |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1091 sizeof(ngx_http_perl_var_t)); |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1092 if (ctx->variables == NULL) { |
7526
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
1093 ctx->error = 1; |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
1094 croak("ngx_array_create() failed"); |
912
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1095 } |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1096 } |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1097 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1098 v = ngx_array_push(ctx->variables); |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1099 if (v == NULL) { |
7526
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
1100 ctx->error = 1; |
8125552a10ca
Perl: handling of allocation errors.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7525
diff
changeset
|
1101 croak("ngx_array_push() failed"); |
912
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1102 } |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1103 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1104 v->hash = hash; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1105 v->name.len = len; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1106 v->name.data = lowcase; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1107 v->value = val; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1108 |
833 | 1109 XSRETURN_UNDEF; |
1110 } | |
1111 | |
1112 XSRETURN_UNDEF; | |
1113 } | |
1114 | |
1115 if (value) { | |
1116 vv->len = val.len; | |
1117 vv->valid = 1; | |
1565 | 1118 vv->no_cacheable = 0; |
833 | 1119 vv->not_found = 0; |
1120 vv->data = val.data; | |
1121 | |
1122 XSRETURN_UNDEF; | |
1123 } | |
1124 | |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
1125 ngx_http_perl_set_targ(vv->data, vv->len); |
833 | 1126 |
912
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1127 done: |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
1128 |
833 | 1129 ST(0) = TARG; |
907 | 1130 |
1131 | |
1132 void | |
911 | 1133 sleep(r, sleep, next) |
1134 CODE: | |
1135 | |
1136 ngx_http_request_t *r; | |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
1137 ngx_http_perl_ctx_t *ctx; |
1897 | 1138 ngx_msec_t sleep; |
911 | 1139 |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
1140 ngx_http_perl_set_request(r, ctx); |
911 | 1141 |
7528
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
1142 if (ctx->variable) { |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
1143 croak("sleep(): cannot be used in variable handler"); |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
1144 } |
0cb693b4cbbb
Perl: disabled unrelated calls from variable handlers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7527
diff
changeset
|
1145 |
7527
02cd116ebe2a
Perl: protection against duplicate $r->sleep() calls.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7526
diff
changeset
|
1146 if (ctx->next) { |
02cd116ebe2a
Perl: protection against duplicate $r->sleep() calls.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7526
diff
changeset
|
1147 croak("sleep(): another handler active"); |
02cd116ebe2a
Perl: protection against duplicate $r->sleep() calls.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7526
diff
changeset
|
1148 } |
02cd116ebe2a
Perl: protection against duplicate $r->sleep() calls.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7526
diff
changeset
|
1149 |
1898 | 1150 sleep = (ngx_msec_t) SvIV(ST(1)); |
1897 | 1151 |
1152 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1153 "perl sleep: %M", sleep); | |
1154 | |
911 | 1155 ctx->next = SvRV(ST(2)); |
1156 | |
6960
1c5e5e5b008d
Perl: fixed delaying subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6233
diff
changeset
|
1157 r->connection->write->delayed = 1; |
1897 | 1158 ngx_add_timer(r->connection->write, sleep); |
1159 | |
1160 r->write_event_handler = ngx_http_perl_sleep_handler; | |
3447
de70f912ad58
fix request counter for $r->sleep(), the bug was introduced in r3050
Igor Sysoev <igor@sysoev.ru>
parents:
3317
diff
changeset
|
1161 r->main->count++; |
911 | 1162 |
1163 | |
1164 void | |
907 | 1165 log_error(r, err, msg) |
1166 CODE: | |
1167 | |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
1168 ngx_http_request_t *r; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
1169 ngx_http_perl_ctx_t *ctx; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
1170 SV *err, *msg; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
1171 u_char *p; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
1172 STRLEN len; |
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
1173 ngx_err_t e; |
907 | 1174 |
7524
deebe988cbd7
Perl: reworked perl module to pass ctx instead of request.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7516
diff
changeset
|
1175 ngx_http_perl_set_request(r, ctx); |
907 | 1176 |
1177 err = ST(1); | |
1178 | |
1179 if (SvROK(err) && SvTYPE(SvRV(err)) == SVt_PV) { | |
1180 err = SvRV(err); | |
1181 } | |
1182 | |
1183 e = SvIV(err); | |
1184 | |
1185 msg = ST(2); | |
1186 | |
1187 if (SvROK(msg) && SvTYPE(SvRV(msg)) == SVt_PV) { | |
1188 msg = SvRV(msg); | |
1189 } | |
1190 | |
1191 p = (u_char *) SvPV(msg, len); | |
1192 | |
910 | 1193 ngx_log_error(NGX_LOG_ERR, r->connection->log, e, "perl: %s", p); |