|
29 | 29 | except ImportError: |
30 | 30 | SSL = None |
31 | 31 |
|
32 | | -from time import sleep |
33 | | - |
34 | 32 | # python version check |
35 | 33 | from roundup import configuration, version_check |
36 | 34 | from roundup import __version__ as roundup_version |
|
76 | 74 |
|
77 | 75 | def auto_ssl(): |
78 | 76 | print _('WARNING: generating temporary SSL certificate') |
79 | | - import OpenSSL, time, random, sys |
| 77 | + import OpenSSL, random |
80 | 78 | pkey = OpenSSL.crypto.PKey() |
81 | 79 | pkey.generate_key(OpenSSL.crypto.TYPE_RSA, 768) |
82 | 80 | cert = OpenSSL.crypto.X509() |
@@ -128,15 +126,15 @@ def readline(self, *args): |
128 | 126 | try: |
129 | 127 | return self.__fileobj.readline(*args) |
130 | 128 | except SSL.WantReadError: |
131 | | - sleep (.1) |
| 129 | + time.sleep(.1) |
132 | 130 |
|
133 | 131 | def read(self, *args): |
134 | 132 | """ SSL.Connection can return WantRead """ |
135 | 133 | while True: |
136 | 134 | try: |
137 | 135 | return self.__fileobj.read(*args) |
138 | 136 | except SSL.WantReadError: |
139 | | - sleep (.1) |
| 137 | + time.sleep(.1) |
140 | 138 |
|
141 | 139 | def __getattr__(self, attrib): |
142 | 140 | return getattr(self.__fileobj, attrib) |
@@ -590,6 +588,20 @@ class RequestHandler(RoundupRequestHandler): |
590 | 588 | DEBUG_MODE = self["MULTIPROCESS"] == "debug" |
591 | 589 | CONFIG = self |
592 | 590 |
|
| 591 | + def setup(self): |
| 592 | + if self.CONFIG["SSL"]: |
| 593 | + # perform initial ssl handshake. This will set |
| 594 | + # internal state correctly so that later closing SSL |
| 595 | + # socket works (with SSL end-handshake started) |
| 596 | + self.request.do_handshake() |
| 597 | + RoundupRequestHandler.setup(self) |
| 598 | + |
| 599 | + def finish(self): |
| 600 | + RoundupRequestHandler.finish(self) |
| 601 | + if self.CONFIG["SSL"]: |
| 602 | + self.request.shutdown() |
| 603 | + self.request.close() |
| 604 | + |
593 | 605 | if self["SSL"]: |
594 | 606 | base_server = SecureHTTPServer |
595 | 607 | else: |
|
0 commit comments