[TASK] Retry request on 403 in linkvalidator 89/26489/6
authorAlexander Stehlik <alexander.stehlik@googlemail.com>
Thu, 19 Dec 2013 13:53:11 +0000 (14:53 +0100)
committerMarkus Klein <klein.t3@mfc-linz.at>
Tue, 18 Mar 2014 10:10:31 +0000 (11:10 +0100)
When the linkvalidator detects a 403 error when doing a HEAD request to
an external URL it will retry the request using the GET method.

Resolves: #54513
Releases: 6.2
Change-Id: Ib36b6cbb8e981b95c348afd5a063ca4f5040de75
Reviewed-on: https://review.typo3.org/26489
Reviewed-by: Markus Klein
Tested-by: Markus Klein
typo3/sysext/linkvalidator/Classes/Linktype/ExternalLinktype.php

index 4c0b810..40599ad 100644 (file)
@@ -86,7 +86,8 @@ class ExternalLinktype extends \TYPO3\CMS\Linkvalidator\Linktype\AbstractLinktyp
                        /** @var $response \HTTP_Request2_Response */
                        $response = $request->send();
                        // HEAD was not allowed, now trying GET
-                       if (isset($response) && $response->getStatus() === 405) {
+                       $status = isset($response) ? $response->getStatus() : 0;
+                       if ($status === 405 || $status === 403) {
                                $request->setMethod('GET');
                                $request->setHeader('Range', 'bytes = 0 - 4048');
                                /** @var $response \HTTP_Request2_Response */
@@ -108,9 +109,10 @@ class ExternalLinktype extends \TYPO3\CMS\Linkvalidator\Linktype\AbstractLinktyp
                        }
                        $errorParams['message'] = $e->getMessage();
                }
-               if (isset($response) && $response->getStatus() >= 300) {
+               $status = isset($response) ? $response->getStatus() : 0;
+               if ($status >= 300) {
                        $isValidUrl = FALSE;
-                       $errorParams['errorType'] = $response->getStatus();
+                       $errorParams['errorType'] = $status;
                        $errorParams['message'] = $response->getReasonPhrase();
                }
                if (!$isValidUrl) {