[BUGFIX] Use correct HTTP method in GeneralUtility::getUrl 79/57479/5
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:34:42 +0000 (17:34 +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/57479
Reviewed-by: Mathias Brodala <mbrodala@pagemachine.de>
Tested-by: Mathias Brodala <mbrodala@pagemachine.de>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Jürgen Venne <venne@schaffrath-digital.de>
Tested-by: Jürgen Venne <venne@schaffrath-digital.de>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/core/Classes/Utility/GeneralUtility.php

index 891af0e..f2c8c7e 100644 (file)
@@ -1809,12 +1809,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() ?: 1518707554;
@@ -1823,14 +1824,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 . ' ' . ($parsedURL['path'] ?? '/')
                     . (!empty($parsedURL['query']) ? '?' . $parsedURL['query'] : '') . ' HTTP/1.0' . CRLF
                     . 'Host: ' . $parsedURL['host'] . CRLF
@@ -1844,10 +1841,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();