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