[BUGFIX] Use correct HTTP method in GeneralUtility::getUrl 88/57488/2
authorMarkus Klein <markus.klein@typo3.org>
Thu, 5 Jul 2018 20:26:14 +0000 (22:26 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Fri, 6 Jul 2018 15:54:49 +0000 (17:54 +0200)
When fetching only headers from an URL there is no need
to download the whole content.
This was overlooked when migrating the core to use Guzzle.

Resolves: #85491
Releases: master, 8.7
Change-Id: I6475b405d51135372e022b5e133368f15a917687
Reviewed-on: https://review.typo3.org/57488
Reviewed-by: Rudy Gnodde <rgn@windinternet.nl>
Reviewed-by: Robert van Kammen <rvkammen@hotmail.com>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/core/Classes/Utility/GeneralUtility.php

index 754cc2a..93a3b56 100644 (file)
@@ -2045,12 +2045,13 @@ class GeneralUtility
             } else {
                 $configuration = [];
             }
-
+            $includeHeader = (int)$includeHeader;
+            $method = $includeHeader === 2 ? 'HEAD' : 'GET';
             try {
                 if (isset($report)) {
                     $report['lib'] = 'GuzzleHttp';
                 }
-                $response = $requestFactory->request($url, 'GET', $configuration);
+                $response = $requestFactory->request($url, $method, $configuration);
             } catch (RequestException $exception) {
                 if (isset($report)) {
                     $report['error'] = $exception->getCode();
@@ -2059,14 +2060,10 @@ class GeneralUtility
                 }
                 return false;
             }
-
             $content = '';
-
             // Add the headers to the output
-            $includeHeader = (int)$includeHeader;
             if ($includeHeader) {
                 $parsedURL = parse_url($url);
-                $method = $includeHeader === 2 ? 'HEAD' : 'GET';
                 $content = $method . ' ' . (isset($parsedURL['path']) ? $parsedURL['path'] : '/')
                     . ($parsedURL['query'] ? '?' . $parsedURL['query'] : '') . ' HTTP/1.0' . CRLF
                     . 'Host: ' . $parsedURL['host'] . CRLF
@@ -2080,10 +2077,9 @@ class GeneralUtility
                 // Headers are separated from the body with two CRLFs
                 $content .= CRLF;
             }
-            // If not just headers are requested, add the body
-            if ($includeHeader !== 2) {
-                $content .= $response->getBody()->getContents();
-            }
+
+            $content .= $response->getBody()->getContents();
+
             if (isset($report)) {
                 if ($response->getStatusCode() >= 300 && $response->getStatusCode() < 400) {
                     $report['http_code'] = $response->getStatusCode();