Mercurial > hg > nginx-site
annotate xml/en/docs/http/ngx_http_perl_module.xml @ 580:be54c443235a
Added copyright markers to documentation sources.
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Tue, 10 Jul 2012 12:59:42 +0000 |
parents | c9c0550465c9 |
children | 764fbac1b8b4 |
rev | line source |
---|---|
416
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
1 <?xml version="1.0"?> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
2 |
580
be54c443235a
Added copyright markers to documentation sources.
Ruslan Ermilov <ru@nginx.com>
parents:
416
diff
changeset
|
3 <!-- |
be54c443235a
Added copyright markers to documentation sources.
Ruslan Ermilov <ru@nginx.com>
parents:
416
diff
changeset
|
4 Copyright (C) Igor Sysoev |
be54c443235a
Added copyright markers to documentation sources.
Ruslan Ermilov <ru@nginx.com>
parents:
416
diff
changeset
|
5 Copyright (C) Nginx, Inc. |
be54c443235a
Added copyright markers to documentation sources.
Ruslan Ermilov <ru@nginx.com>
parents:
416
diff
changeset
|
6 --> |
be54c443235a
Added copyright markers to documentation sources.
Ruslan Ermilov <ru@nginx.com>
parents:
416
diff
changeset
|
7 |
416
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
8 <!DOCTYPE module SYSTEM "../../../../dtd/module.dtd"> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
9 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
10 <module name="Module ngx_http_perl_module" |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
11 link="/en/docs/http/ngx_http_perl_module.html" |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
12 lang="en"> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
13 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
14 <section id="summary"> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
15 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
16 <para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
17 The <literal>ngx_http_perl_module</literal> module allows to implement |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
18 location and variable handlers in Perl, and to insert Perl calls into SSI. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
19 </para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
20 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
21 <para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
22 This module is not built by default, it should be enabled with the |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
23 <literal>--with-http_perl_module</literal> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
24 configuration parameter. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
25 <note> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
26 This module requires Perl version 5.6.1 or higher. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
27 The C compiler should be compatible with that used to build Perl. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
28 </note> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
29 </para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
30 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
31 </section> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
32 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
33 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
34 <section id="bugs" name="Known Bugs"> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
35 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
36 <para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
37 The module is experimental, caveat emptor applies. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
38 </para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
39 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
40 <para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
41 In order for Perl to recompile the modified modules during |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
42 reconfiguration, it needs to be built with the parameters |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
43 <literal>-Dusemultiplicity=yes</literal> or |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
44 <literal>-Dusethreads=yes</literal>. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
45 Also, in order for Perl to leak less memory at run time, |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
46 it needs to be built with the |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
47 <literal>-Dusemymalloc=no</literal> parameter. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
48 To check the values of these parameters in an already built |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
49 Perl (preferred values are specified in the example), run: |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
50 <example> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
51 $ perl -V:usemultiplicity -V:usemymalloc |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
52 usemultiplicity='define'; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
53 usemymalloc='n'; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
54 </example> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
55 </para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
56 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
57 <para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
58 Note that after rebuilding Perl with the new parameters |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
59 <literal>-Dusemultiplicity=yes</literal> or |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
60 <literal>-Dusethreads=yes</literal>, |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
61 all binary Perl modules will have to be rebuilt as well — |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
62 they will just stop working with the new Perl. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
63 </para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
64 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
65 <para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
66 It is possible for the main process and then worker processes |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
67 to grow in size after every reconfiguration. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
68 If the main process grows to an unacceptable size, the |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
69 <link doc="../control.xml" id="upgrade">live upgrade</link> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
70 procedure can be applied without changing an executable file. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
71 </para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
72 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
73 <para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
74 While a Perl module performs long term operation, for example, resolves |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
75 a domain name, connects to another server, queries a database, |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
76 other requests assigned to this worker process will not be processed. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
77 It is thus recommended to limit the work done to operations |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
78 that have predictable and short execution time, for example, |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
79 access local file system. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
80 </para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
81 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
82 <para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
83 The below mentioned issues only affect versions of nginx before 0.6.22. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
84 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
85 <note> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
86 Data returned by the <literal>$r</literal> request object methods |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
87 only has a text value, and the value itself is stored in memory |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
88 allocated by nginx from its own pools, not by Perl. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
89 This allows to reduce the number of copy operations involved in |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
90 most cases, however it can lead to errors in some cases. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
91 For example, a worker process trying to use such a data in the |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
92 numeric context will terminate with an error (FreeBSD): |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
93 <example> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
94 nginx in realloc(): warning: pointer to wrong page |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
95 Out of memory! |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
96 Callback called exit. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
97 </example> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
98 or (Linux): |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
99 <example> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
100 *** glibc detected *** realloc(): invalid pointer: ... *** |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
101 Out of memory! |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
102 Callback called exit. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
103 </example> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
104 The workaround is simple — a method’s value should be assigned |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
105 to a variable. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
106 For example, the following code |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
107 <example> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
108 my $i = $r->variable('counter') + 1; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
109 </example> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
110 should be replaced by |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
111 <example> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
112 my $i = $r->variable('counter'); |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
113 $i++; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
114 </example> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
115 </note> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
116 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
117 <note> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
118 Since most strings inside nginx are stored without a terminating null |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
119 character, they are similarly returned by the <literal>$r</literal> request |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
120 object methods (except for the <literal>$r->filename</literal> and |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
121 <literal>$r->request_body_file</literal> methods). |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
122 Thus, such values cannot be used as filenames and the likes. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
123 The workaround is similar to a previous case — the value should either be |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
124 assigned to a variable (this results in data copying that in turn adds |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
125 the necessary null character) or used in an expression, for example: |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
126 <example> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
127 open FILE, '/path/' . $r->variable('name'); |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
128 </example> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
129 </note> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
130 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
131 </para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
132 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
133 </section> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
134 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
135 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
136 <section id="example" name="Example Configuration"> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
137 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
138 <para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
139 <example> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
140 http { |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
141 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
142 perl_modules perl/lib; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
143 perl_require hello.pm; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
144 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
145 perl_set $msie6 ' |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
146 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
147 sub { |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
148 my $r = shift; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
149 my $ua = $r->header_in("User-Agent"); |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
150 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
151 return "" if $ua =~ /Opera/; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
152 return "1" if $ua =~ / MSIE [6-9]\.\d+/; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
153 return ""; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
154 } |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
155 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
156 '; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
157 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
158 server { |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
159 location / { |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
160 perl hello::handler; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
161 } |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
162 } |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
163 </example> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
164 </para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
165 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
166 <para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
167 The <path>perl/lib/hello.pm</path> module: |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
168 <example> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
169 package hello; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
170 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
171 use nginx; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
172 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
173 sub handler { |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
174 my $r = shift; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
175 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
176 $r->send_http_header("text/html"); |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
177 return OK if $r->header_only; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
178 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
179 $r->print("hello!\n<br/>"); |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
180 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
181 if (-f $r->filename or -d _) { |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
182 $r->print($r->uri, " exists!\n"); |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
183 } |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
184 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
185 return OK; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
186 } |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
187 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
188 1; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
189 __END__ |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
190 </example> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
191 </para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
192 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
193 </section> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
194 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
195 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
196 <section id="directives" name="Directives"> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
197 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
198 <directive name="perl"> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
199 <syntax><value>module</value>::<value>function</value>|'sub { ... }'</syntax> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
200 <default/> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
201 <context>location</context> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
202 <context>limit_except</context> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
203 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
204 <para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
205 Installs a Perl handler for the given location. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
206 </para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
207 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
208 </directive> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
209 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
210 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
211 <directive name="perl_modules"> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
212 <syntax><value>path</value></syntax> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
213 <default/> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
214 <context>http</context> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
215 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
216 <para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
217 Sets an additional path for Perl modules. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
218 </para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
219 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
220 </directive> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
221 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
222 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
223 <directive name="perl_require"> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
224 <syntax><value>module</value></syntax> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
225 <default/> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
226 <context>http</context> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
227 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
228 <para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
229 Defines the name of a module that will be loaded during each |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
230 reconfiguration. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
231 There could be several <literal>perl_require</literal> directives. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
232 </para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
233 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
234 </directive> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
235 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
236 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
237 <directive name="perl_set"> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
238 <syntax> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
239 <value>$variable</value> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
240 <value>module</value>::<value>function</value>|'sub { ... }'</syntax> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
241 <default/> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
242 <context>http</context> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
243 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
244 <para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
245 Installs a Perl handler for the specified variable. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
246 </para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
247 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
248 </directive> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
249 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
250 </section> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
251 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
252 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
253 <section id="ssi" name="Calling Perl from SSI"> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
254 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
255 <para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
256 An SSI command calling Perl has the following format: |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
257 <example> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
258 <!--# perl sub="<value>module</value>::<value>function</value>" arg="<value>parameter1</value>" arg="<value>parameter2</value>" ... |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
259 --> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
260 </example> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
261 </para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
262 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
263 </section> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
264 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
265 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
266 <section id="methods" name="The $r Request Object Methods"> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
267 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
268 <para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
269 <list type="tag"> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
270 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
271 <tag-name><literal>$r->args</literal></tag-name> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
272 <tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
273 returns request arguments. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
274 </tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
275 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
276 <tag-name><literal>$r->filename</literal></tag-name> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
277 <tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
278 returns a filename corresponding to the request URI. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
279 </tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
280 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
281 <tag-name> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
282 <literal>$r->has_request_body(<value>handler</value>)</literal> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
283 </tag-name> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
284 <tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
285 returns 0 if there is no body in a request. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
286 If there is a body, the specified handler is installed |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
287 and 1 is returned. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
288 After reading the request body, nginx will call the installed handler. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
289 Note that the handler function should be passed by reference. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
290 Example: |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
291 <example> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
292 package hello; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
293 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
294 use nginx; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
295 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
296 sub handler { |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
297 my $r = shift; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
298 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
299 if ($r->request_method ne "POST") { |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
300 return DECLINED; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
301 } |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
302 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
303 if ($r->has_request_body(<emphasis>\&post</emphasis>)) { |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
304 return OK; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
305 } |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
306 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
307 return HTTP_BAD_REQUEST; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
308 } |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
309 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
310 sub <emphasis>post</emphasis> { |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
311 my $r = shift; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
312 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
313 $r->send_http_header; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
314 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
315 $r->print("request_body: \"", $r->request_body, "\"<br/>"); |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
316 $r->print("request_body_file: \"", $r->request_body_file, "\"<br/>\n"); |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
317 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
318 return OK; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
319 } |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
320 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
321 1; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
322 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
323 __END__ |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
324 </example> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
325 </tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
326 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
327 <tag-name><literal>$r->allow_ranges</literal></tag-name> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
328 <tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
329 enables the use of byte ranges when sending responses. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
330 </tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
331 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
332 <tag-name><literal>$r->discard_request_body</literal></tag-name> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
333 <tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
334 instructs nginx to discard a request body. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
335 </tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
336 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
337 <tag-name><literal>$r->header_in(<value>field</value>)</literal></tag-name> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
338 <tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
339 returns value of the specified client request header field. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
340 </tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
341 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
342 <tag-name><literal>$r->header_only</literal></tag-name> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
343 <tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
344 determines should the whole response or only its header be sent to a client. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
345 </tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
346 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
347 <tag-name> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
348 <literal>$r->header_out(<value>field</value>, |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
349 <value>value</value>)</literal> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
350 </tag-name> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
351 <tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
352 sets a value for the specified response header field. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
353 </tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
354 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
355 <tag-name> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
356 <literal>$r->internal_redirect(<value>uri</value>)</literal> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
357 </tag-name> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
358 <tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
359 does an internal redirect to the speicified <value>uri</value>. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
360 An actual redirect happens after the Perl handler has completed. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
361 </tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
362 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
363 <tag-name><literal>$r->print(<value>text</value>, ...)</literal></tag-name> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
364 <tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
365 passes data to a client. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
366 </tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
367 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
368 <tag-name><literal>$r->request_body</literal></tag-name> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
369 <tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
370 returns a client request body if it was not |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
371 written to a temporary file. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
372 To ensure that a client request body is in memory, |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
373 its size should be limited with |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
374 <link doc="ngx_http_core_module.xml" id="client_max_body_size"/>, |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
375 and a sufficient buffer size should be set with |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
376 <link doc="ngx_http_core_module.xml" id="client_body_buffer_size"/>. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
377 </tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
378 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
379 <tag-name><literal>$r->request_body_file</literal></tag-name> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
380 <tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
381 returns the name of a file with the client request body. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
382 At the end of processing, the file needs to be removed. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
383 To always write a request body to a file, |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
384 <link doc="ngx_http_core_module.xml" id="client_body_in_file_only"/> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
385 needs to be enabled. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
386 </tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
387 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
388 <tag-name><literal>$r->request_method</literal></tag-name> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
389 <tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
390 returns client request HTTP method. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
391 </tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
392 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
393 <tag-name><literal>$r->remote_addr</literal></tag-name> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
394 <tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
395 returns client IP address. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
396 </tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
397 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
398 <tag-name><literal>$r->flush</literal></tag-name> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
399 <tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
400 immediately sends data to a client. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
401 </tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
402 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
403 <tag-name> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
404 <literal>$r->sendfile(<value>name</value>[, |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
405 <value>offset</value>[, |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
406 <value>length</value>]])</literal> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
407 </tag-name> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
408 <tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
409 sends the specified file content to a client. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
410 Optional parameters |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
411 specify an initial offset and length of data to be transmitted. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
412 The actual data transmission happens after the Perl handler |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
413 has completed. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
414 It should be noted that when using this method in a subrequest, |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
415 and <link doc="ngx_http_core_module.xml" id="sendfile"/> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
416 is enabled, the file content will not be passed through the |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
417 <link doc="ngx_http_gzip_module.xml">gzip</link>, |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
418 <link doc="ngx_http_ssi_module.xml">SSI</link>, and |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
419 <link doc="ngx_http_charset_module.xml">charset</link> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
420 filters. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
421 </tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
422 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
423 <tag-name> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
424 <literal>$r->send_http_header([<value>type</value>])</literal> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
425 </tag-name> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
426 <tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
427 sends the response header to a client. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
428 An optional <value>type</value> parameter sets the value of |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
429 the <header>Content-Type</header> response header field. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
430 If the value is an empty string, the <header>Content-Type</header> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
431 header field will not be passed. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
432 </tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
433 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
434 <tag-name><literal>$r->status(<value>code</value>)</literal></tag-name> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
435 <tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
436 sets a response code. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
437 </tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
438 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
439 <tag-name> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
440 <literal>$r->sleep(<value>milliseconds</value>, |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
441 <value>handler</value>)</literal> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
442 </tag-name> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
443 <tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
444 sets the specified handler |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
445 and stops request processing for the specified time. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
446 In the mean time, nginx continues to process other requests. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
447 After the specified time has elapsed, nginx will call the installed handler. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
448 Note that the handler function should be passed by reference. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
449 In order to pass data between handlers, |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
450 <literal>$r->variable()</literal> should be used. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
451 Example: |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
452 <example> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
453 package hello; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
454 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
455 use nginx; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
456 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
457 sub handler { |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
458 my $r = shift; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
459 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
460 $r->discard_request_body; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
461 $r->variable("var", "OK"); |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
462 $r->sleep(1000, <emphasis>\&next</emphasis>); |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
463 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
464 return OK; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
465 } |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
466 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
467 sub <emphasis>next</emphasis> { |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
468 my $r = shift; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
469 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
470 $r->send_http_header; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
471 $r->print($r->variable("var")); |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
472 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
473 return OK; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
474 } |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
475 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
476 1; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
477 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
478 __END__ |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
479 </example> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
480 </tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
481 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
482 <tag-name><literal>$r->unescape(<value>text</value>)</literal></tag-name> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
483 <tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
484 decodes a text encoded in the “%XX” form. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
485 </tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
486 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
487 <tag-name><literal>$r->uri</literal></tag-name> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
488 <tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
489 returns a request URI. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
490 </tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
491 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
492 <tag-name> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
493 <literal>$r->variable(<value>name</value>[, |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
494 <value>value</value>])</literal> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
495 </tag-name> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
496 <tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
497 returns or sets a value of the specified variable. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
498 Variables are local to each request. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
499 </tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
500 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
501 </list> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
502 </para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
503 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
504 </section> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
505 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
506 </module> |