Subject: | redirect method returns malformed HTTP ("Moved" should be "Found") |
Section 6.1 of the HTTP 1.1 specification states:
The first line of a Response message is the Status-Line,
consisting of the protocol version followed by a numeric
status code and its associated textual phrase.
When calling the redirect method of CGI.pm (including the latest
version, 3.15, from CPAN) on perl 5.8.7 on Linux 2.6.14-gentoo-r5 with:
perl -MCGI -e'print CGI->redirect("http://example.com")'
The output is:
Status: 302 Moved
Location: http://example.com
"Moved" is the textual phrase associated with the 301 status code. The
text for 302 should be "Found".
This error can be corrected by modifying line 1502 of version 3.15. I've
attached a patch generated with:
diff -U 8 -p CGI.pm CGI-dd.pm > CGI.pm-redirect.patch
Subject: | CGI.pm-redirect.patch |
--- CGI.pm 2006-01-14 12:26:20.000000000 +0000
+++ CGI-dd.pm 2006-01-14 12:26:47.000000000 +0000
@@ -1494,17 +1494,17 @@ END_OF_FUNC
# Return a Location: style header
#
####
'redirect' => <<'END_OF_FUNC',
sub redirect {
my($self,@p) = self_or_default(@_);
my($url,$target,$status,$cookie,$nph,@other) =
rearrange([[LOCATION,URI,URL],TARGET,STATUS,['COOKIE','COOKIES'],NPH],@p);
- $status = '302 Moved' unless defined $status;
+ $status = '302 Found' unless defined $status;
$url ||= $self->self_url;
my(@o);
foreach (@other) { tr/\"//d; push(@o,split("=",$_,2)); }
unshift(@o,
'-Status' => $status,
'-Location'=> $url,
'-nph' => $nph);
unshift(@o,'-Target'=>$target) if $target;