# HG changeset patch # User Tom Fredrik Blenning # Date 1674410343 -3600 # Node ID 51b53cd01080f75ac086842947be4760790fbfcd # Parent 6b882fb6ea46934fceb76c509756aae8bc87086a Handle redirects properly. diff -r 6b882fb6ea46 -r 51b53cd01080 Http.inc --- a/Http.inc Sat Jan 21 16:43:41 2023 +0100 +++ b/Http.inc Sun Jan 22 18:59:03 2023 +0100 @@ -109,8 +109,19 @@ $rp = get_headers($url); $response=array('' => array_shift ($rp)); foreach($rp as $kv) { - $tmp=array_map('trim', explode(':', $kv, 2)); - $response[$tmp[0]]=$tmp[1]; + if (!str_contains($kv, ':')) { + if (!preg_match("/^HTTP\/\S+\s(\d+)/", $response[''], $re)) { + throw new Exception('Uninteligble header'); + } + //FIXME: We should do something with this, + //but now we just assume we have a redirect + $retCode=intval($re[1]); + $response=array('' => $kv); + } + else { + $tmp=array_map('trim', explode(':', $kv, 2)); + $response[$tmp[0]]=$tmp[1]; + } } return $response; }