/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/http_server.py

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2020-08-23 01:15:41 UTC
  • mfrom: (7520.1.4 merge-3.1)
  • Revision ID: breezy.the.bot@gmail.com-20200823011541-nv0oh7nzaganx2qy
Merge lp:brz/3.1.

Merged from https://code.launchpad.net/~jelmer/brz/merge-3.1/+merge/389690

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
import errno
18
 
import httplib
 
18
import http.client as http_client
 
19
import http.server as http_server
19
20
import os
20
21
import posixpath
21
22
import random
22
23
import re
23
 
import select
24
 
import SimpleHTTPServer
25
24
import socket
26
 
import SocketServer
27
25
import sys
28
 
import threading
29
 
import time
30
 
import urllib
31
 
import urlparse
 
26
from urllib.parse import urlparse
32
27
 
33
 
from bzrlib import transport
34
 
from bzrlib.tests import test_server
35
 
from bzrlib.transport import local
 
28
from .. import (
 
29
    osutils,
 
30
    urlutils,
 
31
)
 
32
from . import test_server
36
33
 
37
34
 
38
35
class BadWebserverPath(ValueError):
40
37
        return 'path %s is not in %s' % self.args
41
38
 
42
39
 
43
 
class TestingHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
 
40
class TestingHTTPRequestHandler(http_server.SimpleHTTPRequestHandler):
44
41
    """Handles one request.
45
42
 
46
43
    A TestingHTTPRequestHandler is instantiated for every request received by
52
49
    protocol_version = 'HTTP/1.1'
53
50
 
54
51
    # The Message-like class used to parse the request headers
55
 
    MessageClass = httplib.HTTPMessage
 
52
    MessageClass = http_client.HTTPMessage
56
53
 
57
54
    def setup(self):
58
 
        SimpleHTTPServer.SimpleHTTPRequestHandler.setup(self)
 
55
        http_server.SimpleHTTPRequestHandler.setup(self)
59
56
        self._cwd = self.server._home_dir
60
57
        tcs = self.server.test_case_server
61
58
        if tcs.protocol_version is not None:
78
75
        connection early to avoid polluting the test results.
79
76
        """
80
77
        try:
81
 
            SimpleHTTPServer.SimpleHTTPRequestHandler.handle_one_request(self)
82
 
        except socket.error, e:
 
78
            self._handle_one_request()
 
79
        except socket.error as e:
83
80
            # Any socket error should close the connection, but some errors are
84
81
            # due to the client closing early and we don't want to pollute test
85
82
            # results, so we raise only the others.
89
86
                                     errno.ECONNABORTED, errno.EBADF)):
90
87
                raise
91
88
 
92
 
    _range_regexp = re.compile(r'^(?P<start>\d+)-(?P<end>\d+)$')
 
89
    error_content_type = 'text/plain'
 
90
    error_message_format = '''\
 
91
Error code: %(code)s.
 
92
Message: %(message)s.
 
93
'''
 
94
 
 
95
    def send_error(self, code, message=None):
 
96
        """Send and log an error reply.
 
97
 
 
98
        We redefine the python-provided version to be able to set a
 
99
        ``Content-Length`` header as some http/1.1 clients complain otherwise
 
100
        (see bug #568421).
 
101
 
 
102
        :param code: The HTTP error code.
 
103
 
 
104
        :param message: The explanation of the error code, Defaults to a short
 
105
             entry.
 
106
        """
 
107
 
 
108
        if message is None:
 
109
            try:
 
110
                message = self.responses[code][0]
 
111
            except KeyError:
 
112
                message = '???'
 
113
        self.log_error("code %d, message %s", code, message)
 
114
        content = (self.error_message_format %
 
115
                   {'code': code, 'message': message})
 
116
        self.send_response(code, message)
 
117
        self.send_header("Content-Type", self.error_content_type)
 
118
        self.send_header("Content-Length", "%d" % len(content))
 
119
        self.send_header('Connection', 'close')
 
120
        self.end_headers()
 
121
        if self.command != 'HEAD' and code >= 200 and code not in (204, 304):
 
122
            self.wfile.write(content.encode('utf-8'))
 
123
 
 
124
    def _handle_one_request(self):
 
125
        http_server.SimpleHTTPRequestHandler.handle_one_request(self)
 
126
 
 
127
    _range_regexp = re.compile(r'^(?P<start>\d+)-(?P<end>\d+)?$')
93
128
    _tail_regexp = re.compile(r'^-(?P<tail>\d+)$')
94
129
 
