summaryrefslogtreecommitdiffstats
path: root/lib/private/HTTPHelper.php
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@owncloud.com>2016-04-29 13:13:47 +0200
committerRoeland Jago Douma <rullzer@owncloud.com>2016-04-29 13:13:47 +0200
commitf5e0d6ae6adacc44d2e7821425af39ba0a7dc71a (patch)
treee717eb0e4f1b6b3485c6d7fbb1d2df195be9609a /lib/private/HTTPHelper.php
parent5b45f0f91448f109ff33d4fb03368a0405e1da10 (diff)
downloadnextcloud-server-f5e0d6ae6adacc44d2e7821425af39ba0a7dc71a.tar.gz
nextcloud-server-f5e0d6ae6adacc44d2e7821425af39ba0a7dc71a.zip
Move more of \OC to PSR-4
* \OC\DateTimeFormatter * \OC\DateTimeZone * \OC\ForbiddenException * \OC\HTTPHelper * \OC\HintException * \OC\LargeFileHelper * \OC\Log * \OC\NaturalSort * \OC\NavigationManager * \OC\NeedsUpdateException * \OC\NotSquareException
Diffstat (limited to 'lib/private/HTTPHelper.php')
-rw-r--r--lib/private/HTTPHelper.php119
1 files changed, 119 insertions, 0 deletions
diff --git a/lib/private/HTTPHelper.php b/lib/private/HTTPHelper.php
new file mode 100644
index 00000000000..f33d4a51745
--- /dev/null
+++ b/lib/private/HTTPHelper.php
@@ -0,0 +1,119 @@
+<?php
+/**
+ * @author Björn Schießle <schiessle@owncloud.com>
+ * @author Lukas Reschke <lukas@owncloud.com>
+ * @author Morris Jobke <hey@morrisjobke.de>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OC;
+
+use OCP\Http\Client\IClientService;
+use OCP\IConfig;
+
+/**
+ * Class HTTPHelper
+ *
+ * @package OC
+ * @deprecated Use \OCP\Http\Client\IClientService
+ */
+class HTTPHelper {
+ const USER_AGENT = 'ownCloud Server Crawler';
+
+ /** @var \OCP\IConfig */
+ private $config;
+ /** @var IClientService */
+ private $clientService;
+
+ /**
+ * @param IConfig $config
+ * @param IClientService $clientService
+ */
+ public function __construct(IConfig $config,
+ IClientService $clientService) {
+ $this->config = $config;
+ $this->clientService = $clientService;
+ }
+
+ /**
+ * Get URL content
+ * @param string $url Url to get content
+ * @throws \Exception If the URL does not start with http:// or https://
+ * @return string of the response or false on error
+ * This function get the content of a page via curl, if curl is enabled.
+ * If not, file_get_contents is used.
+ * @deprecated Use \OCP\Http\Client\IClientService
+ */
+ public function getUrlContent($url) {
+ try {
+ $client = $this->clientService->newClient();
+ $response = $client->get($url);
+ return $response->getBody();
+ } catch (\Exception $e) {
+ return false;
+ }
+ }
+
+ /**
+ * Returns the response headers of a HTTP URL without following redirects
+ * @param string $location Needs to be a HTTPS or HTTP URL
+ * @return array
+ * @deprecated Use \OCP\Http\Client\IClientService
+ */
+ public function getHeaders($location) {
+ $client = $this->clientService->newClient();
+ $response = $client->get($location);
+ return $response->getHeaders();
+ }
+
+ /**
+ * Checks whether the supplied URL begins with HTTPS:// or HTTP:// (case insensitive)
+ * @param string $url
+ * @return bool
+ */
+ public function isHTTPURL($url) {
+ return stripos($url, 'https://') === 0 || stripos($url, 'http://') === 0;
+ }
+
+ /**
+ * send http post request
+ *
+ * @param string $url
+ * @param array $fields data send by the request
+ * @return array
+ * @deprecated Use \OCP\Http\Client\IClientService
+ */
+ public function post($url, array $fields) {
+ $client = $this->clientService->newClient();
+
+ try {
+ $response = $client->post(
+ $url,
+ [
+ 'body' => $fields,
+ 'connect_timeout' => 10,
+ ]
+ );
+ } catch (\Exception $e) {
+ return ['success' => false, 'result' => $e->getMessage()];
+ }
+
+ return ['success' => true, 'result' => $response->getBody()];
+ }
+
+}