Mercurial > hg > nginx-site
annotate xml/en/docs/http/ngx_http_perl_module.xml @ 416:c9c0550465c9
English translation of ngx_http_perl_module.
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Wed, 15 Feb 2012 14:45:05 +0000 |
parents | |
children | be54c443235a |
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 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
3 <!DOCTYPE module SYSTEM "../../../../dtd/module.dtd"> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
4 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
5 <module name="Module ngx_http_perl_module" |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
6 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
|
7 lang="en"> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
8 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
9 <section id="summary"> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
10 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
11 <para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
12 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
|
13 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
|
14 </para> |
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 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
|
18 <literal>--with-http_perl_module</literal> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
19 configuration parameter. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
20 <note> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
21 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
|
22 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
|
23 </note> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
24 </para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
25 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
26 </section> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
27 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
28 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
29 <section id="bugs" name="Known Bugs"> |
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 <para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
32 The module is experimental, caveat emptor applies. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
33 </para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
34 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
35 <para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
36 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
|
37 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
|
38 <literal>-Dusemultiplicity=yes</literal> or |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
39 <literal>-Dusethreads=yes</literal>. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
40 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
|
41 it needs to be built with the |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
42 <literal>-Dusemymalloc=no</literal> parameter. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
43 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
|
44 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
|
45 <example> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
46 $ perl -V:usemultiplicity -V:usemymalloc |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
47 usemultiplicity='define'; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
48 usemymalloc='n'; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
49 </example> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
50 </para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
51 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
52 <para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
53 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
|
54 <literal>-Dusemultiplicity=yes</literal> or |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
55 <literal>-Dusethreads=yes</literal>, |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
56 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
|
57 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
|
58 </para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
59 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
60 <para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
61 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
|
62 to grow in size after every reconfiguration. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
63 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
|
64 <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
|
65 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
|
66 </para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
67 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
68 <para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
69 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
|
70 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
|
71 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
|
72 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
|
73 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
|
74 access local file system. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
75 </para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
76 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
77 <para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
78 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
|
79 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
80 <note> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
81 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
|
82 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
|
83 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
|
84 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
|
85 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
|
86 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
|
87 numeric context will terminate with an error (FreeBSD): |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
88 <example> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
89 nginx in realloc(): warning: pointer to wrong page |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
90 Out of memory! |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
91 Callback called exit. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
92 </example> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
93 or (Linux): |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
94 <example> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
95 *** glibc detected *** realloc(): invalid pointer: ... *** |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
96 Out of memory! |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
97 Callback called exit. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
98 </example> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
99 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
|
100 to a variable. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
101 For example, the following code |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
102 <example> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
103 my $i = $r->variable('counter') + 1; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
104 </example> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
105 should be replaced by |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
106 <example> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
107 my $i = $r->variable('counter'); |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
108 $i++; |
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 </note> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
111 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
112 <note> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
113 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
|
114 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
|
115 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
|
116 <literal>$r->request_body_file</literal> methods). |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
117 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
|
118 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
|
119 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
|
120 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
|
121 <example> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
122 open FILE, '/path/' . $r->variable('name'); |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
123 </example> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
124 </note> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
125 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
126 </para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
127 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
128 </section> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
129 |
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 <section id="example" name="Example Configuration"> |
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 <para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
134 <example> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
135 http { |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
136 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
137 perl_modules perl/lib; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
138 perl_require hello.pm; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
139 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
140 perl_set $msie6 ' |
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 sub { |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
143 my $r = shift; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
144 my $ua = $r->header_in("User-Agent"); |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
145 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
146 return "" if $ua =~ /Opera/; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
147 return "1" if $ua =~ / MSIE [6-9]\.\d+/; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
148 return ""; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
149 } |
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 '; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
152 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
153 server { |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
154 location / { |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
155 perl hello::handler; |
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 </example> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
159 </para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
160 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
161 <para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
162 The <path>perl/lib/hello.pm</path> module: |
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 package hello; |
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 use nginx; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
167 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
168 sub handler { |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
169 my $r = shift; |
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 $r->send_http_header("text/html"); |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
172 return OK if $r->header_only; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
173 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
174 $r->print("hello!\n<br/>"); |
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 if (-f $r->filename or -d _) { |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
177 $r->print($r->uri, " exists!\n"); |
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 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
180 return OK; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
181 } |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
182 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
183 1; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
184 __END__ |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
185 </example> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
186 </para> |
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 </section> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
189 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
190 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
191 <section id="directives" name="Directives"> |
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 <directive name="perl"> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
194 <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
|
195 <default/> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
196 <context>location</context> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
197 <context>limit_except</context> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
198 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
199 <para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
200 Installs a Perl handler for the given location. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
201 </para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
202 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
203 </directive> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
204 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
205 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
206 <directive name="perl_modules"> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
207 <syntax><value>path</value></syntax> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
208 <default/> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
209 <context>http</context> |
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 <para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
212 Sets an additional path for Perl modules. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
213 </para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
214 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
215 </directive> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
216 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
217 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
218 <directive name="perl_require"> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
219 <syntax><value>module</value></syntax> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
220 <default/> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
221 <context>http</context> |
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 <para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
224 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
|
225 reconfiguration. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
226 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
|
227 </para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
228 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
229 </directive> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
230 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
231 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
232 <directive name="perl_set"> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
233 <syntax> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
234 <value>$variable</value> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
235 <value>module</value>::<value>function</value>|'sub { ... }'</syntax> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
236 <default/> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
237 <context>http</context> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
238 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
239 <para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
240 Installs a Perl handler for the specified variable. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
241 </para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
242 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
243 </directive> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
244 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
245 </section> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
246 |
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 <section id="ssi" name="Calling Perl from SSI"> |
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 <para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
251 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
|
252 <example> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
253 <!--# 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
|
254 --> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
255 </example> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
256 </para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
257 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
258 </section> |
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 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
261 <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
|
262 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
263 <para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
264 <list type="tag"> |
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 <tag-name><literal>$r->args</literal></tag-name> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
267 <tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
268 returns request arguments. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
269 </tag-desc> |
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->filename</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 a filename corresponding to the request URI. |
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> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
277 <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
|
278 </tag-name> |
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 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
|
281 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
|
282 and 1 is returned. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
283 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
|
284 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
|
285 Example: |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
286 <example> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
287 package hello; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
288 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
289 use nginx; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
290 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
291 sub handler { |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
292 my $r = shift; |
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 if ($r->request_method ne "POST") { |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
295 return DECLINED; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
296 } |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
297 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
298 if ($r->has_request_body(<emphasis>\&post</emphasis>)) { |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
299 return OK; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
300 } |
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 return HTTP_BAD_REQUEST; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
303 } |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
304 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
305 sub <emphasis>post</emphasis> { |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
306 my $r = shift; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
307 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
308 $r->send_http_header; |
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 $r->print("request_body: \"", $r->request_body, "\"<br/>"); |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
311 $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
|
312 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
313 return OK; |
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 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
316 1; |
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 __END__ |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
319 </example> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
320 </tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
321 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
322 <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
|
323 <tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
324 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
|
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->discard_request_body</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 instructs nginx to discard a request body. |
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->header_in(<value>field</value>)</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 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
|
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_only</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 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
|
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> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
343 <literal>$r->header_out(<value>field</value>, |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
344 <value>value</value>)</literal> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
345 </tag-name> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
346 <tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
347 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
|
348 </tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
349 |
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 <literal>$r->internal_redirect(<value>uri</value>)</literal> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
352 </tag-name> |
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 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
|
355 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
|
356 </tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
357 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
358 <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
|
359 <tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
360 passes data to a client. |
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->request_body</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 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
|
366 written to a temporary file. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
367 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
|
368 its size should be limited with |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
369 <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
|
370 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
|
371 <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
|
372 </tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
373 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
374 <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
|
375 <tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
376 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
|
377 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
|
378 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
|
379 <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
|
380 needs to be enabled. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
381 </tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
382 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
383 <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
|
384 <tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
385 returns client request HTTP method. |
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->remote_addr</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 IP address. |
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->flush</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 immediately sends data to a client. |
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> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
399 <literal>$r->sendfile(<value>name</value>[, |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
400 <value>offset</value>[, |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
401 <value>length</value>]])</literal> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
402 </tag-name> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
403 <tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
404 sends the specified file content to a client. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
405 Optional parameters |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
406 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
|
407 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
|
408 has completed. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
409 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
|
410 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
|
411 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
|
412 <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
|
413 <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
|
414 <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
|
415 filters. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
416 </tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
417 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
418 <tag-name> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
419 <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
|
420 </tag-name> |
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 sends the response header to a client. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
423 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
|
424 the <header>Content-Type</header> response header field. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
425 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
|
426 header field will not be passed. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
427 </tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
428 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
429 <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
|
430 <tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
431 sets a response code. |
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> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
435 <literal>$r->sleep(<value>milliseconds</value>, |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
436 <value>handler</value>)</literal> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
437 </tag-name> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
438 <tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
439 sets the specified handler |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
440 and stops request processing for the specified time. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
441 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
|
442 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
|
443 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
|
444 In order to pass data between handlers, |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
445 <literal>$r->variable()</literal> should be used. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
446 Example: |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
447 <example> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
448 package hello; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
449 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
450 use nginx; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
451 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
452 sub handler { |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
453 my $r = shift; |
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 $r->discard_request_body; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
456 $r->variable("var", "OK"); |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
457 $r->sleep(1000, <emphasis>\&next</emphasis>); |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
458 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
459 return OK; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
460 } |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
461 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
462 sub <emphasis>next</emphasis> { |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
463 my $r = shift; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
464 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
465 $r->send_http_header; |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
466 $r->print($r->variable("var")); |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
467 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
468 return OK; |
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 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
471 1; |
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 __END__ |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
474 </example> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
475 </tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
476 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
477 <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
|
478 <tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
479 decodes a text encoded in the “%XX” form. |
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->uri</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 returns a request URI. |
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> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
488 <literal>$r->variable(<value>name</value>[, |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
489 <value>value</value>])</literal> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
490 </tag-name> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
491 <tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
492 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
|
493 Variables are local to each request. |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
494 </tag-desc> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
495 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
496 </list> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
497 </para> |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
498 |
c9c0550465c9
English translation of ngx_http_perl_module.
Ruslan Ermilov <ru@nginx.com>
parents:
diff
changeset
|
499 </section> |
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 </module> |