95
 
    def parse_ranges(self, ranges_header):
96
 
        """Parse the range header value and returns ranges and tail.
97
 
 
98
 
        RFC2616 14.35 says that syntactically invalid range
99
 
        specifiers MUST be ignored. In that case, we return 0 for
100
 
        tail and [] for ranges.
 
130
    def _parse_ranges(self, ranges_header, file_size):
 
131
        """Parse the range header value and returns ranges.
 
132
 
 
133
        RFC2616 14.35 says that syntactically invalid range specifiers MUST be
 
134
        ignored. In that case, we return None instead of a range list.
 
135
 
 
136
        :param ranges_header: The 'Range' header value.
 
137
 
 
138
        :param file_size: The size of the requested file.
 
139
 
 
140
        :return: A list of (start, end) tuples or None if some invalid range
 
141
            specifier is encountered.
101
142
        """
102
 
        tail = 0
103
 
        ranges = []
104
143
        if not ranges_header.startswith('bytes='):
105
144
            # Syntactically invalid header
106
 
            return 0, []
 
145
            return None
107
146
 
 
147
        tail = None
 
148
        ranges = []
108
149
        ranges_header = ranges_header[len('bytes='):]
109
150
        for range_str in ranges_header.split(','):
110
 
            # FIXME: RFC2616 says end is optional and default to file_size
111
151
            range_match = self._range_regexp.match(range_str)
112
152
            if range_match is not None:
113
153
                start = int(range_match.group('start'))
114
 
                end = int(range_match.group('end'))
 
154
                end_match = range_match.group('end')
 
155
                if end_match is None:
 
156
                    # RFC2616 says end is optional and default to file_size
 
157
                    end = file_size
 
158
                else:
 
159
                    end = int(end_match)
115
160
                if start > end:
116
161
                    # Syntactically invalid range
117
 
                    return 0, []
 
162
                    return None
118
163
                ranges.append((start, end))
119
164
            else:
120
165
                tail_match = self._tail_regexp.match(range_str)
122
167
                    tail = int(tail_match.group('tail'))
123
168
                else:
124
169
                    # Syntactically invalid range
125
 
                    return 0, []
126
 
        return tail, ranges
 
170
                    return None
 
171
        if tail is not None:
 
172
            # Normalize tail into ranges
 
173
            ranges.append((max(0, file_size - tail), file_size))
 
174
 
 
175
        checked_ranges = []
 
176
        for start, end in ranges:
 
177
            if start >= file_size:
 
178
                # RFC2616 14.35, ranges are invalid if start >= file_size
 
179
                return None
 
180
            # RFC2616 14.35, end values should be truncated
 
181
            # to file_size -1 if they exceed it
 
182
            end = min(end, file_size - 1)
 
183
            checked_ranges.append((start, end))
 
184
        return checked_ranges
127
185
 
128
186
    def _header_line_length(self, keyword, value):
129
187
        header_line = '%s: %s\r\n' % (keyword, value)
130
188
        return len(header_line)
131
189
 
132
 
    def send_head(self):
133
 
        """Overrides base implementation to work around a bug in python2.5."""
134
 
        path = self.translate_path(self.path)
135
 
        if os.path.isdir(path) and not self.path.endswith('/'):
136
 
            # redirect browser - doing basically what apache does when
137
 
            # DirectorySlash option is On which is quite common (braindead, but
138
 
            # common)
139
 
            self.send_response(301)
140
 
            self.send_header("Location", self.path + "/")
141
 
            # Indicates that the body is empty for HTTP/1.1 clients
142
 
            self.send_header('Content-Length', '0')
143
 
            self.end_headers()
144
 
            return None
145
 
 
146
 
        return SimpleHTTPServer.SimpleHTTPRequestHandler.send_head(self)
147
 
 
148
190
    def send_range_content(self, file, start, length):
149
191
        file.seek(start)
150
192
        self.wfile.write(file.read(length))
165
207
    def get_multiple_ranges(self, file, file_size, ranges):
166
208
        self.send_response(206)
167
209
        self.send_header('Accept-Ranges', 'bytes')
168
 
        boundary = '%d' % random.randint(0,0x7FFFFFFF)
 
210
        boundary = '%d' % random.randint(0, 0x7FFFFFFF)
169
211
        self.send_header('Content-Type',
170
212
                         'multipart/byteranges; boundary=%s' % boundary)
171
 
        boundary_line = '--%s\r\n' % boundary
 
213
        boundary_line = b'--%s\r\n' % boundary.encode('ascii')
172
214
        # Calculate the Content-Length
173
215
        content_length = 0
174
216
        for (start, end) in ranges:
177
219
                'Content-type', 'application/octet-stream')
178
220
            content_length += self._header_line_length(
179
221
                'Content-Range', 'bytes %d-%d/%d' % (start, end, file_size))
180
 
            content_length += len('\r\n') # end headers
 
222
            content_length += len('\r\n')  # end headers
181
223
            content_length += end - start + 1
182
224
        content_length += len(boundary_line)
183
225
        self.send_header('Content-length', content_length)
206
248
        ranges_header_value = self.headers.get('Range')
207
249
        if ranges_header_value is None or os.path.isdir(path):
208
250
            # Let the mother class handle most cases
209
 
            return SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET(self)
 
251
            return http_server.SimpleHTTPRequestHandler.do_GET(self)
210
252
 
211
253
        try:
212
254
            # Always read in binary mode. Opening files in text
213
255
            # mode may cause newline translations, making the
214
256
            # actual size of the content transmitted *less* than
215
257
            # the content-length!
216
 
            file = open(path, 'rb')
 
258
            f = open(path, 'rb')
217
259
        except IOError:
218
260
            self.send_error(404, "File not found")
219
261
            return
220
262
 
221
 
        file_size = os.fstat(file.fileno())[6]
222
 
        tail, ranges = self.parse_ranges(ranges_header_value)
223
 
        # Normalize tail into ranges
224
 
        if tail != 0:
225
 
            ranges.append((file_size - tail, file_size))
226
 
 
227
 
        self._satisfiable_ranges = True
228
 
        if len(ranges) == 0:
229
 
            self._satisfiable_ranges = False
230
 
        else:
231
 
            def check_range(range_specifier):
232
 
                start, end = range_specifier
233
 
                # RFC2616 14.35, ranges are invalid if start >= file_size
234
 
                if start >= file_size:
235
 
                    self._satisfiable_ranges = False # Side-effect !
236
 
                    return 0, 0
237
 
                # RFC2616 14.35, end values should be truncated
238
 
                # to file_size -1 if they exceed it
239
 
                end = min(end, file_size - 1)
240
 
                return start, end
241
 
 
242
 
            ranges = map(check_range, ranges)
243
 
 
244
 
        if not self._satisfiable_ranges:
 
263
        file_size = os.fstat(f.fileno())[6]
 
264
        ranges = self._parse_ranges(ranges_header_value, file_size)
 
265
        if not ranges:
245
266
            # RFC2616 14.16 and 14.35 says that when a server
246
267
            # encounters unsatisfiable range specifiers, it
247
268
            # SHOULD return a 416.
248
 
            file.close()
 
269
            f.close()
249
270
            # FIXME: We SHOULD send a Content-Range header too,
250
271
            # but the implementation of send_error does not
251
272
            # allows that. So far.
254
275
 
255
276
        if len(ranges) == 1:
256
277
            (start, end) = ranges[0]
257
 
            self.get_single_range(file, file_size, start, end)
 
278
            self.get_single_range(f, file_size, start, end)
258
279
        else:
259
 
            self.get_multiple_ranges(file, file_size, ranges)
260
 
        file.close()
 
280
            self.get_multiple_ranges(f, file_size, ranges)
 
281
        f.close()
261
282
 
262
283
    def translate_path(self, path):
263
284
        """Translate a /-separated PATH to the local filename syntax.
