Mercurial > hg > nginx-quic
annotate src/http/modules/perl/nginx.xs @ 4207:4fc91bae6f83
Better recheck of dead upstream servers.
Previously nginx used to mark backend again as live as soon as fail_timeout
passes (10s by default) since last failure. On the other hand, detecting
dead backend takes up to 60s (proxy_connect_timeout) in typical situation
"backend is down and doesn't respond to any packets". This resulted in
suboptimal behaviour in the above situation (up to 23% of requests were
directed to dead backend with default settings).
More detailed description of the problem may be found here (in Russian):
http://mailman.nginx.org/pipermail/nginx-ru/2011-August/042172.html
Fix is to only allow one request after fail_timeout passes, and
mark backend as "live" only if this request succeeds.
Note that with new code backend will not be marked "live" unless "check"
request is completed, and this may take a while in some specific workloads
(e.g. streaming). This is believed to be acceptable.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Wed, 12 Oct 2011 14:22:48 +0000 |
parents | 190ae1a7f917 |
children | d620f497c50f |
rev | line source |
---|---|
599 | 1 |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4 */ | |
5 | |
6 | |
882
26c3e48b9996
the PERL_NO_GET_CONTEXT is actually required, see perlguts
Igor Sysoev <igor@sysoev.ru>
parents:
869
diff
changeset
|
7 #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
|
8 |
599 | 9 #include <ngx_config.h> |
10 #include <ngx_core.h> | |
11 #include <ngx_http.h> | |
12 #include <ngx_http_perl_module.h> | |
13 | |
603 | 14 #include "XSUB.h" |
15 | |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
16 |
633 | 17 #define ngx_http_perl_set_request(r) \ |
18 r = INT2PTR(ngx_http_request_t *, SvIV((SV *) SvRV(ST(0)))) | |
19 | |
20 | |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
21 #define ngx_http_perl_set_targ(p, len) \ |
633 | 22 \ |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
23 SvUPGRADE(TARG, SVt_PV); \ |
633 | 24 SvPOK_on(TARG); \ |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
25 sv_setpvn(TARG, (char *) p, len) |
633 | 26 |
599 | 27 |
28 static ngx_int_t | |
29 ngx_http_perl_sv2str(pTHX_ ngx_http_request_t *r, ngx_str_t *s, SV *sv) | |
30 { | |
31 u_char *p; | |
32 STRLEN len; | |
33 | |
34 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PV) { | |
35 sv = SvRV(sv); | |
36 } | |
37 | |
38 p = (u_char *) SvPV(sv, len); | |
39 | |
40 s->len = len; | |
41 | |
1703
43747661804d
*) copy regex captures $1, $2, etc.
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
42 if (SvREADONLY(sv) && SvPOK(sv)) { |
599 | 43 s->data = p; |
1703
43747661804d
*) copy regex captures $1, $2, etc.
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
44 |
43747661804d
*) copy regex captures $1, $2, etc.
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
45 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
|
46 "perl sv2str: %08XD \"%V\"", sv->sv_flags, s); |
43747661804d
*) copy regex captures $1, $2, etc.
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
47 |
599 | 48 return NGX_OK; |
49 } | |
50 | |
2049 | 51 s->data = ngx_pnalloc(r->pool, len); |
599 | 52 if (s->data == NULL) { |
53 return NGX_ERROR; | |
54 } | |
55 | |
56 ngx_memcpy(s->data, p, len); | |
57 | |
1703
43747661804d
*) copy regex captures $1, $2, etc.
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
58 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
|
59 "perl sv2str: %08XD \"%V\"", sv->sv_flags, s); |
43747661804d
*) copy regex captures $1, $2, etc.
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
60 |
599 | 61 return NGX_OK; |
62 } | |
63 | |
64 | |
65 static ngx_int_t | |
66 ngx_http_perl_output(ngx_http_request_t *r, ngx_buf_t *b) | |
67 { | |
617 | 68 ngx_chain_t out; |
69 #if (NGX_HTTP_SSI) | |
70 ngx_chain_t *cl; | |
599 | 71 ngx_http_perl_ctx_t *ctx; |
72 | |
73 ctx = ngx_http_get_module_ctx(r, ngx_http_perl_module); | |
74 | |
75 if (ctx->ssi) { | |
76 cl = ngx_alloc_chain_link(r->pool); | |
77 if (cl == NULL) { | |
78 return NGX_ERROR; | |
79 } | |
80 | |
81 cl->buf = b; | |
82 cl->next = NULL; | |
83 *ctx->ssi->last_out = cl; | |
84 ctx->ssi->last_out = &cl->next; | |
85 | |
86 return NGX_OK; | |
87 } | |
617 | 88 #endif |
599 | 89 |
90 out.buf = b; | |
91 out.next = NULL; | |
92 | |
93 return ngx_http_output_filter(r, &out); | |
94 } | |
95 | |
96 | |
97 MODULE = nginx PACKAGE = nginx | |
98 | |
99 | |
633 | 100 void |
915 | 101 status(r, code) |
102 CODE: | |
103 | |
104 ngx_http_request_t *r; | |
105 | |
106 ngx_http_perl_set_request(r); | |
107 | |
108 r->headers_out.status = SvIV(ST(1)); | |
109 | |
110 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
111 "perl status: %d", r->headers_out.status); | |
112 | |
113 XSRETURN_UNDEF; | |
114 | |
115 | |
116 void | |
599 | 117 send_http_header(r, ...) |
633 | 118 CODE: |
599 | 119 |
633 | 120 ngx_http_request_t *r; |
121 SV *sv; | |
599 | 122 |
633 | 123 ngx_http_perl_set_request(r); |
599 | 124 |
125 if (r->headers_out.status == 0) { | |
126 r->headers_out.status = NGX_HTTP_OK; | |
127 } | |
128 | |
129 if (items != 1) { | |
130 sv = ST(1); | |
131 | |
132 if (ngx_http_perl_sv2str(aTHX_ r, &r->headers_out.content_type, sv) | |
133 != NGX_OK) | |
134 { | |
633 | 135 XSRETURN_EMPTY; |
599 | 136 } |
137 | |
1444
37938e68910b
allow to append charset to the "Content-Type" header
Igor Sysoev <igor@sysoev.ru>
parents:
1372
diff
changeset
|
138 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
|
139 |
599 | 140 } else { |
673 | 141 if (ngx_http_set_content_type(r) != NGX_OK) { |
142 XSRETURN_EMPTY; | |
599 | 143 } |
144 } | |
145 | |
633 | 146 (void) ngx_http_send_header(r); |
599 | 147 |
148 | |
633 | 149 void |
150 header_only(r) | |
599 | 151 CODE: |
152 | |
633 | 153 dXSTARG; |
154 ngx_http_request_t *r; | |
155 | |
156 ngx_http_perl_set_request(r); | |
599 | 157 |
633 | 158 sv_upgrade(TARG, SVt_IV); |
159 sv_setiv(TARG, r->header_only); | |
599 | 160 |
633 | 161 ST(0) = TARG; |
599 | 162 |
163 | |
633 | 164 void |
165 uri(r) | |
166 CODE: | |
167 | |
168 dXSTARG; | |
169 ngx_http_request_t *r; | |
599 | 170 |
633 | 171 ngx_http_perl_set_request(r); |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
172 ngx_http_perl_set_targ(r->uri.data, r->uri.len); |
633 | 173 |
174 ST(0) = TARG; | |
175 | |
176 | |
177 void | |
178 args(r) | |
599 | 179 CODE: |
180 | |
633 | 181 dXSTARG; |
182 ngx_http_request_t *r; | |
599 | 183 |
633 | 184 ngx_http_perl_set_request(r); |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
185 ngx_http_perl_set_targ(r->args.data, r->args.len); |
599 | 186 |
633 | 187 ST(0) = TARG; |
599 | 188 |
189 | |
633 | 190 void |
629 | 191 request_method(r) |
633 | 192 CODE: |
193 | |
194 dXSTARG; | |
195 ngx_http_request_t *r; | |
629 | 196 |
633 | 197 ngx_http_perl_set_request(r); |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
198 ngx_http_perl_set_targ(r->method_name.data, r->method_name.len); |
633 | 199 |
200 ST(0) = TARG; | |
201 | |
202 | |
203 void | |
204 remote_addr(r) | |
629 | 205 CODE: |
206 | |
633 | 207 dXSTARG; |
208 ngx_http_request_t *r; | |
629 | 209 |
633 | 210 ngx_http_perl_set_request(r); |
211 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
|
212 r->connection->addr_text.len); |
629 | 213 |
633 | 214 ST(0) = TARG; |
629 | 215 |
216 | |
633 | 217 void |
218 header_in(r, key) | |
629 | 219 CODE: |
220 | |
633 | 221 dXSTARG; |
667 | 222 ngx_http_request_t *r; |
223 SV *key; | |
224 u_char *p, *lowcase_key, *cookie; | |
225 STRLEN len; | |
226 ssize_t size; | |
227 ngx_uint_t i, n, hash; | |
228 ngx_list_part_t *part; | |
229 ngx_table_elt_t *h, **ph; | |
230 ngx_http_header_t *hh; | |
231 ngx_http_core_main_conf_t *cmcf; | |
629 | 232 |
633 | 233 ngx_http_perl_set_request(r); |
599 | 234 |
633 | 235 key = ST(1); |
599 | 236 |
237 if (SvROK(key) && SvTYPE(SvRV(key)) == SVt_PV) { | |
238 key = SvRV(key); | |
239 } | |
240 | |
241 p = (u_char *) SvPV(key, len); | |
242 | |
667 | 243 /* look up hashed headers */ |
244 | |
2049 | 245 lowcase_key = ngx_pnalloc(r->pool, len); |
667 | 246 if (lowcase_key == NULL) { |
247 XSRETURN_UNDEF; | |
248 } | |
249 | |
2136 | 250 hash = ngx_hash_strlow(lowcase_key, p, len); |
667 | 251 |
252 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); | |
253 | |
254 hh = ngx_hash_find(&cmcf->headers_in_hash, hash, lowcase_key, len); | |
255 | |
256 if (hh) { | |
257 if (hh->offset) { | |
258 | |
259 ph = (ngx_table_elt_t **) ((char *) &r->headers_in + hh->offset); | |
260 | |
261 if (*ph) { | |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
262 ngx_http_perl_set_targ((*ph)->value.data, (*ph)->value.len); |
667 | 263 |
264 goto done; | |
265 } | |
266 | |
267 XSRETURN_UNDEF; | |
268 } | |
269 | |
270 /* Cookie */ | |
271 | |
272 n = r->headers_in.cookies.nelts; | |
273 | |
274 if (n == 0) { | |
275 XSRETURN_UNDEF; | |
276 } | |
277 | |
278 ph = r->headers_in.cookies.elts; | |
279 | |
280 if (n == 1) { | |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
281 ngx_http_perl_set_targ((*ph)->value.data, (*ph)->value.len); |
667 | 282 |
283 goto done; | |
284 } | |
285 | |
286 size = - (ssize_t) (sizeof("; ") - 1); | |
287 | |
288 for (i = 0; i < n; i++) { | |
289 size += ph[i]->value.len + sizeof("; ") - 1; | |
290 } | |
291 | |
2049 | 292 cookie = ngx_pnalloc(r->pool, size); |
667 | 293 if (cookie == NULL) { |
294 XSRETURN_UNDEF; | |
295 } | |
296 | |
297 p = cookie; | |
298 | |
299 for (i = 0; /* void */ ; i++) { | |
300 p = ngx_copy(p, ph[i]->value.data, ph[i]->value.len); | |
301 | |
302 if (i == n - 1) { | |
303 break; | |
304 } | |
305 | |
306 *p++ = ';'; *p++ = ' '; | |
307 } | |
308 | |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
309 ngx_http_perl_set_targ(cookie, size); |
667 | 310 |
311 goto done; | |
312 } | |
313 | |
314 /* iterate over all headers */ | |
315 | |
599 | 316 part = &r->headers_in.headers.part; |
667 | 317 h = part->elts; |
599 | 318 |
319 for (i = 0; /* void */ ; i++) { | |
320 | |
321 if (i >= part->nelts) { | |
322 if (part->next == NULL) { | |
323 break; | |
324 } | |
325 | |
326 part = part->next; | |
667 | 327 h = part->elts; |
599 | 328 i = 0; |
329 } | |
330 | |
667 | 331 if (len != h[i].key.len |
332 || ngx_strcasecmp(p, h[i].key.data) != 0) | |
599 | 333 { |
334 continue; | |
335 } | |
336 | |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
337 ngx_http_perl_set_targ(h[i].value.data, h[i].value.len); |
599 | 338 |
339 goto done; | |
340 } | |
341 | |
342 XSRETURN_UNDEF; | |
343 | |
344 done: | |
345 | |
633 | 346 ST(0) = TARG; |
599 | 347 |
348 | |
633 | 349 void |
681 | 350 has_request_body(r, next) |
351 CODE: | |
352 | |
353 dXSTARG; | |
354 ngx_http_request_t *r; | |
355 ngx_http_perl_ctx_t *ctx; | |
356 | |
357 ngx_http_perl_set_request(r); | |
358 | |
359 if (r->headers_in.content_length_n <= 0) { | |
360 XSRETURN_UNDEF; | |
361 } | |
362 | |
363 ctx = ngx_http_get_module_ctx(r, ngx_http_perl_module); | |
909 | 364 ctx->next = SvRV(ST(1)); |
681 | 365 |
366 r->request_body_in_single_buf = 1; | |
367 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
|
368 r->request_body_in_clean_file = 1; |
681 | 369 |
370 if (r->request_body_in_file_only) { | |
371 r->request_body_file_log_level = 0; | |
372 } | |
373 | |
374 ngx_http_read_client_request_body(r, ngx_http_perl_handle_request); | |
375 | |
376 sv_upgrade(TARG, SVt_IV); | |
377 sv_setiv(TARG, 1); | |
378 | |
379 ST(0) = TARG; | |
380 | |
381 | |
382 void | |
631 | 383 request_body(r) |
384 CODE: | |
385 | |
633 | 386 dXSTARG; |
387 ngx_http_request_t *r; | |
388 size_t len; | |
389 | |
390 ngx_http_perl_set_request(r); | |
631 | 391 |
941 | 392 if (r->request_body == NULL |
393 || r->request_body->temp_file | |
394 || r->request_body->bufs == NULL) | |
395 { | |
633 | 396 XSRETURN_UNDEF; |
397 } | |
631 | 398 |
633 | 399 len = r->request_body->bufs->buf->last - r->request_body->bufs->buf->pos; |
631 | 400 |
401 if (len == 0) { | |
402 XSRETURN_UNDEF; | |
403 } | |
404 | |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
405 ngx_http_perl_set_targ(r->request_body->bufs->buf->pos, len); |
631 | 406 |
633 | 407 ST(0) = TARG; |
631 | 408 |
409 | |
633 | 410 void |
411 request_body_file(r) | |
412 CODE: | |
413 | |
414 dXSTARG; | |
415 ngx_http_request_t *r; | |
416 | |
417 ngx_http_perl_set_request(r); | |
418 | |
941 | 419 if (r->request_body == NULL || r->request_body->temp_file == NULL) { |
633 | 420 XSRETURN_UNDEF; |
421 } | |
422 | |
423 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
|
424 r->request_body->temp_file->file.name.len); |
599 | 425 |
633 | 426 ST(0) = TARG; |
427 | |
428 | |
429 void | |
1371 | 430 discard_request_body(r) |
431 CODE: | |
432 | |
433 ngx_http_request_t *r; | |
434 | |
435 ngx_http_perl_set_request(r); | |
436 | |
437 ngx_http_discard_request_body(r); | |
438 | |
439 | |
440 void | |
633 | 441 header_out(r, key, value) |
442 CODE: | |
599 | 443 |
633 | 444 ngx_http_request_t *r; |
445 SV *key; | |
446 SV *value; | |
447 ngx_table_elt_t *header; | |
599 | 448 |
633 | 449 ngx_http_perl_set_request(r); |
450 | |
451 key = ST(1); | |
452 value = ST(2); | |
599 | 453 |
454 header = ngx_list_push(&r->headers_out.headers); | |
455 if (header == NULL) { | |
633 | 456 XSRETURN_EMPTY; |
599 | 457 } |
458 | |
459 header->hash = 1; | |
460 | |
461 if (ngx_http_perl_sv2str(aTHX_ r, &header->key, key) != NGX_OK) { | |
633 | 462 XSRETURN_EMPTY; |
599 | 463 } |
464 | |
465 if (ngx_http_perl_sv2str(aTHX_ r, &header->value, value) != NGX_OK) { | |
633 | 466 XSRETURN_EMPTY; |
599 | 467 } |
468 | |
469 if (header->key.len == sizeof("Content-Length") - 1 | |
3870 | 470 && 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
|
471 sizeof("Content-Length") - 1) == 0) |
599 | 472 { |
741
63a08390a8a2
$r->headers_out("Content-Length", "NNN") did not work
Igor Sysoev <igor@sysoev.ru>
parents:
681
diff
changeset
|
473 r->headers_out.content_length_n = (off_t) SvIV(value); |
599 | 474 r->headers_out.content_length = header; |
475 } | |
476 | |
4196
190ae1a7f917
Handling of Content-Encoding set from perl.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4188
diff
changeset
|
477 if (header->key.len == sizeof("Content-Encoding") - 1 |
190ae1a7f917
Handling of Content-Encoding set from perl.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4188
diff
changeset
|
478 && ngx_strncasecmp(header->key.data, "Content-Encoding", |
190ae1a7f917
Handling of Content-Encoding set from perl.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4188
diff
changeset
|
479 sizeof("Content-Encoding") - 1) == 0) |
190ae1a7f917
Handling of Content-Encoding set from perl.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4188
diff
changeset
|
480 { |
190ae1a7f917
Handling of Content-Encoding set from perl.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4188
diff
changeset
|
481 r->headers_out.content_encoding = header; |
190ae1a7f917
Handling of Content-Encoding set from perl.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4188
diff
changeset
|
482 } |
190ae1a7f917
Handling of Content-Encoding set from perl.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4188
diff
changeset
|
483 |
599 | 484 |
633 | 485 void |
599 | 486 filename(r) |
633 | 487 CODE: |
599 | 488 |
633 | 489 dXSTARG; |
774
589841f06b87
previous commit broke two modules
Igor Sysoev <igor@sysoev.ru>
parents:
741
diff
changeset
|
490 size_t root; |
633 | 491 ngx_http_request_t *r; |
599 | 492 ngx_http_perl_ctx_t *ctx; |
493 | |
633 | 494 ngx_http_perl_set_request(r); |
599 | 495 |
496 ctx = ngx_http_get_module_ctx(r, ngx_http_perl_module); | |
633 | 497 if (ctx->filename.data) { |
599 | 498 goto done; |
499 } | |
500 | |
774
589841f06b87
previous commit broke two modules
Igor Sysoev <igor@sysoev.ru>
parents:
741
diff
changeset
|
501 if (ngx_http_map_uri_to_path(r, &ctx->filename, &root, 0) == NULL) { |
599 | 502 XSRETURN_UNDEF; |
503 } | |
504 | |
633 | 505 ctx->filename.len--; |
506 sv_setpv(PL_statname, (char *) ctx->filename.data); | |
599 | 507 |
508 done: | |
509 | |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
510 ngx_http_perl_set_targ(ctx->filename.data, ctx->filename.len); |
599 | 511 |
633 | 512 ST(0) = TARG; |
599 | 513 |
514 | |
633 | 515 void |
599 | 516 print(r, ...) |
517 CODE: | |
518 | |
633 | 519 ngx_http_request_t *r; |
520 SV *sv; | |
521 int i; | |
522 u_char *p; | |
523 size_t size; | |
524 STRLEN len; | |
525 ngx_buf_t *b; | |
526 | |
527 ngx_http_perl_set_request(r); | |
599 | 528 |
529 if (items == 2) { | |
530 | |
531 /* | |
532 * do zero copy for prolate single read-only SV: | |
533 * $r->print("some text\n"); | |
534 */ | |
535 | |
536 sv = ST(1); | |
537 | |
538 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PV) { | |
539 sv = SvRV(sv); | |
540 } | |
541 | |
1703
43747661804d
*) copy regex captures $1, $2, etc.
Igor Sysoev <igor@sysoev.ru>
parents:
1565
diff
changeset
|
542 if (SvREADONLY(sv) && SvPOK(sv)) { |
599 | 543 |
544 p = (u_char *) SvPV(sv, len); | |
545 | |
546 if (len == 0) { | |
633 | 547 XSRETURN_EMPTY; |
599 | 548 } |
549 | |
550 b = ngx_calloc_buf(r->pool); | |
551 if (b == NULL) { | |
633 | 552 XSRETURN_EMPTY; |
599 | 553 } |
554 | |
555 b->memory = 1; | |
556 b->pos = p; | |
557 b->last = p + len; | |
558 b->start = p; | |
559 b->end = b->last; | |
560 | |
601 | 561 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
562 "$r->print: read-only SV: %z", len); | |
563 | |
599 | 564 goto out; |
565 } | |
566 } | |
567 | |
568 size = 0; | |
569 | |
570 for (i = 1; i < items; i++) { | |
571 | |
572 sv = ST(i); | |
573 | |
574 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PV) { | |
575 sv = SvRV(sv); | |
576 } | |
577 | |
601 | 578 (void) SvPV(sv, len); |
599 | 579 |
601 | 580 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
581 "$r->print: copy SV: %z", len); | |
599 | 582 |
583 size += len; | |
584 } | |
585 | |
586 if (size == 0) { | |
633 | 587 XSRETURN_EMPTY; |
599 | 588 } |
589 | |
590 b = ngx_create_temp_buf(r->pool, size); | |
591 if (b == NULL) { | |
633 | 592 XSRETURN_EMPTY; |
599 | 593 } |
594 | |
595 for (i = 1; i < items; i++) { | |
596 sv = ST(i); | |
597 | |
598 if (SvROK(sv) && SvTYPE(SvRV(sv)) == SVt_PV) { | |
599 sv = SvRV(sv); | |
600 } | |
601 | |
602 p = (u_char *) SvPV(sv, len); | |
603 b->last = ngx_cpymem(b->last, p, len); | |
604 } | |
605 | |
606 out: | |
607 | |
633 | 608 (void) ngx_http_perl_output(r, b); |
599 | 609 |
610 | |
633 | 611 void |
613 | 612 sendfile(r, filename, offset = -1, bytes = 0) |
633 | 613 CODE: |
614 | |
1454 | 615 ngx_http_request_t *r; |
616 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
|
617 off_t offset; |
1454 | 618 size_t bytes; |
619 ngx_str_t path; | |
620 ngx_buf_t *b; | |
621 ngx_open_file_info_t of; | |
622 ngx_http_core_loc_conf_t *clcf; | |
599 | 623 |
633 | 624 ngx_http_perl_set_request(r); |
625 | |
626 filename = SvPV_nolen(ST(1)); | |
599 | 627 |
628 if (filename == NULL) { | |
629 croak("sendfile(): NULL filename"); | |
630 } | |
631 | |
633 | 632 offset = items < 3 ? -1 : SvIV(ST(2)); |
633 bytes = items < 4 ? 0 : SvIV(ST(3)); | |
634 | |
599 | 635 b = ngx_calloc_buf(r->pool); |
636 if (b == NULL) { | |
633 | 637 XSRETURN_EMPTY; |
599 | 638 } |
639 | |
640 b->file = ngx_pcalloc(r->pool, sizeof(ngx_file_t)); | |
641 if (b->file == NULL) { | |
633 | 642 XSRETURN_EMPTY; |
599 | 643 } |
644 | |
1454 | 645 path.len = ngx_strlen(filename); |
646 | |
2061
b0a1c84725cf
change useless ngx_pcalloc() to ngx_pnalloc()
Igor Sysoev <igor@sysoev.ru>
parents:
2049
diff
changeset
|
647 path.data = ngx_pnalloc(r->pool, path.len + 1); |
1454 | 648 if (path.data == NULL) { |
633 | 649 XSRETURN_EMPTY; |
599 | 650 } |
651 | |
3870 | 652 (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
|
653 |
2063
67a29af877ed
initialize of.uniq in ngx_open_cached_file()
Igor Sysoev <igor@sysoev.ru>
parents:
2061
diff
changeset
|
654 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
|
655 |
2068
75a8d34459c5
ngx_memzero() ngx_open_file_info_t
Igor Sysoev <igor@sysoev.ru>
parents:
2063
diff
changeset
|
656 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
|
657 |
3178 | 658 of.read_ahead = clcf->read_ahead; |
2129 | 659 of.directio = clcf->directio; |
2063
67a29af877ed
initialize of.uniq in ngx_open_cached_file()
Igor Sysoev <igor@sysoev.ru>
parents:
2061
diff
changeset
|
660 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
|
661 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
|
662 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
|
663 of.events = clcf->open_file_cache_events; |
67a29af877ed
initialize of.uniq in ngx_open_cached_file()
Igor Sysoev <igor@sysoev.ru>
parents:
2061
diff
changeset
|
664 |
1799 | 665 if (ngx_open_cached_file(clcf->open_file_cache, &path, &of, r->pool) |
666 != NGX_OK) | |
667 { | |
1454 | 668 if (of.err == 0) { |
669 XSRETURN_EMPTY; | |
670 } | |
671 | |
599 | 672 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
|
673 "%s \"%s\" failed", of.failed, filename); |
633 | 674 XSRETURN_EMPTY; |
599 | 675 } |
676 | |
613 | 677 if (offset == -1) { |
678 offset = 0; | |
679 } | |
680 | |
681 if (bytes == 0) { | |
1454 | 682 bytes = of.size - offset; |
599 | 683 } |
684 | |
685 b->in_file = 1; | |
613 | 686 |
687 b->file_pos = offset; | |
688 b->file_last = offset + bytes; | |
599 | 689 |
1454 | 690 b->file->fd = of.fd; |
599 | 691 b->file->log = r->connection->log; |
2231
8564129d49b6
*) handle unaligned file part for directio
Igor Sysoev <igor@sysoev.ru>
parents:
2136
diff
changeset
|
692 b->file->directio = of.is_directio; |
599 | 693 |
633 | 694 (void) ngx_http_perl_output(r, b); |
599 | 695 |
696 | |
633 | 697 void |
1178
a77f6980de50
rename $r->rflush to $r->flush
Igor Sysoev <igor@sysoev.ru>
parents:
1075
diff
changeset
|
698 flush(r) |
633 | 699 CODE: |
599 | 700 |
633 | 701 ngx_http_request_t *r; |
702 ngx_buf_t *b; | |
599 | 703 |
633 | 704 ngx_http_perl_set_request(r); |
599 | 705 |
706 b = ngx_calloc_buf(r->pool); | |
707 if (b == NULL) { | |
633 | 708 XSRETURN_EMPTY; |
599 | 709 } |
710 | |
711 b->flush = 1; | |
712 | |
1178
a77f6980de50
rename $r->rflush to $r->flush
Igor Sysoev <igor@sysoev.ru>
parents:
1075
diff
changeset
|
713 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "$r->flush"); |
601 | 714 |
633 | 715 (void) ngx_http_perl_output(r, b); |
599 | 716 |
633 | 717 XSRETURN_EMPTY; |
599 | 718 |
719 | |
720 void | |
721 internal_redirect(r, uri) | |
633 | 722 CODE: |
599 | 723 |
633 | 724 ngx_http_request_t *r; |
725 SV *uri; | |
599 | 726 ngx_uint_t i; |
727 ngx_http_perl_ctx_t *ctx; | |
728 | |
633 | 729 ngx_http_perl_set_request(r); |
730 | |
731 uri = ST(1); | |
599 | 732 |
733 ctx = ngx_http_get_module_ctx(r, ngx_http_perl_module); | |
734 | |
735 if (ngx_http_perl_sv2str(aTHX_ r, &ctx->redirect_uri, uri) != NGX_OK) { | |
736 XSRETURN_EMPTY; | |
737 } | |
738 | |
739 for (i = 0; i < ctx->redirect_uri.len; i++) { | |
740 if (ctx->redirect_uri.data[i] == '?') { | |
741 | |
742 ctx->redirect_args.len = ctx->redirect_uri.len - (i + 1); | |
743 ctx->redirect_args.data = &ctx->redirect_uri.data[i + 1]; | |
744 ctx->redirect_uri.len = i; | |
745 | |
746 XSRETURN_EMPTY; | |
747 } | |
748 } | |
601 | 749 |
750 | |
633 | 751 void |
811 | 752 allow_ranges(r) |
753 CODE: | |
754 | |
755 ngx_http_request_t *r; | |
756 | |
757 ngx_http_perl_set_request(r); | |
758 | |
759 r->allow_ranges = 1; | |
760 | |
761 | |
762 void | |
601 | 763 unescape(r, text, type = 0) |
764 CODE: | |
765 | |
633 | 766 dXSTARG; |
767 ngx_http_request_t *r; | |
768 SV *text; | |
769 int type; | |
770 u_char *p, *dst, *src; | |
771 STRLEN len; | |
601 | 772 |
633 | 773 ngx_http_perl_set_request(r); |
774 | |
775 text = ST(1); | |
776 | |
777 src = (u_char *) SvPV(text, len); | |
778 | |
2049 | 779 p = ngx_pnalloc(r->pool, len + 1); |
601 | 780 if (p == NULL) { |
781 XSRETURN_UNDEF; | |
782 } | |
783 | |
784 dst = p; | |
785 | |
633 | 786 type = items < 3 ? 0 : SvIV(ST(2)); |
787 | |
788 ngx_unescape_uri(&dst, &src, len, (ngx_uint_t) type); | |
601 | 789 *dst = '\0'; |
790 | |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
791 ngx_http_perl_set_targ(p, dst - p); |
601 | 792 |
633 | 793 ST(0) = TARG; |
833 | 794 |
795 | |
796 void | |
797 variable(r, name, value = NULL) | |
798 CODE: | |
799 | |
800 dXSTARG; | |
801 ngx_http_request_t *r; | |
802 SV *name, *value; | |
803 u_char *p, *lowcase; | |
804 STRLEN len; | |
805 ngx_str_t var, val; | |
806 ngx_uint_t i, hash; | |
912
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
807 ngx_http_perl_var_t *v; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
808 ngx_http_perl_ctx_t *ctx; |
833 | 809 ngx_http_variable_value_t *vv; |
810 | |
811 ngx_http_perl_set_request(r); | |
812 | |
813 name = ST(1); | |
814 | |
815 if (SvROK(name) && SvTYPE(SvRV(name)) == SVt_PV) { | |
816 name = SvRV(name); | |
817 } | |
818 | |
819 if (items == 2) { | |
820 value = NULL; | |
821 | |
822 } else { | |
823 value = ST(2); | |
824 | |
825 if (SvROK(value) && SvTYPE(SvRV(value)) == SVt_PV) { | |
826 value = SvRV(value); | |
827 } | |
828 | |
829 if (ngx_http_perl_sv2str(aTHX_ r, &val, value) != NGX_OK) { | |
830 XSRETURN_UNDEF; | |
831 } | |
832 } | |
833 | |
834 p = (u_char *) SvPV(name, len); | |
835 | |
2049 | 836 lowcase = ngx_pnalloc(r->pool, len); |
833 | 837 if (lowcase == NULL) { |
838 XSRETURN_UNDEF; | |
839 } | |
840 | |
2136 | 841 hash = ngx_hash_strlow(lowcase, p, len); |
833 | 842 |
843 var.len = len; | |
844 var.data = lowcase; | |
845 | |
4188 | 846 #if (NGX_DEBUG) |
912
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
847 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
848 if (value) { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
849 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
|
850 "perl variable: \"%V\"=\"%V\"", &var, &val); |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
851 } else { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
852 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
|
853 "perl variable: \"%V\"", &var); |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
854 } |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
855 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
856 #endif |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
857 |
3500
0eb46e3c5c02
change processing variables accessed by SSI and perl module:
Igor Sysoev <igor@sysoev.ru>
parents:
3447
diff
changeset
|
858 vv = ngx_http_get_variable(r, &var, hash); |
833 | 859 if (vv == NULL) { |
860 XSRETURN_UNDEF; | |
861 } | |
862 | |
863 if (vv->not_found) { | |
912
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
864 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
865 ctx = ngx_http_get_module_ctx(r, ngx_http_perl_module); |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
866 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
867 if (ctx->variables) { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
868 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
869 v = ctx->variables->elts; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
870 for (i = 0; i < ctx->variables->nelts; i++) { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
871 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
872 if (hash != v[i].hash |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
873 || len != v[i].name.len |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
874 || 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
|
875 { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
876 continue; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
877 } |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
878 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
879 if (value) { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
880 v[i].value = val; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
881 XSRETURN_UNDEF; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
882 } |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
883 |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
884 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
|
885 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
886 goto done; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
887 } |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
888 } |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
889 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
890 if (value) { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
891 if (ctx->variables == NULL) { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
892 ctx->variables = ngx_array_create(r->pool, 1, |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
893 sizeof(ngx_http_perl_var_t)); |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
894 if (ctx->variables == NULL) { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
895 XSRETURN_UNDEF; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
896 } |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
897 } |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
898 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
899 v = ngx_array_push(ctx->variables); |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
900 if (v == NULL) { |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
901 XSRETURN_UNDEF; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
902 } |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
903 |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
904 v->hash = hash; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
905 v->name.len = len; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
906 v->name.data = lowcase; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
907 v->value = val; |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
908 |
833 | 909 XSRETURN_UNDEF; |
910 } | |
911 | |
912 XSRETURN_UNDEF; | |
913 } | |
914 | |
915 if (value) { | |
916 vv->len = val.len; | |
917 vv->valid = 1; | |
1565 | 918 vv->no_cacheable = 0; |
833 | 919 vv->not_found = 0; |
920 vv->data = val.data; | |
921 | |
922 XSRETURN_UNDEF; | |
923 } | |
924 | |
1739
5b7baef2e11e
copy return values to perl's allocated memory
Igor Sysoev <igor@sysoev.ru>
parents:
1703
diff
changeset
|
925 ngx_http_perl_set_targ(vv->data, vv->len); |
833 | 926 |
912
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
927 done: |
7fa926a7926d
$r->variable() supports perl only variables
Igor Sysoev <igor@sysoev.ru>
parents:
911
diff
changeset
|
928 |
833 | 929 ST(0) = TARG; |
907 | 930 |
931 | |
932 void | |
911 | 933 sleep(r, sleep, next) |
934 CODE: | |
935 | |
936 ngx_http_request_t *r; | |
1897 | 937 ngx_msec_t sleep; |
911 | 938 ngx_http_perl_ctx_t *ctx; |
939 | |
940 ngx_http_perl_set_request(r); | |
941 | |
1898 | 942 sleep = (ngx_msec_t) SvIV(ST(1)); |
1897 | 943 |
944 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
945 "perl sleep: %M", sleep); | |
946 | |
911 | 947 ctx = ngx_http_get_module_ctx(r, ngx_http_perl_module); |
948 | |
949 ctx->next = SvRV(ST(2)); | |
950 | |
1897 | 951 ngx_add_timer(r->connection->write, sleep); |
952 | |
953 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
|
954 r->main->count++; |
911 | 955 |
956 | |
957 void | |
907 | 958 log_error(r, err, msg) |
959 CODE: | |
960 | |
961 ngx_http_request_t *r; | |
962 SV *err, *msg; | |
963 u_char *p; | |
964 STRLEN len; | |
965 ngx_err_t e; | |
966 | |
967 ngx_http_perl_set_request(r); | |
968 | |
969 err = ST(1); | |
970 | |
971 if (SvROK(err) && SvTYPE(SvRV(err)) == SVt_PV) { | |
972 err = SvRV(err); | |
973 } | |
974 | |
975 e = SvIV(err); | |
976 | |
977 msg = ST(2); | |
978 | |
979 if (SvROK(msg) && SvTYPE(SvRV(msg)) == SVt_PV) { | |
980 msg = SvRV(msg); | |
981 } | |
982 | |
983 p = (u_char *) SvPV(msg, len); | |
984 | |
910 | 985 ngx_log_error(NGX_LOG_ERR, r->connection->log, e, "perl: %s", p); |