Revision b1d979cf lib/http.py
b/lib/http.py | ||
---|---|---|
412 | 412 |
self._ssl_cert.digest("md5") == cert.digest("md5")) |
413 | 413 |
|
414 | 414 |
|
415 |
class _HttpConnectionHandler(object):
|
|
415 |
class HttpServerRequestExecutor(object):
|
|
416 | 416 |
"""Implements server side of HTTP |
417 | 417 |
|
418 | 418 |
This class implements the server side of HTTP. It's based on code of Python's |
... | ... | |
465 | 465 |
|
466 | 466 |
self.should_fork = False |
467 | 467 |
|
468 |
logging.info("Connection from %s:%s", client_addr[0], client_addr[1]) |
|
468 | 469 |
try: |
469 |
self._ReadRequest() |
|
470 |
self._ReadPostData() |
|
471 |
except HTTPException, err: |
|
472 |
self._SetErrorStatus(err) |
|
470 |
try: |
|
471 |
try: |
|
472 |
try: |
|
473 |
# Read, parse and handle request |
|
474 |
self._ReadRequest() |
|
475 |
self._ReadPostData() |
|
476 |
self._HandleRequest() |
|
477 |
except HTTPException, err: |
|
478 |
self._SetErrorStatus(err) |
|
479 |
finally: |
|
480 |
# Try to send a response |
|
481 |
self._SendResponse() |
|
482 |
self._Close() |
|
483 |
except SocketClosed: |
|
484 |
pass |
|
485 |
finally: |
|
486 |
logging.info("Disconnected %s:%s", client_addr[0], client_addr[1]) |
|
473 | 487 |
|
474 |
def Close(self): |
|
488 |
def _Close(self):
|
|
475 | 489 |
if not self.wfile.closed: |
476 | 490 |
self.wfile.flush() |
477 | 491 |
self.wfile.close() |
... | ... | |
512 | 526 |
self.response_content_type = self.error_content_type |
513 | 527 |
self.response_body = self.error_message_format % values |
514 | 528 |
|
515 |
def HandleRequest(self): |
|
529 |
def _HandleRequest(self):
|
|
516 | 530 |
"""Handle the actual request. |
517 | 531 |
|
518 | 532 |
Calls the actual handler function and converts exceptions into HTTP errors. |
... | ... | |
549 | 563 |
except HTTPException, err: |
550 | 564 |
self._SetErrorStatus(err) |
551 | 565 |
|
552 |
def SendResponse(self): |
|
566 |
def _SendResponse(self):
|
|
553 | 567 |
"""Sends response to the client. |
554 | 568 |
|
555 | 569 |
""" |
... | ... | |
794 | 808 |
pid = os.fork() |
795 | 809 |
if pid == 0: |
796 | 810 |
# Child process |
797 |
logging.info("Connection from %s:%s", client_addr[0], client_addr[1]) |
|
798 |
|
|
799 | 811 |
try: |
800 |
try: |
|
801 |
try: |
|
802 |
handler = None |
|
803 |
try: |
|
804 |
# Read, parse and handle request |
|
805 |
handler = _HttpConnectionHandler(self, connection, client_addr, |
|
806 |
self._fileio_class) |
|
807 |
handler.HandleRequest() |
|
808 |
finally: |
|
809 |
# Try to send a response |
|
810 |
if handler: |
|
811 |
handler.SendResponse() |
|
812 |
handler.Close() |
|
813 |
except SocketClosed: |
|
814 |
pass |
|
815 |
finally: |
|
816 |
logging.info("Disconnected %s:%s", client_addr[0], client_addr[1]) |
|
812 |
HttpServerRequestExecutor(self, connection, client_addr, |
|
813 |
self._fileio_class) |
|
817 | 814 |
except: |
818 | 815 |
logging.exception("Error while handling request from %s:%s", |
819 | 816 |
client_addr[0], client_addr[1]) |
Also available in: Unified diff