276
297
            # do beginning with python 2.4.3: abandon query
277
298
            # parameters, scheme, host port, etc (which ensure we
278
299
            # provide the right behaviour on all python versions).
279
 
            path = urlparse.urlparse(path)[2]
 
300
            path = urlparse(path)[2]
280
301
            # And now, we can apply *our* trick to proxy files
281
302
            path += '-proxied'
282
303
 
294
315
        Override from python standard library to stop it calling os.getcwd()
295
316
        """
296
317
        # abandon query parameters
297
 
        path = urlparse.urlparse(path)[2]
298
 
        path = posixpath.normpath(urllib.unquote(path))
299
 
        path = path.decode('utf-8')
 
318
        path = urlparse(path)[2]
 
319
        path = posixpath.normpath(urlutils.unquote(path))
300
320
        words = path.split('/')
301
 
        words = filter(None, words)
302
321
        path = self._cwd
303
 
        for num, word in enumerate(words):
 
322
        for num, word in enumerate(w for w in words if w):
304
323
            if num == 0:
305
324
                drive, word = os.path.splitdrive(word)
306
325
            head, word = os.path.split(word)
307
 
            if word in (os.curdir, os.pardir): continue
 
326
            if word in (os.curdir, os.pardir):
 
327
                continue
308
328
            path = os.path.join(path, word)
309
329
        return path
310
330
 
319
339
        self.test_case_server = test_case_server
320
340
        self._home_dir = test_case_server._home_dir
321
341
 
322
 
    def stop_server(self):
323
 
         """Called to clean-up the server.
