Mercurial > SimpleWebPresenter
changeset 132:51b53cd01080
Handle redirects properly.
| author | Tom Fredrik Blenning <bfg@bfgconsult.no> |
|---|---|
| date | Sun, 22 Jan 2023 18:59:03 +0100 |
| parents | 6b882fb6ea46 |
| children | 00255ca89459 |
| files | Http.inc |
| diffstat | 1 files changed, 13 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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; }
