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 ext
| 169 | |
| 170 | |
| 171 | class BaseHTTPRequestHandler(socketserver.StreamRequestHandler): |
| 172 | |
| 173 | """HTTP request handler base class. |
| 174 | |
| 175 | The following explanation of HTTP serves to guide you through the |
| 176 | code as well as to expose any misunderstandings I may have about |
| 177 | HTTP (so you don't need to read the code to figure out I'm wrong |
| 178 | :-). |
| 179 | |
| 180 | HTTP (HyperText Transfer Protocol) is an extensible protocol on |
| 181 | top of a reliable stream transport (e.g. TCP/IP). The protocol |
| 182 | recognizes three parts to a request: |
| 183 | |
| 184 | 1. One line identifying the request type and path |
| 185 | 2. An optional set of RFC-822-style headers |
| 186 | 3. An optional data part |
| 187 | |
| 188 | The headers and data are separated by a blank line. |
| 189 | |
| 190 | The first line of the request has the form |
| 191 | |
| 192 | <command> <path> <version> |
| 193 | |
| 194 | where <command> is a (case-sensitive) keyword such as GET or POST, |
| 195 | <path> is a string containing path information for the request, |
| 196 | and <version> should be the string "HTTP/1.0" or "HTTP/1.1". |
| 197 | <path> is encoded using the URL encoding scheme (using %xx to signify |
| 198 | the ASCII character with hex code xx). |
| 199 | |
| 200 | The specification specifies that lines are separated by CRLF but |
| 201 | for compatibility with the widest range of clients recommends |
| 202 | servers also handle LF. Similarly, whitespace in the request line |
| 203 | is treated sensibly (allowing multiple spaces between components |
| 204 | and allowing trailing whitespace). |
| 205 | |
| 206 | Similarly, for output, lines ought to be separated by CRLF pairs |
| 207 | but most clients grok LF characters just fine. |
| 208 | |
| 209 | If the first line of the request has the form |
| 210 | |
| 211 | <command> <path> |
| 212 | |
| 213 | (i.e. <version> is left out) then this is assumed to be an HTTP |
| 214 | 0.9 request; this form has no optional headers and data part and |
| 215 | the reply consists of just the data. |
| 216 | |
| 217 | The reply form of the HTTP 1.x protocol again has three parts: |
| 218 | |
| 219 | 1. One line giving the response code |
| 220 | 2. An optional set of RFC-822-style headers |
| 221 | 3. The data |
| 222 | |
| 223 | Again, the headers and data are separated by a blank line. |
| 224 | |
| 225 | The response code line has the form |
| 226 | |
| 227 | <version> <responsecode> <responsestring> |
| 228 |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…