Mercurial > cpython-lru_cache-weakref
annotate Doc/lib/libbasehttp.tex @ 39940:dfd809dcf680 2.5
Bug #1446043: correctly raise a LookupError if an encoding name given
to encodings.search_function() contains a dot.
(backport from rev. 52075)
| author | Georg Brandl <georg@python.org> |
|---|---|
| date | Sat, 30 Sep 2006 11:22:35 +0000 |
| parents | 4668df450672 |
| children |
| rev | line source |
|---|---|
| 8918 | 1 \section{\module{BaseHTTPServer} --- |
|
15139
dd49f29d9879
Better synopses based on suggestions from Ka-Ping Yee <ping@lfw.org>.
Fred Drake <fdrake@acm.org>
parents:
13625
diff
changeset
|
2 Basic HTTP server} |
|
dd49f29d9879
Better synopses based on suggestions from Ka-Ping Yee <ping@lfw.org>.
Fred Drake <fdrake@acm.org>
parents:
13625
diff
changeset
|
3 |
|
8716
760dcf197048
Adjusted to use the new module synopsis support macros.
Fred Drake <fdrake@acm.org>
parents:
7875
diff
changeset
|
4 \declaremodule{standard}{BaseHTTPServer} |
| 8855 | 5 \modulesynopsis{Basic HTTP server (base class for |
|
15139
dd49f29d9879
Better synopses based on suggestions from Ka-Ping Yee <ping@lfw.org>.
Fred Drake <fdrake@acm.org>
parents:
13625
diff
changeset
|
6 \class{SimpleHTTPServer} and \class{CGIHTTPServer}).} |
|
8716
760dcf197048
Adjusted to use the new module synopsis support macros.
Fred Drake <fdrake@acm.org>
parents:
7875
diff
changeset
|
7 |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
8 |
|
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
9 \indexii{WWW}{server} |
|
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
10 \indexii{HTTP}{protocol} |
|
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
11 \index{URL} |
|
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
12 \index{httpd} |
|
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
13 |
|
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
14 This module defines two classes for implementing HTTP servers |
|
18574
346dcafc878b
Minor changes to match the style guide.
Fred Drake <fdrake@acm.org>
parents:
15139
diff
changeset
|
15 (Web servers). Usually, this module isn't used directly, but is used |
|
346dcafc878b
Minor changes to match the style guide.
Fred Drake <fdrake@acm.org>
parents:
15139
diff
changeset
|
16 as a basis for building functioning Web servers. See the |
|
32309
fc6a73905e6f
make a reference to the SimpleHTTPServer module a hyperlink to the
Fred Drake <fdrake@acm.org>
parents:
31958
diff
changeset
|
17 \refmodule{SimpleHTTPServer}\refstmodindex{SimpleHTTPServer} and |
|
10983
39f242bf4622
Misc. changes related to the new sections.
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
18 \refmodule{CGIHTTPServer}\refstmodindex{CGIHTTPServer} modules. |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
19 |
| 7684 | 20 The first class, \class{HTTPServer}, is a |
|
18574
346dcafc878b
Minor changes to match the style guide.
Fred Drake <fdrake@acm.org>
parents:
15139
diff
changeset
|
21 \class{SocketServer.TCPServer} subclass. It creates and listens at the |
|
346dcafc878b
Minor changes to match the style guide.
Fred Drake <fdrake@acm.org>
parents:
15139
diff
changeset
|
22 HTTP socket, dispatching the requests to a handler. Code to create and |
| 7684 | 23 run the server looks like this: |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
24 |
|
7277
bf4e790bd61a
Remove all \bcode / \ecode cruft; this is no longer needed. See previous
Fred Drake <fdrake@acm.org>
parents:
7204
diff
changeset
|
25 \begin{verbatim} |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
26 def run(server_class=BaseHTTPServer.HTTPServer, |
|
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
27 handler_class=BaseHTTPServer.BaseHTTPRequestHandler): |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
28 server_address = ('', 8000) |
|
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
29 httpd = server_class(server_address, handler_class) |
|
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
30 httpd.serve_forever() |
|
7277
bf4e790bd61a
Remove all \bcode / \ecode cruft; this is no longer needed. See previous
Fred Drake <fdrake@acm.org>
parents:
7204
diff
changeset
|
31 \end{verbatim} |
| 7684 | 32 |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
33 \begin{classdesc}{HTTPServer}{server_address, RequestHandlerClass} |
|
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
34 This class builds on the \class{TCPServer} class by |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
35 storing the server address as instance |
| 7684 | 36 variables named \member{server_name} and \member{server_port}. The |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
37 server is accessible by the handler, typically through the handler's |
| 7684 | 38 \member{server} instance variable. |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
39 \end{classdesc} |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
40 |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
41 \begin{classdesc}{BaseHTTPRequestHandler}{request, client_address, server} |
|
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
42 This class is used |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
43 to handle the HTTP requests that arrive at the server. By itself, |
|
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
44 it cannot respond to any actual HTTP requests; it must be subclassed |
|
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
45 to handle each request method (e.g. GET or POST). |
| 7684 | 46 \class{BaseHTTPRequestHandler} provides a number of class and instance |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
47 variables, and methods for use by subclasses. |
|
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
48 |
|
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
49 The handler will parse the request and the headers, then call a |
|
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
50 method specific to the request type. The method name is constructed |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
51 from the request. For example, for the request method \samp{SPAM}, the |
| 7684 | 52 \method{do_SPAM()} method will be called with no arguments. All of |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
53 the relevant information is stored in instance variables of the |
|
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
54 handler. Subclasses should not need to override or extend the |
|
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
55 \method{__init__()} method. |
|
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
56 \end{classdesc} |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
57 |
|
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
58 |
| 7684 | 59 \class{BaseHTTPRequestHandler} has the following instance variables: |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
60 |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
61 \begin{memberdesc}{client_address} |
| 7684 | 62 Contains a tuple of the form \code{(\var{host}, \var{port})} referring |
| 63 to the client's address. | |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
64 \end{memberdesc} |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
65 |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
66 \begin{memberdesc}{command} |
| 7684 | 67 Contains the command (request type). For example, \code{'GET'}. |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
68 \end{memberdesc} |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
69 |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
70 \begin{memberdesc}{path} |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
71 Contains the request path. |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
72 \end{memberdesc} |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
73 |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
74 \begin{memberdesc}{request_version} |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
75 Contains the version string from the request. For example, |
| 7684 | 76 \code{'HTTP/1.0'}. |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
77 \end{memberdesc} |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
78 |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
79 \begin{memberdesc}{headers} |
| 7684 | 80 Holds an instance of the class specified by the \member{MessageClass} |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
81 class variable. This instance parses and manages the headers in |
|
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
82 the HTTP request. |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
83 \end{memberdesc} |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
84 |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
85 \begin{memberdesc}{rfile} |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
86 Contains an input stream, positioned at the start of the optional |
|
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
87 input data. |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
88 \end{memberdesc} |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
89 |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
90 \begin{memberdesc}{wfile} |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
91 Contains the output stream for writing a response back to the client. |
|
13625
fdfd1049f36e
Rob W. W. Hooft's spelling fixes for the Library Reference. I hope
Thomas Wouters <thomas@python.org>
parents:
10983
diff
changeset
|
92 Proper adherence to the HTTP protocol must be used when writing |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
93 to this stream. |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
94 \end{memberdesc} |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
95 |
|
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
96 |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
97 \class{BaseHTTPRequestHandler} has the following class variables: |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
98 |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
99 \begin{memberdesc}{server_version} |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
100 Specifies the server software version. You may want to override |
|
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
101 this. |
|
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
102 The format is multiple whitespace-separated strings, |
|
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
103 where each string is of the form name[/version]. |
| 7684 | 104 For example, \code{'BaseHTTP/0.2'}. |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
105 \end{memberdesc} |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
106 |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
107 \begin{memberdesc}{sys_version} |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
108 Contains the Python system version, in a form usable by the |
| 7684 | 109 \member{version_string} method and the \member{server_version} class |
| 110 variable. For example, \code{'Python/1.4'}. | |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
111 \end{memberdesc} |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
112 |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
113 \begin{memberdesc}{error_message_format} |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
114 Specifies a format string for building an error response to the |
|
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
115 client. It uses parenthesized, keyed format specifiers, so the |
|
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
116 format operand must be a dictionary. The \var{code} key should |
|
13625
fdfd1049f36e
Rob W. W. Hooft's spelling fixes for the Library Reference. I hope
Thomas Wouters <thomas@python.org>
parents:
10983
diff
changeset
|
117 be an integer, specifying the numeric HTTP error code value. |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
118 \var{message} should be a string containing a (detailed) error |
|
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
119 message of what occurred, and \var{explain} should be an |
|
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
120 explanation of the error code number. Default \var{message} |
|
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
121 and \var{explain} values can found in the \var{responses} |
|
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
122 class variable. |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
123 \end{memberdesc} |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
124 |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
125 \begin{memberdesc}{protocol_version} |
|
22346
27f36f4bf525
Patch #430706: Persistent connections in BaseHTTPServer.
Martin v. Löwis <martin@v.loewis.de>
parents:
18574
diff
changeset
|
126 This specifies the HTTP protocol version used in responses. If set |
|
27f36f4bf525
Patch #430706: Persistent connections in BaseHTTPServer.
Martin v. Löwis <martin@v.loewis.de>
parents:
18574
diff
changeset
|
127 to \code{'HTTP/1.1'}, the server will permit HTTP persistent |
|
27f36f4bf525
Patch #430706: Persistent connections in BaseHTTPServer.
Martin v. Löwis <martin@v.loewis.de>
parents:
18574
diff
changeset
|
128 connections; however, your server \emph{must} then include an |
|
27f36f4bf525
Patch #430706: Persistent connections in BaseHTTPServer.
Martin v. Löwis <martin@v.loewis.de>
parents:
18574
diff
changeset
|
129 accurate \code{Content-Length} header (using \method{send_header()}) |
|
27f36f4bf525
Patch #430706: Persistent connections in BaseHTTPServer.
Martin v. Löwis <martin@v.loewis.de>
parents:
18574
diff
changeset
|
130 in all of its responses to clients. For backwards compatibility, |
|
27f36f4bf525
Patch #430706: Persistent connections in BaseHTTPServer.
Martin v. Löwis <martin@v.loewis.de>
parents:
18574
diff
changeset
|
131 the setting defaults to \code{'HTTP/1.0'}. |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
132 \end{memberdesc} |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
133 |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
134 \begin{memberdesc}{MessageClass} |
| 7684 | 135 Specifies a \class{rfc822.Message}-like class to parse HTTP |
| 136 headers. Typically, this is not overridden, and it defaults to | |
| 137 \class{mimetools.Message}. | |
| 138 \withsubitem{(in module mimetools)}{\ttindex{Message}} | |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
139 \end{memberdesc} |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
140 |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
141 \begin{memberdesc}{responses} |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
142 This variable contains a mapping of error code integers to two-element |
|
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
143 tuples containing a short and long message. For example, |
| 7684 | 144 \code{\{\var{code}: (\var{shortmessage}, \var{longmessage})\}}. The |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
145 \var{shortmessage} is usually used as the \var{message} key in an |
|
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
146 error response, and \var{longmessage} as the \var{explain} key |
| 7684 | 147 (see the \member{error_message_format} class variable). |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
148 \end{memberdesc} |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
149 |
|
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
150 |
| 7684 | 151 A \class{BaseHTTPRequestHandler} instance has the following methods: |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
152 |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
153 \begin{methoddesc}{handle}{} |
|
22346
27f36f4bf525
Patch #430706: Persistent connections in BaseHTTPServer.
Martin v. Löwis <martin@v.loewis.de>
parents:
18574
diff
changeset
|
154 Calls \method{handle_one_request()} once (or, if persistent connections |
|
27f36f4bf525
Patch #430706: Persistent connections in BaseHTTPServer.
Martin v. Löwis <martin@v.loewis.de>
parents:
18574
diff
changeset
|
155 are enabled, multiple times) to handle incoming HTTP requests. |
|
27f36f4bf525
Patch #430706: Persistent connections in BaseHTTPServer.
Martin v. Löwis <martin@v.loewis.de>
parents:
18574
diff
changeset
|
156 You should never need to override it; instead, implement appropriate |
|
27f36f4bf525
Patch #430706: Persistent connections in BaseHTTPServer.
Martin v. Löwis <martin@v.loewis.de>
parents:
18574
diff
changeset
|
157 \method{do_*()} methods. |
|
27f36f4bf525
Patch #430706: Persistent connections in BaseHTTPServer.
Martin v. Löwis <martin@v.loewis.de>
parents:
18574
diff
changeset
|
158 \end{methoddesc} |
|
27f36f4bf525
Patch #430706: Persistent connections in BaseHTTPServer.
Martin v. Löwis <martin@v.loewis.de>
parents:
18574
diff
changeset
|
159 |
|
27f36f4bf525
Patch #430706: Persistent connections in BaseHTTPServer.
Martin v. Löwis <martin@v.loewis.de>
parents:
18574
diff
changeset
|
160 \begin{methoddesc}{handle_one_request}{} |
|
27f36f4bf525
Patch #430706: Persistent connections in BaseHTTPServer.
Martin v. Löwis <martin@v.loewis.de>
parents:
18574
diff
changeset
|
161 This method will parse and dispatch |
|
27f36f4bf525
Patch #430706: Persistent connections in BaseHTTPServer.
Martin v. Löwis <martin@v.loewis.de>
parents:
18574
diff
changeset
|
162 the request to the appropriate \method{do_*()} method. You should |
|
27f36f4bf525
Patch #430706: Persistent connections in BaseHTTPServer.
Martin v. Löwis <martin@v.loewis.de>
parents:
18574
diff
changeset
|
163 never need to override it. |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
164 \end{methoddesc} |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
165 |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
166 \begin{methoddesc}{send_error}{code\optional{, message}} |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
167 Sends and logs a complete error reply to the client. The numeric |
|
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
168 \var{code} specifies the HTTP error code, with \var{message} as |
|
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
169 optional, more specific text. A complete set of headers is sent, |
| 7684 | 170 followed by text composed using the \member{error_message_format} |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
171 class variable. |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
172 \end{methoddesc} |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
173 |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
174 \begin{methoddesc}{send_response}{code\optional{, message}} |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
175 Sends a response header and logs the accepted request. The HTTP |
|
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
176 response line is sent, followed by \emph{Server} and \emph{Date} |
|
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
177 headers. The values for these two headers are picked up from the |
| 7684 | 178 \method{version_string()} and \method{date_time_string()} methods, |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
179 respectively. |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
180 \end{methoddesc} |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
181 |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
182 \begin{methoddesc}{send_header}{keyword, value} |
|
31958
338577afdab6
the headers in an HTTP request are HTTP headers, not MIME headers
Fred Drake <fdrake@acm.org>
parents:
22346
diff
changeset
|
183 Writes a specific HTTP header to the output stream. \var{keyword} |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
184 should specify the header keyword, with \var{value} specifying |
|
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
185 its value. |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
186 \end{methoddesc} |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
187 |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
188 \begin{methoddesc}{end_headers}{} |
|
31958
338577afdab6
the headers in an HTTP request are HTTP headers, not MIME headers
Fred Drake <fdrake@acm.org>
parents:
22346
diff
changeset
|
189 Sends a blank line, indicating the end of the HTTP headers in |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
190 the response. |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
191 \end{methoddesc} |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
192 |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
193 \begin{methoddesc}{log_request}{\optional{code\optional{, size}}} |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
194 Logs an accepted (successful) request. \var{code} should specify |
|
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
195 the numeric HTTP code associated with the response. If a size of |
|
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
196 the response is available, then it should be passed as the |
|
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
197 \var{size} parameter. |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
198 \end{methoddesc} |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
199 |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
200 \begin{methoddesc}{log_error}{...} |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
201 Logs an error when a request cannot be fulfilled. By default, |
| 7684 | 202 it passes the message to \method{log_message()}, so it takes the |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
203 same arguments (\var{format} and additional values). |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
204 \end{methoddesc} |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
205 |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
206 \begin{methoddesc}{log_message}{format, ...} |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
207 Logs an arbitrary message to \code{sys.stderr}. This is typically |
|
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
208 overridden to create custom error logging mechanisms. The |
|
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
209 \var{format} argument is a standard printf-style format string, |
| 7684 | 210 where the additional arguments to \method{log_message()} are applied |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
211 as inputs to the formatting. The client address and current date |
|
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
212 and time are prefixed to every message logged. |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
213 \end{methoddesc} |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
214 |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
215 \begin{methoddesc}{version_string}{} |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
216 Returns the server software's version string. This is a combination |
| 7684 | 217 of the \member{server_version} and \member{sys_version} class variables. |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
218 \end{methoddesc} |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
219 |
|
36555
4668df450672
Patch #1417555: SimpleHTTPServer now returns Last-Modified headers.
Georg Brandl <georg@python.org>
parents:
32309
diff
changeset
|
220 \begin{methoddesc}{date_time_string}{\optional{timestamp}} |
|
4668df450672
Patch #1417555: SimpleHTTPServer now returns Last-Modified headers.
Georg Brandl <georg@python.org>
parents:
32309
diff
changeset
|
221 Returns the date and time given by \var{timestamp} (which must be in the |
|
4668df450672
Patch #1417555: SimpleHTTPServer now returns Last-Modified headers.
Georg Brandl <georg@python.org>
parents:
32309
diff
changeset
|
222 format returned by \function{time.time()}), formatted for a message header. |
|
4668df450672
Patch #1417555: SimpleHTTPServer now returns Last-Modified headers.
Georg Brandl <georg@python.org>
parents:
32309
diff
changeset
|
223 If \var{timestamp} is omitted, it uses the current date and time. |
|
4668df450672
Patch #1417555: SimpleHTTPServer now returns Last-Modified headers.
Georg Brandl <georg@python.org>
parents:
32309
diff
changeset
|
224 |
|
4668df450672
Patch #1417555: SimpleHTTPServer now returns Last-Modified headers.
Georg Brandl <georg@python.org>
parents:
32309
diff
changeset
|
225 The result looks like \code{'Sun, 06 Nov 1994 08:49:37 GMT'}. |
|
4668df450672
Patch #1417555: SimpleHTTPServer now returns Last-Modified headers.
Georg Brandl <georg@python.org>
parents:
32309
diff
changeset
|
226 \versionadded[The \var{timestamp} parameter]{2.5} |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
227 \end{methoddesc} |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
228 |
|
36555
4668df450672
Patch #1417555: SimpleHTTPServer now returns Last-Modified headers.
Georg Brandl <georg@python.org>
parents:
32309
diff
changeset
|
229 \begin{methoddesc}{log_date_time_string}{} |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
230 Returns the current date and time, formatted for logging. |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
231 \end{methoddesc} |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
232 |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
233 \begin{methoddesc}{address_string}{} |
|
6970
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
234 Returns the client address, formatted for logging. A name lookup |
|
e5aff41036f3
Added Greg Stein's docs for BaseHTTPServer.py.
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
235 is performed on the client's IP address. |
|
7875
8f425f8f4be2
Remove obsolete \setindexsubitem macros.
Fred Drake <fdrake@acm.org>
parents:
7712
diff
changeset
|
236 \end{methoddesc} |
|
10983
39f242bf4622
Misc. changes related to the new sections.
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
237 |
|
39f242bf4622
Misc. changes related to the new sections.
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
238 |
|
39f242bf4622
Misc. changes related to the new sections.
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
239 \begin{seealso} |
|
39f242bf4622
Misc. changes related to the new sections.
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
240 \seemodule{CGIHTTPServer}{Extended request handler that supports CGI |
|
39f242bf4622
Misc. changes related to the new sections.
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
241 scripts.} |
|
39f242bf4622
Misc. changes related to the new sections.
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
242 |
|
39f242bf4622
Misc. changes related to the new sections.
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
243 \seemodule{SimpleHTTPServer}{Basic request handler that limits response |
|
39f242bf4622
Misc. changes related to the new sections.
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
244 to files actually under the document root.} |
|
39f242bf4622
Misc. changes related to the new sections.
Fred Drake <fdrake@acm.org>
parents:
8918
diff
changeset
|
245 \end{seealso} |
