OLD | NEW |
1 """HTTP server base class. | 1 """HTTP server base class. |
2 | 2 |
3 Note: the class in this module doesn't implement any HTTP request; see | 3 Note: the class in this module doesn't implement any HTTP request; see |
4 SimpleHTTPServer for simple implementations of GET, HEAD and POST | 4 SimpleHTTPServer for simple implementations of GET, HEAD and POST |
5 (including CGI scripts). It does, however, optionally implement HTTP/1.1 | 5 (including CGI scripts). It does, however, optionally implement HTTP/1.1 |
6 persistent connections, as of version 0.3. | 6 persistent connections, as of version 0.3. |
7 | 7 |
8 Contents: | 8 Contents: |
9 | 9 |
10 - BaseHTTPRequestHandler: HTTP request handler base class | 10 - BaseHTTPRequestHandler: HTTP request handler base class |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 self.close_connection = 1 | 314 self.close_connection = 1 |
315 return | 315 return |
316 if not self.parse_request(): # An error code has been sent, just exit | 316 if not self.parse_request(): # An error code has been sent, just exit |
317 return | 317 return |
318 mname = 'do_' + self.command | 318 mname = 'do_' + self.command |
319 if not hasattr(self, mname): | 319 if not hasattr(self, mname): |
320 self.send_error(501, "Unsupported method (%r)" % self.command) | 320 self.send_error(501, "Unsupported method (%r)" % self.command) |
321 return | 321 return |
322 method = getattr(self, mname) | 322 method = getattr(self, mname) |
323 method() | 323 method() |
| 324 self.wfile.flush() #actually send the response if not already done. |
324 | 325 |
325 def handle(self): | 326 def handle(self): |
326 """Handle multiple requests if necessary.""" | 327 """Handle multiple requests if necessary.""" |
327 self.close_connection = 1 | 328 self.close_connection = 1 |
328 | 329 |
329 self.handle_one_request() | 330 self.handle_one_request() |
330 while not self.close_connection: | 331 while not self.close_connection: |
331 self.handle_one_request() | 332 self.handle_one_request() |
332 | 333 |
333 def send_error(self, code, message=None): | 334 def send_error(self, code, message=None): |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 HandlerClass.protocol_version = protocol | 584 HandlerClass.protocol_version = protocol |
584 httpd = ServerClass(server_address, HandlerClass) | 585 httpd = ServerClass(server_address, HandlerClass) |
585 | 586 |
586 sa = httpd.socket.getsockname() | 587 sa = httpd.socket.getsockname() |
587 print "Serving HTTP on", sa[0], "port", sa[1], "..." | 588 print "Serving HTTP on", sa[0], "port", sa[1], "..." |
588 httpd.serve_forever() | 589 httpd.serve_forever() |
589 | 590 |
590 | 591 |
591 if __name__ == '__main__': | 592 if __name__ == '__main__': |
592 test() | 593 test() |
OLD | NEW |