]> git.mxchange.org Git - friendica.git/commitdiff
Remove contact immediately on 410 response code
authorMatthew Exon <git.mexon@spamgourmet.com>
Sat, 13 Jul 2024 15:49:01 +0000 (17:49 +0200)
committerMatthew Exon <git.mexon@spamgourmet.com>
Mon, 15 Jul 2024 06:52:56 +0000 (08:52 +0200)
src/Network/HTTPClient/Capability/ICanHandleHttpResponses.php
src/Network/HTTPClient/Response/CurlResult.php
src/Network/HTTPClient/Response/GuzzleResponse.php
src/Worker/OnePoll.php

index 5eb2e9bf4db926e617500d397675fc8e329b1922..76ce255a0bf5091d7232066ec76e90b091c115c7 100644 (file)
@@ -84,6 +84,13 @@ interface ICanHandleHttpResponses
         */
        public function isSuccess(): bool;
 
+       /**
+        * Returns if the URL is permanently gone (return code 410)
+        *
+        * @return bool
+        */
+       public function isGone(): bool;
+
        /**
         * @return string
         */
index 2680a8b8066368a92141729e7c2aed2cfc868211..15c13b779cb529aadca72b3ee2cd3bf868e84502 100644 (file)
@@ -56,6 +56,11 @@ class CurlResult implements ICanHandleHttpResponses
         */
        private $isSuccess;
 
+       /**
+        * @var boolean true (if HTTP 410 result) or false
+        */
+       private $isGone;
+
        /**
         * @var string the URL which was called
         */
@@ -148,6 +153,7 @@ class CurlResult implements ICanHandleHttpResponses
 
                $this->parseBodyHeader($result);
                $this->checkSuccess();
+               $this->checkGone();
                $this->checkRedirect();
                $this->checkInfo();
        }
@@ -194,6 +200,11 @@ class CurlResult implements ICanHandleHttpResponses
                }
        }
 
+       private function checkGone()
+       {
+               $this->isGone = $this->returnCode == 410;
+       }
+
        private function checkRedirect()
        {
                if (!array_key_exists('url', $this->info)) {
@@ -322,6 +333,12 @@ class CurlResult implements ICanHandleHttpResponses
                return $this->isSuccess;
        }
 
+       /** {@inheritDoc} */
+       public function isGone(): bool
+       {
+               return $this->isSuccess;
+       }
+
        /** {@inheritDoc} */
        public function getUrl(): string
        {
index 277acbbc9a697f996d177e8b327a82253987ee80..31e6e8957311d7b2b2a28387bab34e965e29aa1b 100644 (file)
@@ -38,6 +38,8 @@ class GuzzleResponse extends Response implements ICanHandleHttpResponses, Respon
        private $isTimeout;
        /** @var boolean */
        private $isSuccess;
+       /** @var boolean */
+       private $isGone;
        /**
         * @var int the error number or 0 (zero) if no error
         */
@@ -63,6 +65,7 @@ class GuzzleResponse extends Response implements ICanHandleHttpResponses, Respon
                $this->errorNumber = $errorNumber;
 
                $this->checkSuccess();
+               $this->checkGone();
                $this->checkRedirect($response);
        }
 
@@ -86,6 +89,11 @@ class GuzzleResponse extends Response implements ICanHandleHttpResponses, Respon
                }
        }
 
+       private function checkGone()
+       {
+               $this->isGone = $this->getStatusCode() == 410;
+       }
+
        private function checkRedirect(ResponseInterface $response)
        {
                $headersRedirect = $response->getHeader(RedirectMiddleware::HISTORY_HEADER) ?? [];
@@ -135,6 +143,12 @@ class GuzzleResponse extends Response implements ICanHandleHttpResponses, Respon
                return $this->isSuccess;
        }
 
+       /** {@inheritDoc} */
+       public function isGone(): bool
+       {
+               return $this->isGone;
+       }
+
        /** {@inheritDoc} */
        public function getUrl(): string
        {
index 7c784ab7049a47775b1d70a615b64492934f4dc6..e2db89fce52ee86a7d08e95691b48d89757e648f 100644 (file)
@@ -174,6 +174,12 @@ class OnePoll
                        return false;
                }
 
+               if ($curlResult->isGone()) {
+                       Logger::notice('URL is permanently gone', ['id' => $contact['id'], 'url' => $contact['poll']]);
+                       Contact::remove($contact['id']);
+                       return false;
+               }
+
                if ($curlResult->redirectIsPermanent()) {
                        Logger::notice('Poll address permanently changed', [
                                'id' => $contact['id'],