[rfc] Handling redirects properly.

John Arbash Meinel john at arbash-meinel.com
Wed Jul 19 18:24:46 BST 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I just wanted to bring up the idea of how we could handle redirects
inside bzrlib, such that they work better with the real world.

This is discussed a little in this bug
https://launchpad.net/products/bzr/+bug/36004

Basically, http transport is currently silently redirecting. Which means
you have to redirect all files that belong to a given branch. What is
probably better, would be to handle an initial redirect, and then make
all new requests to the new URL, and probably alert the user while we
are at it.

I *think* the best way to handle this would be to add a new exception
RedirectRequested(old_url, new_url, is_permanent=True)

Then rather than following redirects, the Http transports can raise this
exception when they get a redirect request.

This exception can be caught in a higher level, the user alerted, and
then the request repeated with the new url.

I believe the best place to catch the exception would be in
BzrDir.open_containing_from_transport().

Basically, we would have something like:

try:
  format = BzrDirFormat.find_format(a_transport)

  ...
except RedirectRequested, e:
  note('URL %s has been redirected to %s', e.old_url, e.new_url)
  a_transport = get_transport(e.new_url)

I think this puts the functionality right about where we want it. So
that when we go to open a new branch, we get redirected to the correct
location.

I suppose we could also have the try/except in BzrDir.open() around the
find_format call there.

It would also be possible to handle the redirect inside find_format(),
but then we need to update the find_format api so that it can return the
real transport.

Thoughts?

John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFEvmrdJdeBCYSNAAMRAsh/AKCH10acdbLnb+sCmxxqOetV05goXwCgr3pQ
0u5g4qjQDRITnblqXVMsB14=
=1v2o
-----END PGP SIGNATURE-----




More information about the bazaar mailing list