[rfc] Handling redirects properly.

Martin Pool mbp at canonical.com
Thu Jul 20 23:56:14 BST 2006


On 20 Jul 2006, John Arbash Meinel <john at arbash-meinel.com> wrote:
> > If we get a redirection at some later point the error will be uncaught
> > and terminate bzr.  We don't really expect to get redirections, but
> > still it would seem nice if the default behaviour is to just follow
> > them.
> 
> I think we could enable direct redirect handling for everything but the
> when we know that we will catch the exception.

Yep.

> I think the easiest way to retain the most functionality, while still
> being nice for http redirects is to update 'Transport.get()' so that it
> can take a 'follow_redirects' parameter, which would default to True.
> The api can be defined so that it is a hint, rather than a required command.
> 
> And then for HTTP if that flag is set, it follows just like it does now.
> And the only caller who sets it to false is
> BzrDir.open/open_containing_from_transport

That sounds good.

> Now for handling the full url issue for redirects I was thinking to do:
> 
> try:
>   find_format(a_transport)
> except RedirectRequested, e:
>   relpath = a_transport.relpath(e.old_url)
>   assert e.new_url.endswith(relpath)
>   new_base_url = e.new_url[:-len(relpath)]
> 
> I'll have to see if all my indexes are right. But that is the basic idea.

That sounds fine too.

What I was suggesting is that this idea of "fetch this file, and if it
redirects adjust the url" can usefully be separated from opening the
branch.

> Now, instead of doing the assert, we *could* just retry the request with
> 'follow_redirects=True', and just keep trying. However, if someone is
> redirecting '.bzr/branch-format' to 'index.html', we have a serious
> error. I would rather raise some sort of InvalidRedirectRequested.

OK, so not actually an assert but rather if/raise.  I agree.

> People seem generally positive about my idea, so I'll probably look into
> doing it.

I am for one.

-- 
Martin




More information about the bazaar mailing list