Class Basehttprequesthandler (Socketserver. Streamrequesthandler)
HTTP Request Handler base class.
|
| The following explanation of HTTP serves to guide you through the
| Code as well as to expose any misunderstandings I
| HTTP (so you don't need to read the code to figure out I ' m wrong
| :-).
|
| HTTP (hypertext Transfer Protocol) is a extensible Protocol on
| Top of a reliable stream transport (e.g. TCP/IP). The Protocol
| Recognizes three parts to a request:
|
| 1. One line identifying the request type and path
| 2. An optional set of Rfc-822-style headers
| 3. An optional data part
|
| The headers and data is separated by a blank line.
|
| The first line of the request has the form
|
| <command> <path> <version>
|
| Where <command> is a (case-sensitive) keyword such as GET or POST,
| <path> is a string containing path information for the request,
| And <version> should be the string "http/1.0" or "http/1.1".
| <path> is encoded using the URL encoding scheme (using%XX to signify
| The ASCII character with hex code XX).
|
| The specification specifies that lines is separated by CRLF but
| For compatibility with the widest range of clients recommends
| servers also handle LF. Similarly, whitespace in the request line
| is treated sensibly (allowing multiple spaces between
| and allowing trailing whitespace).
|
| Similarly, for output, lines ought to is separated by CRLF pairs
| But the most clients grok LF characters just fine.
|
| If the first line of the request has the form
| <command> <path>
|
| (i.e. <version> is left out) and then the is assumed
| 0.9 request; This form has a optional headers and data part and
| The reply consists of just the data.
|
| The reply form of the HTTP 1.x protocol again has three parts:
|
| 1. One line giving the response code
| 2. An optional set of Rfc-822-style headers
| 3. The data
|
| Again, the headers and data is separated by a blank line.
|
| The response code line has the form
|
| <version> <responsecode> <responsestring>
|
| Where <version> is the protocol version ("http/1.0" or "http/1.1"),
| <responsecode> is a 3-digit response code indicating success or
| Failure of the request, and <responsestring> are an optional
| Human-readable string explaining what the response code means.
|
| This server parses the request and the headers, and then calls a
| function specific to the request type (<command>). Specifically,
| A request SPAM is handled by a method Do_spam (). If No
| Such method exists the server sends an error response to the
| Client. If it exists, it is called with no arguments:
|
| Do_spam ()
|
| Note the request name is case sensitive (i.e. SPAM and SPAM
| is different requests).
| The various request details is stored in instance variables:
|
| -Client_address is the client IP address in the form (host,
| Port);
|
| -command, path and version is the broken-down request line;
|
| -headers is an instance of Email.message.Message (or a derived
| Class) containing the header information;
|
| -Rfile is a file object open for reading positioned at the
| Start of the optional input data part;
|
| -Wfile is a file object open for writing.
|
| IT's IMPORTANT to adhere to the PROTOCOL for writing!
|
| The first thing to be written must is the response line. Then
| Follow 0 or more header lines, then a blank line, and then the
| Actual data (if any). The meaning of the header lines depends on
| The command executed by the server; In more cases, when the data is
| Returned, there should is at least one header line of the form
|
| Content-type: <type>/<subtype>
|
| where <type> and <subtype> should be registered MIME types,
| e.g. "text/html" or "Text/plain".
|
| Method Resolution Order:
| Basehttprequesthandler
| Socketserver. Streamrequesthandler
| Socketserver. Baserequesthandler
| Builtins.object
Python--baseequestandler class (interesting found in Python ' s document)