324
 
 
325
 
         Since the server may be (surely is, even) in a blocking listen, we
326
 
         shutdown its socket before closing it.
327
 
         """
328
 
         # Note that is this executed as part of the implicit tear down in the
329
 
         # main thread while the server runs in its own thread. The clean way
330
 
         # to tear down the server is to instruct him to stop accepting
331
 
         # connections and wait for the current connection(s) to end
332
 
         # naturally. To end the connection naturally, the http transports
333
 
         # should close their socket when they do not need to talk to the
334
 
         # server anymore. This happens naturally during the garbage collection
335
 
         # phase of the test transport objetcs (the server clients), so we
336
 
         # don't have to worry about them.  So, for the server, we must tear
337
 
         # down here, from the main thread, when the test have ended.  Note
338
 
         # that since the server is in a blocking operation and since python
339
 
         # use select internally, shutting down the socket is reliable and
340
 
         # relatively clean.
341
 
         try:
342
 
             self.socket.shutdown(socket.SHUT_RDWR)
343
 
         except socket.error, e:
344
 
             # WSAENOTCONN (10057) 'Socket is not connected' is harmless on
345
 
             # windows (occurs before the first connection attempt
346
 
             # vila--20071230)
347
 
 
348
 
             # 'Socket is not connected' can also occur on OSX, with a
349
 
             # "regular" ENOTCONN (when something went wrong during test case
350
 
             # setup leading to self.setUp() *not* being called but
351
 
             # self.stop_server() still being called -- vila20081106
352
 
             if not len(e.args) or e.args[0] not in (errno.ENOTCONN, 10057):
353
 
                 raise
354
 
         # Let the server properly close the socket
355
 
         self.server_close()
356
 
 
357
 
 
358
 
class TestingHTTPServer(SocketServer.TCPServer, TestingHTTPServerMixin):
 
342
 
 
343
class TestingHTTPServer(test_server.TestingTCPServer, TestingHTTPServerMixin):
359
344
 
360
345
    def __init__(self, server_address, request_handler_class,
361
346
                 test_case_server):
 
347
        test_server.TestingTCPServer.__init__(self, server_address,
 
348
                                              request_handler_class)
362
349
        TestingHTTPServerMixin.__init__(self, test_case_server)
363
 
        SocketServer.TCPServer.__init__(self, server_address,
364
 
                                        request_handler_class)
365
 
 
366
 
 
367
 
class TestingThreadingHTTPServer(SocketServer.ThreadingTCPServer,
 
350
 
 
351
 
 
352
class TestingThreadingHTTPServer(test_server.TestingThreadingTCPServer,
368
353
                                 TestingHTTPServerMixin):
369
354
    """A threading HTTP test server for HTTP 1.1.
370
355
 
375
360
 
376
361
    def __init__(self, server_address, request_handler_class,
377
362
                 test_case_server):
 
363
        test_server.TestingThreadingTCPServer.__init__(self, server_address,
 
364
                                                       request_handler_class)
378
365
        TestingHTTPServerMixin.__init__(self, test_case_server)
379
 
        SocketServer.ThreadingTCPServer.__init__(self, server_address,
380
 
                                                 request_handler_class)
381
 
        # Decides how threads will act upon termination of the main
382
 
        # process. This is prophylactic as we should not leave the threads
383
 
        # lying around.
384
 
        self.daemon_threads = True
385
 
 
386
 
    def process_request_thread(self, request, client_address):
387
 
        SocketServer.ThreadingTCPServer.process_request_thread(
388
 
            self, request, client_address)
389
 
        # Under some circumstances (as in bug #383920), we need to force the
390
 
        # shutdown as python delays it until gc occur otherwise and the client
391
 
        # may hang.
392
 
        try:
393
 
            # The request process has been completed, the thread is about to
394
 
            # die, let's shutdown the socket if we can.
395
 
            request.shutdown(socket.SHUT_RDWR)
396
 
        except (socket.error, select.error), e:
397
 
            if e[0] in (errno.EBADF, errno.ENOTCONN):
