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