~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/HttpServer.py

  • Committer: v.ladeuil+lp at free
  • Date: 2007-02-04 17:41:12 UTC
  • mto: (2323.7.1 redirection)
  • mto: This revision was merged to the branch mainline in revision 2390.
  • Revision ID: v.ladeuil+lp@free.fr-20070204174112-iv6gxzinnjddlaxj
Add tests for redirection. Preserve transport decorations.

* bzrlib/tests/test_http.py:
(TestRedirections): new tests.

* bzrlib/tests/HttpServer.py:
(HttpServer): Make server host and port public once the socket
have been established.

* bzrlib/tests/HTTPTestUtil.py:
(RedirectRequestHandler, HTTPServerRedirecting): New http test
server for redirections. Only a whole host can be redirected, so
far.

* bzrlib/errors.py:
(RedirectRequested.__init__): Add a 'qual_proto' oso that
transport decorations can be transmitted to redirected transport.
(RedirectRequested._requalify_url,
RedirectRequested.get_source_url,
RedirectRequested.get_target_url): New methods providing fully
decorated urls.

* bzrlib/bzrdir.py:
(BzrDir.open_from_transport): The redirection should preserve
transport decorations.
(BzrDirMetaFormat1): To be able to specialize bzr branches from
foreign branches, we need to register BzrDirMetaFormat1 as the
default control format (instead of BzrDirMetaFormat which is
abstract and can still be used by foreign branches).

Show diffs side-by-side

added added

removed removed

Lines of Context:
153
153
            self.end_headers()
154
154
            self.send_range_content(file, start, end - start + 1)
155
155
            self.wfile.write("--%s\r\n" % boundary)
156
 
            pass
157
156
 
158
157
    def do_GET(self):
159
158
        """Serve a GET request.
267
266
    def __init__(self, request_handler=TestingHTTPRequestHandler):
268
267
        Server.__init__(self)
269
268
        self.request_handler = request_handler
 
269
        self.host = 'localhost'
 
270
        self.port = 0
 
271
        self._httpd = None
270
272
 
271
273
    def _get_httpd(self):
272
 
        return TestingHTTPServer(('localhost', 0),
273
 
                                  self.request_handler,
274
 
                                  self)
 
274
        if self._httpd is None:
 
275
            self._httpd = TestingHTTPServer((self.host, self.port),
 
276
                                            self.request_handler,
 
277
                                            self)
 
278
            host, self.port = self._httpd.socket.getsockname()
 
279
        return self._httpd
275
280
 
276
281
    def _http_start(self):
277
 
        httpd = None
278
282
        httpd = self._get_httpd()
279
 
        host, self.port = httpd.socket.getsockname()
280
 
        self._http_base_url = '%s://localhost:%s/' % (self._url_protocol,
281
 
                                                      self.port)
 
283
        self._http_base_url = '%s://%s:%s/' % (self._url_protocol,
 
284
                                               self.host,
 
285
                                               self.port)
282
286
        self._http_starting.release()
283
287
        httpd.socket.settimeout(0.1)
284
288