]> git.mxchange.org Git - friendica.git/blob - src/Network/IHTTPRequest.php
Fix: The "extid" field wasn't updated
[friendica.git] / src / Network / IHTTPRequest.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2021, the Friendica project
4  *
5  * @license GNU APGL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Network;
23
24 /**
25  * Interface for calling HTTP requests and returning their responses
26  */
27 interface IHTTPRequest
28 {
29         /**
30          * Fetches the content of an URL
31          *
32          * Set the cookiejar argument to a string (e.g. "/tmp/friendica-cookies.txt")
33          * to preserve cookies from one request to the next.
34          *
35          * @param string $url             URL to fetch
36          * @param int    $timeout         Timeout in seconds, default system config value or 60 seconds
37          * @param string $accept_content  supply Accept: header with 'accept_content' as the value
38          * @param string $cookiejar       Path to cookie jar file
39          *
40          * @return string The fetched content
41          */
42         public function fetch(string $url, int $timeout = 0, string $accept_content = '', string $cookiejar = '');
43
44         /**
45          * Fetches the whole response of an URL.
46          *
47          * Inner workings and parameters are the same as @ref fetchUrl but returns an array with
48          * all the information collected during the fetch.
49          *
50          * @param string $url             URL to fetch
51          * @param int    $timeout         Timeout in seconds, default system config value or 60 seconds
52          * @param string $accept_content  supply Accept: header with 'accept_content' as the value
53          * @param string $cookiejar       Path to cookie jar file
54          *
55          * @return CurlResult With all relevant information, 'body' contains the actual fetched content.
56          */
57         public function fetchFull(string $url, int $timeout = 0, string $accept_content = '', string $cookiejar = '');
58
59         /**
60          * Send a HEAD to an URL.
61          *
62          * @param string $url        URL to fetch
63          * @param array  $opts       (optional parameters) assoziative array with:
64          *                           'accept_content' => supply Accept: header with 'accept_content' as the value
65          *                           'timeout' => int Timeout in seconds, default system config value or 60 seconds
66          *                           'cookiejar' => path to cookie jar file
67          *                           'header' => header array
68          *
69          * @return CurlResult
70          */
71         public function head(string $url, array $opts = []);
72
73         /**
74          * Send a GET to an URL.
75          *
76          * @param string $url        URL to fetch
77          * @param array  $opts       (optional parameters) assoziative array with:
78          *                           'accept_content' => supply Accept: header with 'accept_content' as the value
79          *                           'timeout' => int Timeout in seconds, default system config value or 60 seconds
80          *                           'cookiejar' => path to cookie jar file
81          *                           'header' => header array
82          *
83          * @return CurlResult
84          */
85         public function get(string $url, array $opts = []);
86
87         /**
88          * Send POST request to an URL
89          *
90          * @param string $url     URL to post
91          * @param mixed  $params  array of POST variables
92          * @param array  $headers HTTP headers
93          * @param int    $timeout The timeout in seconds, default system config value or 60 seconds
94          *
95          * @return CurlResult The content
96          */
97         public function post(string $url, $params, array $headers = [], int $timeout = 0);
98
99         /**
100          * Returns the original URL of the provided URL
101          *
102          * This function strips tracking query params and follows redirections, either
103          * through HTTP code or meta refresh tags. Stops after 10 redirections.
104          *
105          * @param string $url       A user-submitted URL
106          * @param int    $depth     The current redirection recursion level (internal)
107          * @param bool   $fetchbody Wether to fetch the body or not after the HEAD requests
108          *
109          * @return string A canonical URL
110          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
111          * @see   ParseUrl::getSiteinfo
112          *
113          * @todo  Remove the $fetchbody parameter that generates an extraneous HEAD request
114          */
115         public function finalUrl(string $url, int $depth = 1, bool $fetchbody = false);
116
117         /**
118          * Returns the current UserAgent as a String
119          *
120          * @return string the UserAgent as a String
121          */
122         public function getUserAgent();
123 }