1
1
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
4
<link rel="STYLESHEET" href="modpython.css" type='text/css'>
5
<link rel="first" href="modpython.html" title='Mod_python Manual'>
6
<link rel='contents' href='contents.html' title="Contents">
7
<link rel='index' href='genindex.html' title='Index'>
8
<link rel='last' href='about.html' title='About this document...'>
9
<link rel='help' href='about.html' title='About this document...'>
10
<LINK REL="next" href="pyapi-mprequest-mem.html">
11
<LINK REL="prev" href="pyapi-mprequest.html">
12
<LINK REL="parent" href="pyapi-mprequest.html">
13
<LINK REL="next" href="pyapi-mprequest-mem.html">
14
<meta name='aesop' content='information'>
15
<META NAME="description" CONTENT="Request Methods">
16
<META NAME="keywords" CONTENT="modpython">
17
<META NAME="resource-type" CONTENT="document">
18
<META NAME="distribution" CONTENT="global">
19
<title>4.5.3.1 Request Methods</title>
4
<link rel="STYLESHEET" href="modpython.css" type='text/css' />
5
<link rel="first" href="modpython.html" title='Mod_python Manual' />
6
<link rel='contents' href='contents.html' title="Contents" />
7
<link rel='index' href='genindex.html' title='Index' />
8
<link rel='last' href='about.html' title='About this document...' />
9
<link rel='help' href='about.html' title='About this document...' />
10
<link rel="next" href="pyapi-mprequest-mem.html" />
11
<link rel="prev" href="pyapi-mprequest.html" />
12
<link rel="parent" href="pyapi-mprequest.html" />
13
<link rel="next" href="pyapi-mprequest-mem.html" />
14
<meta name='aesop' content='information' />
15
<title>4.5.4.1 Request Methods</title>
22
18
<DIV CLASS="navigation">
19
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
23
20
<table align="center" width="100%" cellpadding="0" cellspacing="2">
25
<td><a rel="prev" title="4.5.3 Request Object "
26
href="pyapi-mprequest.html"><img src='previous.gif'
27
border='0' height='32' alt='Previous Page' width='32'></A></td>
28
<td><a rel="parent" title="4.5.3 Request Object "
29
href="pyapi-mprequest.html"><img src='up.gif'
30
border='0' height='32' alt='Up One Level' width='32'></A></td>
31
<td><a rel="next" title="4.5.3.2 Request Members"
32
href="pyapi-mprequest-mem.html"><img src='next.gif'
33
border='0' height='32' alt='Next Page' width='32'></A></td>
22
<td class='online-navigation'><a rel="prev" title="4.5.4 Request Object"
23
href="pyapi-mprequest.html"><img src='previous.png'
24
border='0' height='32' alt='Previous Page' width='32' /></A></td>
25
<td class='online-navigation'><a rel="parent" title="4.5.4 Request Object"
26
href="pyapi-mprequest.html"><img src='up.png'
27
border='0' height='32' alt='Up One Level' width='32' /></A></td>
28
<td class='online-navigation'><a rel="next" title="4.5.4.2 Request Members"
29
href="pyapi-mprequest-mem.html"><img src='next.png'
30
border='0' height='32' alt='Next Page' width='32' /></A></td>
34
31
<td align="center" width="100%">Mod_python Manual</td>
35
<td><a rel="contents" title="Table of Contents"
36
href="contents.html"><img src='contents.gif'
37
border='0' height='32' alt='Contents' width='32'></A></td>
38
<td><img src='blank.gif'
39
border='0' height='32' alt='' width='32'></td>
40
<td><a rel="index" title="Index"
41
href="genindex.html"><img src='index.gif'
42
border='0' height='32' alt='Index' width='32'></A></td>
32
<td class='online-navigation'><a rel="contents" title="Table of Contents"
33
href="contents.html"><img src='contents.png'
34
border='0' height='32' alt='Contents' width='32' /></A></td>
35
<td class='online-navigation'><img src='blank.png'
36
border='0' height='32' alt='' width='32' /></td>
37
<td class='online-navigation'><a rel="index" title="Index"
38
href="genindex.html"><img src='index.png'
39
border='0' height='32' alt='Index' width='32' /></A></td>
41
<div class='online-navigation'>
44
42
<b class="navlabel">Previous:</b>
45
<a class="sectref" rel="prev" href="pyapi-mprequest.html">4.5.3 Request Object </A>
43
<a class="sectref" rel="prev" href="pyapi-mprequest.html">4.5.4 Request Object</A>
46
44
<b class="navlabel">Up:</b>
47
<a class="sectref" rel="parent" href="pyapi-mprequest.html">4.5.3 Request Object </A>
45
<a class="sectref" rel="parent" href="pyapi-mprequest.html">4.5.4 Request Object</A>
48
46
<b class="navlabel">Next:</b>
49
<a class="sectref" rel="next" href="pyapi-mprequest-mem.html">4.5.3.2 Request Members</A>
47
<a class="sectref" rel="next" href="pyapi-mprequest-mem.html">4.5.4.2 Request Members</A>
52
51
<!--End of Navigation Panel-->
54
<H3><A NAME="SECTION006531000000000000000"> </A>
53
<H3><A NAME="SECTION006541000000000000000"></A><A NAME="pyapi-mprequest-meth"></A>
56
4.5.3.1 Request Methods
55
4.5.4.1 Request Methods
60
59
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
61
<td><nobr><b><a name="l2h-45"><tt class="method">add_common_vars</tt></a></b>(</nobr></td>
62
<td>)</td></tr></table>
60
<td><nobr><b><tt id='l2h-48' xml:id='l2h-48' class="method">add_common_vars</tt></b>(</nobr></td>
61
<td><var></var>)</td></tr></table></dt>
64
63
Calls the Apache <tt class="cfunction">ap_add_common_vars()</tt> function. After a
65
64
call to this method, <tt class="member">req.subprocess_env</tt> will contain a
77
76
containing the name of any of the apache request (but not filter or
78
77
connection) handler directives,
79
78
e.g. "<tt class="samp">PythonHandler</tt>". <var>handler</var> is a string containing the
80
name of the module and the handler function. Optional <var>dir</var> is
81
a string containing the name of the directory to be added to the
82
pythonpath. If no directory is specified, then, if there is already
83
a handler of the same type specified, its directory is inherited,
84
otherwise the directory of the presently executing handler is
85
used. If there is a <code>PythonPath</code> directive in effect, then
86
<code>sys.path</code> will be set exactly according to it (no directories
87
added, the <var>dir</var> argument is ignored).
79
name of the module and the handler function, or the callable object
80
itself. Optional <var>dir</var> is a string containing the name of the
81
directory to be added to the module search path when looking for the
82
handler. If no directory is specified, then the directory to search
83
in is inherited from the handler which is making the registration,
90
86
A handler added this way only persists throughout the life of the
91
87
request. It is possible to register more handlers while inside the
92
handler of the same type. One has to be careful as to not to create
93
an infinite loop this way.
88
handler of the same type. One has to be careful as to not to create an
89
infinite loop this way.
96
92
Dynamic handler registration is a useful technique that allows the
112
108
If you pass this function an invalid handler, an exception will be
113
109
generated at the time an attempt is made to find the handler.
118
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
119
<td><nobr><b><a name="l2h-47"><tt class="method">allow_methods</tt></a></b>(</nobr></td>
120
<td><var>methods</var><big>[</big><var>, reset</var><big>]</big>)</td></tr></table>
116
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
117
<td><nobr><b><tt id='l2h-50' xml:id='l2h-50' class="method">add_input_filter</tt></b>(</nobr></td>
118
<td><var>filter_name</var>)</td></tr></table></dt>
120
Adds the named filter into the input filter chain for the current request.
121
The filter should be added before the first attempt to read any data from
126
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
127
<td><nobr><b><tt id='l2h-51' xml:id='l2h-51' class="method">add_output_filter</tt></b>(</nobr></td>
128
<td><var>filter_name</var>)</td></tr></table></dt>
130
Adds the named filter into the output filter chain for the current request.
131
The filter should be added before the first attempt to write any data for
135
Provided that all data written is being buffered and not flushed, this
136
could be used to add the "CONTENT_LENGTH" filter into the chain of
137
output filters. The purpose of the "CONTENT_LENGTH" filter is to add a
138
<code>Content-Length:</code> header to the response.
141
<div class="verbatim"><pre>
142
req.add_output_filter("CONTENT_LENGTH")
143
req.write("content",0)
150
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
151
<td><nobr><b><tt id='l2h-52' xml:id='l2h-52' class="method">allow_methods</tt></b>(</nobr></td>
152
<td><var>methods</var><big>[</big><var>, reset</var><big>]</big><var></var>)</td></tr></table></dt>
122
154
Adds methods to the <tt class="member">req.allowed_methods</tt> list. This list
123
155
will be passed in <code>Allowed:</code> header if
136
168
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
137
<td><nobr><b><a name="l2h-48"><tt class="method">document_root</tt></a></b>(</nobr></td>
138
<td>)</td></tr></table>
169
<td><nobr><b><tt id='l2h-53' xml:id='l2h-53' class="method">auth_name</tt></b>(</nobr></td>
170
<td><var></var>)</td></tr></table></dt>
172
Returns AuthName setting.
176
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
177
<td><nobr><b><tt id='l2h-54' xml:id='l2h-54' class="method">auth_type</tt></b>(</nobr></td>
178
<td><var></var>)</td></tr></table></dt>
180
Returns AuthType setting.
184
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
185
<td><nobr><b><tt id='l2h-55' xml:id='l2h-55' class="method">construct_url</tt></b>(</nobr></td>
186
<td><var>uri</var>)</td></tr></table></dt>
188
This function returns a fully qualified URI string from the path specified
189
by uri, using the information stored in the request to determine the scheme,
190
server name and port. The port number is not included in the string if it
191
is the same as the default port 80.
194
For example, imagine that the current request is directed to the virtual
195
server www.modpython.org at port 80. Then supplying "<tt class="samp">/index.html</tt>" will
196
yield the string "<tt class="samp">http://www.modpython.org/index.html</tt>".
202
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
203
<td><nobr><b><tt id='l2h-56' xml:id='l2h-56' class="method">discard_request_body</tt></b>(</nobr></td>
204
<td><var></var>)</td></tr></table></dt>
206
Tests for and reads any message body in the request, simply discarding
207
whatever it receives.
211
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
212
<td><nobr><b><tt id='l2h-57' xml:id='l2h-57' class="method">document_root</tt></b>(</nobr></td>
213
<td><var></var>)</td></tr></table></dt>
140
215
Returns DocumentRoot setting.
144
219
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
145
<td><nobr><b><a name="l2h-49"><tt class="method">get_basic_auth_pw</tt></a></b>(</nobr></td>
146
<td>)</td></tr></table>
220
<td><nobr><b><tt id='l2h-58' xml:id='l2h-58' class="method">get_basic_auth_pw</tt></b>(</nobr></td>
221
<td><var></var>)</td></tr></table></dt>
148
223
Returns a string containing the password when Basic authentication is
297
372
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
298
<td><nobr><b><a name="l2h-56"><tt class="method">meets_conditions</tt></a></b>(</nobr></td>
299
<td>)</td></tr></table>
373
<td><nobr><b><tt id='l2h-65' xml:id='l2h-65' class="method">meets_conditions</tt></b>(</nobr></td>
374
<td><var></var>)</td></tr></table></dt>
301
Calls the Apache <tt class="cfunction">ap_meets_conditions()</tt> function which
302
returns a status code. If <var>status</var> is <tt class="constant">apache.OK</tt>, generate
303
the content of the response normally. If not, simply return <var>status</var>.
304
Note that <tt class="member">req.headers_out</tt> should be set prior to calling this
305
function. The same goes for <tt class="member">req.status</tt> if the status differs
306
from <tt class="constant">apache.OK</tt>.
376
Calls the Apache <tt class="cfunction">ap_meets_conditions()</tt> function which returns
377
a status code. If <var>status</var> is <tt class="constant">apache.OK</tt>, generate the
378
content of the response normally. If not, simply return <var>status</var>.
379
Note that <var>mtime</var> (and possibly the ETag header) should be set as
380
appropriate prior to calling this function. The same goes for
381
<tt class="member">req.status</tt> if the status differs from <tt class="constant">apache.OK</tt>.
310
385
<div class="verbatim"><pre>
312
r.headers_out['ETag'] = "1130794f-3774-4584-a4ea-0ab19e684268"
313
r.headers_out['Last-Modified'] = 'Wed, 23 Feb 2005 00:00:00 GMT'
387
r.headers_out['ETag'] = '"1130794f-3774-4584-a4ea-0ab19e684268"'
314
388
r.headers_out['Expires'] = 'Mon, 18 Apr 2005 17:30:00 GMT'
389
r.update_mtime(1000000000)
390
r.set_last_modified()
316
392
status = r.meets_conditions()
317
393
if status != apache.OK:
394
470
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
395
<td><nobr><b><a name="l2h-60"><tt class="method">readlines</tt></a></b>(</nobr></td>
396
<td><big>[</big><var>sizehint</var><big>]</big>)</td></tr></table>
471
<td><nobr><b><tt id='l2h-69' xml:id='l2h-69' class="method">readlines</tt></b>(</nobr></td>
472
<td><var></var><big>[</big><var>sizehint</var><big>]</big><var></var>)</td></tr></table></dt>
398
Reads all or up to <var>sizehint</var> bytes of lines using
399
<tt class="method">readline</tt> and returns a list of the lines read.
474
Reads all lines using <tt class="method">readline</tt> and returns a list of the lines read.
475
If the optional <var>sizehint</var> parameter is given in, the method will read
476
at least <var>sizehint</var> bytes of data, up to the completion of the line in
477
which the <var>sizehint</var> bytes limit is reached.
403
481
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
404
<td><nobr><b><a name="l2h-61"><tt class="method">register_cleanup</tt></a></b>(</nobr></td>
405
<td><var>callable</var><big>[</big><var>, data</var><big>]</big>)</td></tr></table>
482
<td><nobr><b><tt id='l2h-70' xml:id='l2h-70' class="method">register_cleanup</tt></b>(</nobr></td>
483
<td><var>callable</var><big>[</big><var>, data</var><big>]</big><var></var>)</td></tr></table></dt>
434
512
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
435
<td><nobr><b><a name="l2h-62"><tt class="method">sendfile</tt></a></b>(</nobr></td>
436
<td><var>path</var><big>[</big><var>, offset, len</var><big>]</big>)</td></tr></table>
513
<td><nobr><b><tt id='l2h-71' xml:id='l2h-71' class="method">register_input_filter</tt></b>(</nobr></td>
514
<td><var>filter_name, filter</var><big>[</big><var>, dir</var><big>]</big><var></var>)</td></tr></table></dt>
518
Allows dynamic registration of mod_python input filters. <var>filter_name</var>
519
is a string which would then subsequently be used to identify the filter.
520
<var>filter</var> is a string containing the name of the module and the filter
521
function or the callable object itself. Optional <var>dir</var> is a string
522
containing the name of the directory to be added to the module search when
523
looking for the module.
526
The registration of the filter this way only persists for the life of the
527
request. To actually add the filter into the chain of input filters for
528
the current request <code>req.add_input_filter()</code> would be used.
534
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
535
<td><nobr><b><tt id='l2h-72' xml:id='l2h-72' class="method">register_output_filter</tt></b>(</nobr></td>
536
<td><var>filter_name, filter</var><big>[</big><var>, dir</var><big>]</big><var></var>)</td></tr></table></dt>
540
Allows dynamic registration of mod_python output filters. <var>filter_name</var>
541
is a string which would then subsequently be used to identify the filter.
542
<var>filter</var> is a string containing the name of the module and the filter
543
function or the callable object itself. Optional <var>dir</var> is a string
544
containing the name of the directory to be added to the module search
545
path when looking for the handler.
548
The registration of the filter this way only persists for the life of the
549
request. To actually add the filter into the chain of output filters for
550
the current request <code>req.add_output_filter()</code> would be used.
556
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
557
<td><nobr><b><tt id='l2h-73' xml:id='l2h-73' class="method">sendfile</tt></b>(</nobr></td>
558
<td><var>path</var><big>[</big><var>, offset, len</var><big>]</big><var></var>)</td></tr></table></dt>
438
560
Sends <var>len</var> bytes of file <var>path</var> directly to the client,
439
561
starting at offset <var>offset</var> using the server's internal
453
575
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
454
<td><nobr><b><a name="l2h-63"><tt class="method">ssl_var_lookup</tt></a></b>(</nobr></td>
455
<td><var>var_name</var>)</td></tr></table>
576
<td><nobr><b><tt id='l2h-74' xml:id='l2h-74' class="method">set_etag</tt></b>(</nobr></td>
577
<td><var></var>)</td></tr></table></dt>
579
Sets the outgoing "<tt class="samp">ETag</tt>" header.
583
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
584
<td><nobr><b><tt id='l2h-75' xml:id='l2h-75' class="method">set_last_modified</tt></b>(</nobr></td>
585
<td><var></var>)</td></tr></table></dt>
587
Sets the outgoing "<tt class="samp">Last-Modified</tt>" header based on value of
588
<code>mtime</code> attribute.
592
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
593
<td><nobr><b><tt id='l2h-76' xml:id='l2h-76' class="method">ssl_var_lookup</tt></b>(</nobr></td>
594
<td><var>var_name</var>)</td></tr></table></dt>
457
596
Looks up the value of the named SSL variable. This method queries
458
597
the mod_ssl Apache module directly, and may therefore be used in
497
636
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
498
<td><nobr><b><a name="l2h-64"><tt class="method">write</tt></a></b>(</nobr></td>
499
<td><var>string</var><big>[</big><var>, flush=1</var><big>]</big>)</td></tr></table>
637
<td><nobr><b><tt id='l2h-77' xml:id='l2h-77' class="method">update_mtime</tt></b>(</nobr></td>
638
<td><var>dependency_mtime</var>)</td></tr></table></dt>
640
If <var>dependency_mtime</var> is later than the value in the <code>mtime</code>
641
attribute, sets the attribute to the new value.
645
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
646
<td><nobr><b><tt id='l2h-78' xml:id='l2h-78' class="method">write</tt></b>(</nobr></td>
647
<td><var>string</var><big>[</big><var>, flush=1</var><big>]</big><var></var>)</td></tr></table></dt>
501
649
Writes <var>string</var> directly to the client, then flushes the buffer,
502
650
unless flush is 0.
526
674
<DIV CLASS="navigation">
675
<div class='online-navigation'>
528
677
<table align="center" width="100%" cellpadding="0" cellspacing="2">
530
<td><a rel="prev" title="4.5.3 Request Object "
531
rel="prev" title="4.5.3 Request Object "
532
href="pyapi-mprequest.html"><img src='previous.gif'
533
border='0' height='32' alt='Previous Page' width='32'></A></td>
534
<td><a rel="parent" title="4.5.3 Request Object "
535
rel="parent" title="4.5.3 Request Object "
536
href="pyapi-mprequest.html"><img src='up.gif'
537
border='0' height='32' alt='Up One Level' width='32'></A></td>
538
<td><a rel="next" title="4.5.3.2 Request Members"
539
rel="next" title="4.5.3.2 Request Members"
540
href="pyapi-mprequest-mem.html"><img src='next.gif'
541
border='0' height='32' alt='Next Page' width='32'></A></td>
679
<td class='online-navigation'><a rel="prev" title="4.5.4 Request Object"
680
href="pyapi-mprequest.html"><img src='previous.png'
681
border='0' height='32' alt='Previous Page' width='32' /></A></td>
682
<td class='online-navigation'><a rel="parent" title="4.5.4 Request Object"
683
href="pyapi-mprequest.html"><img src='up.png'
684
border='0' height='32' alt='Up One Level' width='32' /></A></td>
685
<td class='online-navigation'><a rel="next" title="4.5.4.2 Request Members"
686
href="pyapi-mprequest-mem.html"><img src='next.png'
687
border='0' height='32' alt='Next Page' width='32' /></A></td>
542
688
<td align="center" width="100%">Mod_python Manual</td>
543
<td><a rel="contents" title="Table of Contents"
544
rel="contents" title="Table of Contents"
545
href="contents.html"><img src='contents.gif'
546
border='0' height='32' alt='Contents' width='32'></A></td>
547
<td><img src='blank.gif'
548
border='0' height='32' alt='' width='32'></td>
549
<td><a rel="index" title="Index"
550
rel="index" title="Index"
551
href="genindex.html"><img src='index.gif'
552
border='0' height='32' alt='Index' width='32'></A></td>
689
<td class='online-navigation'><a rel="contents" title="Table of Contents"
690
href="contents.html"><img src='contents.png'
691
border='0' height='32' alt='Contents' width='32' /></A></td>
692
<td class='online-navigation'><img src='blank.png'
693
border='0' height='32' alt='' width='32' /></td>
694
<td class='online-navigation'><a rel="index" title="Index"
695
href="genindex.html"><img src='index.png'
696
border='0' height='32' alt='Index' width='32' /></A></td>
698
<div class='online-navigation'>
554
699
<b class="navlabel">Previous:</b>
555
<a class="sectref" rel="prev" href="pyapi-mprequest.html">4.5.3 Request Object </A>
700
<a class="sectref" rel="prev" href="pyapi-mprequest.html">4.5.4 Request Object</A>
556
701
<b class="navlabel">Up:</b>
557
<a class="sectref" rel="parent" href="pyapi-mprequest.html">4.5.3 Request Object </A>
702
<a class="sectref" rel="parent" href="pyapi-mprequest.html">4.5.4 Request Object</A>
558
703
<b class="navlabel">Next:</b>
559
<a class="sectref" rel="next" href="pyapi-mprequest-mem.html">4.5.3.2 Request Members</A>
561
<span class="release-info">Release 3.2.10, documentation updated on July 19, 2006.</span>
704
<a class="sectref" rel="next" href="pyapi-mprequest-mem.html">4.5.4.2 Request Members</A>
708
<span class="release-info">Release 3.3.1, documentation updated on January 29, 2007.</span>
563
710
<!--End of Navigation Panel-->