From 422d95a745d9b177da2d68eb815f3cd8ac42f351 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 21 Mar 2017 14:41:37 +0100 Subject: [inc/Download] Properly return final HTTP status code for redirected requests --- inc/download.inc.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'inc/download.inc.php') diff --git a/inc/download.inc.php b/inc/download.inc.php index 51601545..a2054f78 100644 --- a/inc/download.inc.php +++ b/inc/download.inc.php @@ -49,8 +49,8 @@ class Download curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $data = curl_exec($ch); $head = self::getContents($head); - if (preg_match('#^HTTP/\d+\.\d+ (\d+) #', $head, $out)) { - $code = (int) $out[1]; + if (preg_match_all('#^HTTP/\d+\.\d+ (\d+) #m', $head, $out)) { + $code = (int) array_pop($out[1]); } else { $code = 999; } @@ -83,8 +83,8 @@ class Download curl_setopt($ch, CURLOPT_POSTFIELDS, $string); $data = curl_exec($ch); $head = self::getContents($head); - if (preg_match('#^HTTP/\d+\.\d+ (\d+) #', $head, $out)) { - $code = (int) $out[1]; + if (preg_match_all('#^HTTP/\d+\.\d+ (\d+) #m', $head, $out)) { + $code = (int) array_pop($out[1]); } else { $code = 999; } @@ -116,8 +116,8 @@ class Download @unlink($target); return false; } - if (preg_match_all('#\bHTTP/\d+\.\d+ (\d+) #', $head, $out, PREG_SET_ORDER)) { - $code = (int) $out[count($out) - 1][1]; + if (preg_match_all('#^HTTP/\d+\.\d+ (\d+) #m', $head, $out)) { + $code = (int) array_pop($out[1]); } else { $code = '999 ' . curl_error($ch); } -- cgit v1.2.3-55-g7522