Mailinglist Archive: opensuse-buildservice (233 mails)

< Previous Next >
Re: [opensuse-buildservice] BSRPC: support redirects
  • From: Marcus Hüwe <suse-tux@xxxxxx>
  • Date: Sun, 14 Dec 2008 00:17:21 +0100
  • Message-id: <20081213231721.GI3175@xxxxxxxxxxxxxxxxxxx>
On 2008-12-13 23:31:11 +0100, Michal Marek wrote:
Marcus Hüwe napsal(a):
Index: BSRPC.pm
===================================================================
--- BSRPC.pm (Revision 5877)
+++ BSRPC.pm (Arbeitskopie)
@@ -225,14 +225,20 @@
}
my %headers;
BSHTTP::gethead(\%headers, $headers);
- if ($status !~ /^200[^\d]/) {
+ if ($status =~ /^200[^\d]/) {
+ undef $status;
+ } elsif ($status =~ /^302[^\d]/) {
+ # XXX: should we do the redirect if $param->{'ignorestatus'} is
defined?
+ close S;
+ die("status 302 but no 'location' header found\n") unless exists
$headers{'location'};
+ $param->{'uri'} = $headers{'location'};
+ return rpc($param, $xmlargs, @args);

Shouldn't there be an upper limit on the number of redirects?

Arghs - thanks for the hint. Here's the new version.


Marcus
Index: BSRPC.pm
===================================================================
--- BSRPC.pm (Revision 5877)
+++ BSRPC.pm (Arbeitskopie)
@@ -73,6 +73,7 @@
# receiver
# ignorestatus
# replydtd
+# maxredirects
#

sub rpc {
@@ -225,14 +226,22 @@
}
my %headers;
BSHTTP::gethead(\%headers, $headers);
- if ($status !~ /^200[^\d]/) {
+ if ($status =~ /^200[^\d]/) {
+ undef $status;
+ } elsif ($status =~ /^302[^\d]/) {
+ # XXX: should we do the redirect if $param->{'ignorestatus'} is defined?
+ close S;
+ die("error: status 302 but no 'location' header found\n") unless exists
$headers{'location'};
+ $param->{'uri'} = $headers{'location'};
+ $param->{'maxredirects'} = exists $param->{'maxredirects'} ?
--$param->{'maxredirects'} : 3;
+ die("error: max number of redirects reached\n") if
$param->{'maxredirects'} < 0;
+ return rpc($param, $xmlargs, @args);
+ } else {
#if ($param->{'verbose'}) {
# 1 while sysread(S, $ans, 1024, length($ans));
# print "< $ans\n";
#}
die("remote error: $status\n") unless $param->{'ignorestatus'};
- } else {
- undef $status;
}
if ($headers{'set-cookie'} && $param->{'uri'}) {
my @cookie = split(',', $headers{'set-cookie'});
< Previous Next >