/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 bzrlib/tests/http_server.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-02-11 04:02:41 UTC
  • mfrom: (5017.2.2 tariff)
  • Revision ID: pqm@pqm.ubuntu.com-20100211040241-w6n021dz0uus341n
(mbp) add import-tariff tests

Show diffs side-by-side

added added

removed removed

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