398
 
                # Right, the socket is already down
399
 
                pass
400
 
            else:
401
 
                raise
402
 
 
403
 
 
404
 
class HttpServer(transport.Server):
 
366
 
 
367
 
 
368
class HttpServer(test_server.TestingTCPServerInAThread):
405
369
    """A test server for http transports.
406
370
 
407
371
    Subclasses can provide a specific request handler.
429
393
        :param protocol_version: if specified, will override the protocol
430
394
            version of the request handler.
431
395
        """
432
 
        transport.Server.__init__(self)
433
 
        self.request_handler = request_handler
 
396
        # Depending on the protocol version, we will create the approriate
 
397
        # server
 
398
        if protocol_version is None:
 
399
            # Use the request handler one
 
400
            proto_vers = request_handler.protocol_version
 
401
        else:
 
402
            # Use our own, it will be used to override the request handler
 
403
            # one too.
 
404
            proto_vers = protocol_version
 
405
        # Get the appropriate server class for the required protocol
 
406
        serv_cls = self.http_server_class.get(proto_vers, None)
 
407
        if serv_cls is None:
 
408
            raise http_client.UnknownProtocol(proto_vers)
434
409
        self.host = 'localhost'
435
410
        self.port = 0
436
 
        self._httpd = None
437
 
        self.protocol_version = protocol_version
 
411
        super(HttpServer, self).__init__((self.host, self.port),
 
412
                                         serv_cls,
 
413
                                         request_handler)
 
414
        self.protocol_version = proto_vers
438
415
        # Allows tests to verify number of GET requests issued
439
416
        self.GET_request_nb = 0
440
 
 
441
 
    def create_httpd(self, serv_cls, rhandler_cls):
442
 
        return serv_cls((self.host, self.port), self.request_handler, self)
443
 
 
444
 
    def __repr__(self):
445
 
        return "%s(%s:%s)" % \
446
 
            (self.__class__.__name__, self.host, self.port)
447
 
 
448
 
    def _get_httpd(self):
449
 
        if self._httpd is None:
450
 
            rhandler = self.request_handler
451
 
            # Depending on the protocol version, we will create the approriate
452
 
            # server
453
 
            if self.protocol_version is None:
454
 
                # Use the request handler one
455
 
                proto_vers = rhandler.protocol_version
456
 
            else:
457
 
                # Use our own, it will be used to override the request handler
458
 
                # one too.
459
 
                proto_vers = self.protocol_version
460
 
            # Create the appropriate server for the required protocol
461
 
            serv_cls = self.http_server_class.get(proto_vers, None)
462
 
            if serv_cls is None:
463
 
                raise httplib.UnknownProtocol(proto_vers)
464
 
            else:
465
 
                self._httpd = self.create_httpd(serv_cls, rhandler)
466
 
            self.host, self.port = self._httpd.socket.getsockname()
467
 
        return self._httpd
468
 
 
469
 
    def _http_start(self):
470
 
        """Server thread main entry point. """
471
 
        self._http_running = False
472
 
        try:
473
 
            try:
474
 
                httpd = self._get_httpd()
475
 
                self._http_base_url = '%s://%s:%s/' % (self._url_protocol,
476
 
                                                       self.host, self.port)
477
 
                self._http_running = True
478
 
            except:
479
 
                # Whatever goes wrong, we save the exception for the main
480
 
                # thread. Note that since we are running in a thread, no signal
481
 
                # can be received, so we don't care about KeyboardInterrupt.
482
 
                self._http_exception = sys.exc_info()
483
 
        finally:
484
 
            # Release the lock or the main thread will block and the whole
485
 
            # process will hang.
486
 
            self._http_starting.release()
487
 
 
488
 
        # From now on, exceptions are taken care of by the
489
 
        # SocketServer.BaseServer or the request handler.
490
 
        while self._http_running:
491
 
            try:
492
 
                # Really an HTTP connection but the python framework is generic
493
 
                # and call them requests
494
 
                httpd.handle_request()
495
 
            except socket.timeout:
496
 
                pass
497
 
            except (socket.error, select.error), e:
498
 
                if (e[0] == errno.EBADF
499
 
                    or (sys.platform == 'win32' and e[0] == 10038)):
500
 
                    # Starting with python-2.6, handle_request may raise socket
501
 
                    # or select exceptions when the server is shut down (as we
502
 
                    # do).
503
 
                    # 10038 = WSAENOTSOCK
504
 
                    # http://msdn.microsoft.com/en-us/library/ms740668%28VS.85%29.aspx
