Mercurial > SimpleWebPresenter
comparison Http.inc @ 132:51b53cd01080
Handle redirects properly.
| author | Tom Fredrik Blenning <bfg@bfgconsult.no> |
|---|---|
| date | Sun, 22 Jan 2023 18:59:03 +0100 |
| parents | 111770d32c2e |
| children |
comparison
equal
deleted
inserted
replaced
| 131:6b882fb6ea46 | 132:51b53cd01080 |
|---|---|
| 107 } | 107 } |
| 108 elseif (true) { | 108 elseif (true) { |
| 109 $rp = get_headers($url); | 109 $rp = get_headers($url); |
| 110 $response=array('' => array_shift ($rp)); | 110 $response=array('' => array_shift ($rp)); |
| 111 foreach($rp as $kv) { | 111 foreach($rp as $kv) { |
| 112 $tmp=array_map('trim', explode(':', $kv, 2)); | 112 if (!str_contains($kv, ':')) { |
| 113 $response[$tmp[0]]=$tmp[1]; | 113 if (!preg_match("/^HTTP\/\S+\s(\d+)/", $response[''], $re)) { |
| 114 throw new Exception('Uninteligble header'); | |
| 115 } | |
| 116 //FIXME: We should do something with this, | |
| 117 //but now we just assume we have a redirect | |
| 118 $retCode=intval($re[1]); | |
| 119 $response=array('' => $kv); | |
| 120 } | |
| 121 else { | |
| 122 $tmp=array_map('trim', explode(':', $kv, 2)); | |
| 123 $response[$tmp[0]]=$tmp[1]; | |
| 124 } | |
| 114 } | 125 } |
| 115 return $response; | 126 return $response; |
| 116 } | 127 } |
| 117 else { | 128 else { |
| 118 return array('' => 'HTTP/1.1 200 OK'); | 129 return array('' => 'HTTP/1.1 200 OK'); |
