At 20:12 2002-06-14 +0100, John J. Lee wrote:
>BTW, I presume that, unlike me, you read the RFC properly and noticed that
>the various 30x responses have to be treated differently?  Not all POSTs
>should be redirected on all 30x's.  Pretty obvious I know: why else would
>there be more than one value of x, but I managed to miss it.

My code is below... but it's just something temporary that I cobbled
together for the time being. I didn't (yet) implement it according to
the RFC. At the moment, I only dimly remember what's in the RFC, but I
do remember that the RFC is half the problem: the RFC says to not
auto-redirect POST (among other things), but everyone expects redirects
to always be honored anyway.

Anyhow, for whatever it's worth:

sub redirect_ok
{
    # RFC 2068, section 10.3.2 and 10.3.3 say:
    #  If the 30[12] status code is received in response to a request other
    #  than GET or HEAD, the user agent MUST NOT automatically redirect the
    #  request unless it can be confirmed by the user, since this might
    #  change the conditions under which the request was issued.

    # Note that this routine used to be just:
    #  return 0 if $_[1]->method eq "POST";  return 1;

    my($self, $request) = @_;
    my $method = $request->method;

    LWP::Debug::trace("Considering redirection of a $method request...");

    return 0 unless grep $_ eq $method,
      @{ $self->requests_redirectable || [] };
    
    if($request->url->scheme eq 'file') {
      LWP::Debug::trace("Can't redirect to a file:// URL!");
      return 0;
    }

    if($self->{'_post_redirect_as_get'} and $request->method eq 'POST') {
      LWP::Debug::trace("Turning $request from POST to a contentless GET");
      $request->method('GET');
      $request->content('');
    }

    # Otherwise it's apparently okay...
    return 1;
}

--
Sean M. Burke    http://www.spinn.net/~sburke/

Reply via email to