505
 
                    pass
506
 
                else:
507
 
                    raise
 
417
        self._http_base_url = None
 
418
        self.logs = []
 
419
 
 
420
    def create_server(self):
 
421
        return self.server_class(
 
422
            (self.host, self.port), self.request_handler_class, self)
508
423
 
509
424
    def _get_remote_url(self, path):
510
425
        path_parts = path.split(os.path.sep)
511
426
        if os.path.isabs(path):
512
427
            if path_parts[:len(self._local_path_parts)] != \
513
 
                   self._local_path_parts:
 
428
                    self._local_path_parts:
514
429
                raise BadWebserverPath(path, self.test_dir)
515
430
            remote_path = '/'.join(path_parts[len(self._local_path_parts):])
516
431
        else:
523
438
        self.logs.append(format % args)
524
439
 
525
440
    def start_server(self, backing_transport_server=None):
526
 
        """See bzrlib.transport.Server.start_server.
 
441
        """See breezy.transport.Server.start_server.
527
442
 
528
443
        :param backing_transport_server: The transport that requests over this
529
444
            protocol should be forwarded to. Note that this is currently not
535
450
                or isinstance(backing_transport_server,
536
451
                              test_server.LocalURLServer)):
537
452
            raise AssertionError(
538
 
                "HTTPServer currently assumes local transport, got %s" % \
 
453
                "HTTPServer currently assumes local transport, got %s" %
539
454
                backing_transport_server)
540
 
        self._home_dir = os.getcwdu()
 
455
        self._home_dir = osutils.getcwd()
541
456
        self._local_path_parts = self._home_dir.split(os.path.sep)
542
 
        self._http_base_url = None
543
 
 
544
 
        # Create the server thread
545
 
        self._http_starting = threading.Lock()
546
 
        self._http_starting.acquire()
547
 
        self._http_thread = threading.Thread(target=self._http_start)
548
 
        self._http_thread.setDaemon(True)
549
 
        self._http_exception = None
550
 
        self._http_thread.start()
551
 
 
552
 
        # Wait for the server thread to start (i.e release the lock)
553
 
        self._http_starting.acquire()
554
 
 
555
 
        if self._http_exception is not None:
556
 
            # Something went wrong during server start
557
 
            exc_class, exc_value, exc_tb = self._http_exception
558
 
            raise exc_class, exc_value, exc_tb
559
 
        self._http_starting.release()
560
457
        self.logs = []
561
458
 
562
 
    def stop_server(self):
563
 
        self._httpd.stop_server()
564
 
        self._http_running = False
565
 
        # We don't need to 'self._http_thread.join()' here since the thread is
566
 
        # a daemonic one and will be garbage collected anyway. Joining just
567
 
        # slows us down for no added benefit.
 
459
        super(HttpServer, self).start_server()
 
460
        self._http_base_url = '%s://%s:%s/' % (
 
461
            self._url_protocol, self.host, self.port)
568
462
 
569
463
    def get_url(self):
570
 
        """See bzrlib.transport.Server.get_url."""
 
464
        """See breezy.transport.Server.get_url."""
571
465
        return self._get_remote_url(self._home_dir)
572
466
 
573
467
    def get_bogus_url(self):
574
 
        """See bzrlib.transport.Server.get_bogus_url."""
 
468
        """See breezy.transport.Server.get_bogus_url."""
575
469
        # this is chosen to try to prevent trouble with proxies, weird dns,
576
470
        # etc
577
471
        return self._url_protocol + '://127.0.0.1:1/'
578
 
 
579
 
 
580
 
class HttpServer_urllib(HttpServer):
581
 
    """Subclass of HttpServer that gives http+urllib urls.
582
 
 
583
 
    This is for use in testing: connections to this server will always go
584
 
    through urllib where possible.
585
 
    """
586
 
 
587
 
    # urls returned by this server should require the urllib client impl
588
 
    _url_protocol = 'http+urllib'
589
 
 
590
 
 
591
 
class HttpServer_PyCurl(HttpServer):
592
 
    """Subclass of HttpServer that gives http+pycurl urls.
593
 
 
594
 
    This is for use in testing: connections to this server will always go
595
 
    through pycurl where possible.
596
 
    """
597
 
 
598
 
    # We don't care about checking the pycurl availability as
599
 
    # this server will be required only when pycurl is present
600
 
 
601
 
    # urls returned by this server should require the pycurl client impl
602
 
    _url_protocol = 'http+pycurl'