Skip to content

Commit

Permalink
[BUGFIX] Use correct HTTP method in GeneralUtility::getUrl
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
liayn authored and maddy2101 committed Jul 6, 2018
1 parent 28fd8ff commit 770b3a5
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions typo3/sysext/core/Classes/Utility/GeneralUtility.php
Expand Up @@ -2045,12 +2045,13 @@ public static function getUrl($url, $includeHeader = 0, $requestHeaders = null,
} 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();
Expand All @@ -2059,14 +2060,10 @@ public static function getUrl($url, $includeHeader = 0, $requestHeaders = null,
}
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
Expand All @@ -2080,10 +2077,9 @@ public static function getUrl($url, $includeHeader = 0, $requestHeaders = null,
// 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();
Expand Down

0 comments on commit 770b3a5

Please sign in to comment.