From 451314eb48c7d922264adc6eada8a0273b12344c Mon Sep 17 00:00:00 2001 From: VirtualTam Date: Tue, 1 Sep 2015 21:45:06 +0200 Subject: HTTP: move utils to a proper file, add tests Relates to #333 Modifications: - move HTTP utils to 'application/HttpUtils.php' - simplify logic - replace 'http_parse_headers_shaarli' by built-in 'get_headers()' - remove superfluous '$status' parameter (provided by the HTTP headers) - apply coding conventions - add test coverage (unitary only) Signed-off-by: VirtualTam --- application/HttpUtils.php | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 application/HttpUtils.php (limited to 'application') diff --git a/application/HttpUtils.php b/application/HttpUtils.php new file mode 100644 index 00000000..175333ae --- /dev/null +++ b/application/HttpUtils.php @@ -0,0 +1,52 @@ + array( + 'method' => 'GET', + 'timeout' => $timeout, + 'user_agent' => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:23.0)' + .' Gecko/20100101 Firefox/23.0' + ) + ); + + $context = stream_context_create($options); + + try { + // TODO: catch Exception in calling code (thumbnailer) + $content = file_get_contents($url, false, $context, -1, $maxBytes); + } catch (Exception $exc) { + return array(array(0 => 'HTTP Error'), $exc->getMessage()); + } + + if (!$content) { + return array(array(0 => 'HTTP Error'), ''); + } + + return array(get_headers($url, 1), $content); +} -- cgit v1.2.3