]> git.mxchange.org Git - friendica.git/blobdiff - src/Network/HTTPClient.php
Fix HTTPClient
[friendica.git] / src / Network / HTTPClient.php
index d83b805df0d278229769228aa58f032d00ef2501..f4653628ffabaa78082d97c8891e9e9ee652849a 100644 (file)
@@ -31,6 +31,7 @@ use GuzzleHttp\Exception\TransferException;
 use GuzzleHttp\RequestOptions;
 use mattwright\URLResolver;
 use Psr\Http\Message\ResponseInterface;
+use Psr\Log\InvalidArgumentException;
 use Psr\Log\LoggerInterface;
 
 /**
@@ -92,11 +93,6 @@ class HTTPClient implements IHTTPClient
                        return CurlResult::createErrorCurl($url);
                }
 
-               if (Network::isRedirectBlocked($url)) {
-                       $this->logger->info('Domain should not be redirected.', ['url' => $url]);
-                       return CurlResult::createErrorCurl($url);
-               }
-
                $conf = [];
 
                if (!empty($opts['cookiejar'])) {
@@ -107,7 +103,7 @@ class HTTPClient implements IHTTPClient
                $header = [];
 
                if (!empty($opts['accept_content'])) {
-                       array_push($header, 'Accept: ' . $opts['accept_content']);
+                       $header['Accept'] = $opts['accept_content'];
                }
 
                if (!empty($opts['header'])) {
@@ -135,10 +131,9 @@ class HTTPClient implements IHTTPClient
                try {
                        switch ($method) {
                                case 'get':
-                                       $response = $this->client->get($url, $conf);
-                                       break;
                                case 'head':
-                                       $response = $this->client->head($url, $conf);
+                               case 'post':
+                                       $response = $this->client->$method($url, $conf);
                                        break;
                                default:
                                        throw new TransferException('Invalid method');
@@ -151,6 +146,9 @@ class HTTPClient implements IHTTPClient
                        } else {
                                return new CurlResult($url, '', ['http_code' => $exception->getCode()], $exception->getCode(), '');
                        }
+               } catch (InvalidArgumentException $argumentException) {
+                       $this->logger->info('Invalid Argument for HTTP call.', ['url' => $url, 'method' => $method, 'exception' => $argumentException]);
+                       return new CurlResult($url, '', ['http_code' => $argumentException->getCode()], $argumentException->getCode(), $argumentException->getMessage());
                } finally {
                        $this->logger->debug('Request stop.', ['url' => $url, 'method' => $method]);
                        $this->profiler->stopRecording();