Show More
@@ -33,10 +33,15 class _error_logger(object): | |||
|
33 | 33 | for msg in seq: |
|
34 | 34 | self.handler.log_error("HG error: %s", msg) |
|
35 | 35 | |
|
36 |
class _h |
|
|
36 | class _httprequesthandler(BaseHTTPServer.BaseHTTPRequestHandler): | |
|
37 | 37 | |
|
38 | 38 | url_scheme = 'http' |
|
39 | 39 | |
|
40 | @staticmethod | |
|
41 | def preparehttpserver(httpserver, ssl_cert): | |
|
42 | """Prepare .socket of new HTTPServer instance""" | |
|
43 | pass | |
|
44 | ||
|
40 | 45 | def __init__(self, *args, **kargs): |
|
41 | 46 | self.protocol_version = 'HTTP/1.1' |
|
42 | 47 | BaseHTTPServer.BaseHTTPRequestHandler.__init__(self, *args, **kargs) |
@@ -168,28 +173,44 class _hgwebhandler(BaseHTTPServer.BaseH | |||
|
168 | 173 | self.wfile.write(data) |
|
169 | 174 | self.wfile.flush() |
|
170 | 175 | |
|
171 |
class _ |
|
|
176 | class _httprequesthandleropenssl(_httprequesthandler): | |
|
177 | """HTTPS handler based on pyOpenSSL""" | |
|
172 | 178 | |
|
173 | 179 | url_scheme = 'https' |
|
174 | 180 | |
|
181 | @staticmethod | |
|
182 | def preparehttpserver(httpserver, ssl_cert): | |
|
183 | try: | |
|
184 | import OpenSSL | |
|
185 | OpenSSL.SSL.Context | |
|
186 | except ImportError: | |
|
187 | raise util.Abort(_("SSL support is unavailable")) | |
|
188 | ctx = OpenSSL.SSL.Context(OpenSSL.SSL.SSLv23_METHOD) | |
|
189 | ctx.use_privatekey_file(ssl_cert) | |
|
190 | ctx.use_certificate_file(ssl_cert) | |
|
191 | sock = socket.socket(httpserver.address_family, httpserver.socket_type) | |
|
192 | httpserver.socket = OpenSSL.SSL.Connection(ctx, sock) | |
|
193 | httpserver.server_bind() | |
|
194 | httpserver.server_activate() | |
|
195 | ||
|
175 | 196 | def setup(self): |
|
176 | 197 | self.connection = self.request |
|
177 | 198 | self.rfile = socket._fileobject(self.request, "rb", self.rbufsize) |
|
178 | 199 | self.wfile = socket._fileobject(self.request, "wb", self.wbufsize) |
|
179 | 200 | |
|
180 | 201 | def do_write(self): |
|
181 | from OpenSSL.SSL import SysCallError | |
|
202 | import OpenSSL | |
|
182 | 203 | try: |
|
183 |
_h |
|
|
184 | except SysCallError, inst: | |
|
204 | _httprequesthandler.do_write(self) | |
|
205 | except OpenSSL.SSL.SysCallError, inst: | |
|
185 | 206 | if inst.args[0] != errno.EPIPE: |
|
186 | 207 | raise |
|
187 | 208 | |
|
188 | 209 | def handle_one_request(self): |
|
189 | from OpenSSL.SSL import SysCallError, ZeroReturnError | |
|
210 | import OpenSSL | |
|
190 | 211 | try: |
|
191 |
_h |
|
|
192 | except (SysCallError, ZeroReturnError): | |
|
212 | _httprequesthandler.handle_one_request(self) | |
|
213 | except (OpenSSL.SSL.SysCallError, OpenSSL.SSL.ZeroReturnError): | |
|
193 | 214 | self.close_connection = True |
|
194 | 215 | pass |
|
195 | 216 | |
@@ -219,19 +240,7 class MercurialHTTPServer(object, _mixin | |||
|
219 | 240 | self.daemon_threads = True |
|
220 | 241 | self.application = app |
|
221 | 242 | |
|
222 |
|
|
|
223 | if ssl_cert: | |
|
224 | try: | |
|
225 | from OpenSSL import SSL | |
|
226 | ctx = SSL.Context(SSL.SSLv23_METHOD) | |
|
227 | except ImportError: | |
|
228 | raise util.Abort(_("SSL support is unavailable")) | |
|
229 | ctx.use_privatekey_file(ssl_cert) | |
|
230 | ctx.use_certificate_file(ssl_cert) | |
|
231 | sock = socket.socket(self.address_family, self.socket_type) | |
|
232 | self.socket = SSL.Connection(ctx, sock) | |
|
233 | self.server_bind() | |
|
234 | self.server_activate() | |
|
243 | handler.preparehttpserver(self, ui.config('web', 'certificate')) | |
|
235 | 244 | |
|
236 | 245 | prefix = ui.config('web', 'prefix', '') |
|
237 | 246 | if prefix: |
@@ -256,9 +265,9 class IPv6HTTPServer(MercurialHTTPServer | |||
|
256 | 265 | def create_server(ui, app): |
|
257 | 266 | |
|
258 | 267 | if ui.config('web', 'certificate'): |
|
259 |
handler = _ |
|
|
268 | handler = _httprequesthandleropenssl | |
|
260 | 269 | else: |
|
261 |
handler = _h |
|
|
270 | handler = _httprequesthandler | |
|
262 | 271 | |
|
263 | 272 | if ui.configbool('web', 'ipv6'): |
|
264 | 273 | cls = IPv6HTTPServer |
General Comments 0
You need to be logged in to leave comments.
Login now