Module « wsgiref.simple_server »
Python 3.11.3
Classe « BaseHTTPRequestHandler »
Informations générales
Héritage
builtins.object
BaseRequestHandler
StreamRequestHandler
BaseHTTPRequestHandler
Définition
class BaseHTTPRequestHandler(StreamRequestHandler):
help(BaseHTTPRequestHandler)
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 may have about
HTTP (so you don't need to read the code to figure out I'm wrong
:-).
HTTP (HyperText Transfer Protocol) is an 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 are 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 are 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 components
and allowing trailing whitespace).
Similarly, for output, lines ought to be separated by CRLF pairs
but 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) then this is assumed to be an HTTP
0.9 request; this form has no 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 are 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> is 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 will be 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 that the request name is case sensitive (i.e. SPAM and spam
are different requests).
The various request details are stored in instance variables:
- client_address is the client IP address in the form (host,
port);
- command, path and version are 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 IS IMPORTANT TO ADHERE TO THE PROTOCOL FOR WRITING!
The first thing to be written must be 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 most cases, when data is
returned, there should be 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".
Constructeur(s)
Liste des attributs statiques
default_request_version | |
disable_nagle_algorithm | |
error_content_type | |
error_message_format | |
monthname | |
protocol_version | |
rbufsize | |
responses | |
server_version | |
sys_version | |
timeout | |
wbufsize | |
weekdayname | |
Liste des opérateurs
Opérateurs hérités de la classe object
__eq__,
__ge__,
__gt__,
__le__,
__lt__,
__ne__
Liste des méthodes
Toutes les méthodes
Méthodes d'instance
Méthodes statiques
Méthodes dépréciées
address_string(self) |
Return the client address. [extrait de address_string.__doc__] |
date_time_string(self, timestamp=None) |
Return the current date and time formatted for a message header. [extrait de date_time_string.__doc__] |
end_headers(self) |
Send the blank line ending the MIME headers. [extrait de end_headers.__doc__] |
flush_headers(self) |
|
handle(self) |
Handle multiple requests if necessary. [extrait de handle.__doc__] |
handle_expect_100(self) |
Decide what to do with an "Expect: 100-continue" header. [extrait de handle_expect_100.__doc__] |
handle_one_request(self) |
Handle a single HTTP request. [extrait de handle_one_request.__doc__] |
log_date_time_string(self) |
Return the current time formatted for logging. [extrait de log_date_time_string.__doc__] |
log_error(self, format, *args) |
Log an error. [extrait de log_error.__doc__] |
log_message(self, format, *args) |
Log an arbitrary message. [extrait de log_message.__doc__] |
log_request(self, code='-', size='-') |
Log an accepted request. [extrait de log_request.__doc__] |
parse_request(self) |
Parse a request (internal). [extrait de parse_request.__doc__] |
send_error(self, code, message=None, explain=None) |
Send and log an error reply. [extrait de send_error.__doc__] |
send_header(self, keyword, value) |
Send a MIME header to the headers buffer. [extrait de send_header.__doc__] |
send_response(self, code, message=None) |
Add the response header to the headers buffer and log the [extrait de send_response.__doc__] |
send_response_only(self, code, message=None) |
Send the response header only. [extrait de send_response_only.__doc__] |
version_string(self) |
Return the server software version string. [extrait de version_string.__doc__] |
Méthodes héritées de la classe StreamRequestHandler
__init_subclass__, __subclasshook__, finish, setup
Méthodes héritées de la classe object
__delattr__,
__dir__,
__format__,
__getattribute__,
__getstate__,
__hash__,
__reduce__,
__reduce_ex__,
__repr__,
__setattr__,
__sizeof__,
__str__
Améliorations / Corrections
Vous avez des améliorations (ou des corrections) à proposer pour ce document : je vous remerçie par avance de m'en faire part, cela m'aide à améliorer le site.
Emplacement :
Description des améliorations :