You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

211 lines
7.7 KiB

3 years ago
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2016, ownCloud, Inc.
  5. *
  6. * @author Lukas Reschke <lukas@statuscode.ch>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. *
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace OCP\Http\Client;
  26. /**
  27. * Interface IClient
  28. *
  29. * @since 8.1.0
  30. */
  31. interface IClient {
  32. /**
  33. * Sends a GET request
  34. * @param string $uri
  35. * @param array $options Array such as
  36. * 'query' => [
  37. * 'field' => 'abc',
  38. * 'other_field' => '123',
  39. * 'file_name' => fopen('/path/to/file', 'r'),
  40. * ],
  41. * 'headers' => [
  42. * 'foo' => 'bar',
  43. * ],
  44. * 'cookies' => ['
  45. * 'foo' => 'bar',
  46. * ],
  47. * 'allow_redirects' => [
  48. * 'max' => 10, // allow at most 10 redirects.
  49. * 'strict' => true, // use "strict" RFC compliant redirects.
  50. * 'referer' => true, // add a Referer header
  51. * 'protocols' => ['https'] // only allow https URLs
  52. * ],
  53. * 'save_to' => '/path/to/file', // save to a file or a stream
  54. * 'verify' => true, // bool or string to CA file
  55. * 'debug' => true,
  56. * @return IResponse
  57. * @throws \Exception If the request could not get completed
  58. * @since 8.1.0
  59. */
  60. public function get(string $uri, array $options = []): IResponse;
  61. /**
  62. * Sends a HEAD request
  63. * @param string $uri
  64. * @param array $options Array such as
  65. * 'headers' => [
  66. * 'foo' => 'bar',
  67. * ],
  68. * 'cookies' => ['
  69. * 'foo' => 'bar',
  70. * ],
  71. * 'allow_redirects' => [
  72. * 'max' => 10, // allow at most 10 redirects.
  73. * 'strict' => true, // use "strict" RFC compliant redirects.
  74. * 'referer' => true, // add a Referer header
  75. * 'protocols' => ['https'] // only allow https URLs
  76. * ],
  77. * 'save_to' => '/path/to/file', // save to a file or a stream
  78. * 'verify' => true, // bool or string to CA file
  79. * 'debug' => true,
  80. * @return IResponse
  81. * @throws \Exception If the request could not get completed
  82. * @since 8.1.0
  83. */
  84. public function head(string $uri, array $options = []): IResponse;
  85. /**
  86. * Sends a POST request
  87. * @param string $uri
  88. * @param array $options Array such as
  89. * 'body' => [
  90. * 'field' => 'abc',
  91. * 'other_field' => '123',
  92. * 'file_name' => fopen('/path/to/file', 'r'),
  93. * ],
  94. * 'headers' => [
  95. * 'foo' => 'bar',
  96. * ],
  97. * 'cookies' => ['
  98. * 'foo' => 'bar',
  99. * ],
  100. * 'allow_redirects' => [
  101. * 'max' => 10, // allow at most 10 redirects.
  102. * 'strict' => true, // use "strict" RFC compliant redirects.
  103. * 'referer' => true, // add a Referer header
  104. * 'protocols' => ['https'] // only allow https URLs
  105. * ],
  106. * 'save_to' => '/path/to/file', // save to a file or a stream
  107. * 'verify' => true, // bool or string to CA file
  108. * 'debug' => true,
  109. * @return IResponse
  110. * @throws \Exception If the request could not get completed
  111. * @since 8.1.0
  112. */
  113. public function post(string $uri, array $options = []): IResponse;
  114. /**
  115. * Sends a PUT request
  116. * @param string $uri
  117. * @param array $options Array such as
  118. * 'body' => [
  119. * 'field' => 'abc',
  120. * 'other_field' => '123',
  121. * 'file_name' => fopen('/path/to/file', 'r'),
  122. * ],
  123. * 'headers' => [
  124. * 'foo' => 'bar',
  125. * ],
  126. * 'cookies' => ['
  127. * 'foo' => 'bar',
  128. * ],
  129. * 'allow_redirects' => [
  130. * 'max' => 10, // allow at most 10 redirects.
  131. * 'strict' => true, // use "strict" RFC compliant redirects.
  132. * 'referer' => true, // add a Referer header
  133. * 'protocols' => ['https'] // only allow https URLs
  134. * ],
  135. * 'save_to' => '/path/to/file', // save to a file or a stream
  136. * 'verify' => true, // bool or string to CA file
  137. * 'debug' => true,
  138. * @return IResponse
  139. * @throws \Exception If the request could not get completed
  140. * @since 8.1.0
  141. */
  142. public function put(string $uri, array $options = []): IResponse;
  143. /**
  144. * Sends a DELETE request
  145. * @param string $uri
  146. * @param array $options Array such as
  147. * 'body' => [
  148. * 'field' => 'abc',
  149. * 'other_field' => '123',
  150. * 'file_name' => fopen('/path/to/file', 'r'),
  151. * ],
  152. * 'headers' => [
  153. * 'foo' => 'bar',
  154. * ],
  155. * 'cookies' => ['
  156. * 'foo' => 'bar',
  157. * ],
  158. * 'allow_redirects' => [
  159. * 'max' => 10, // allow at most 10 redirects.
  160. * 'strict' => true, // use "strict" RFC compliant redirects.
  161. * 'referer' => true, // add a Referer header
  162. * 'protocols' => ['https'] // only allow https URLs
  163. * ],
  164. * 'save_to' => '/path/to/file', // save to a file or a stream
  165. * 'verify' => true, // bool or string to CA file
  166. * 'debug' => true,
  167. * @return IResponse
  168. * @throws \Exception If the request could not get completed
  169. * @since 8.1.0
  170. */
  171. public function delete(string $uri, array $options = []): IResponse;
  172. /**
  173. * Sends a options request
  174. * @param string $uri
  175. * @param array $options Array such as
  176. * 'body' => [
  177. * 'field' => 'abc',
  178. * 'other_field' => '123',
  179. * 'file_name' => fopen('/path/to/file', 'r'),
  180. * ],
  181. * 'headers' => [
  182. * 'foo' => 'bar',
  183. * ],
  184. * 'cookies' => ['
  185. * 'foo' => 'bar',
  186. * ],
  187. * 'allow_redirects' => [
  188. * 'max' => 10, // allow at most 10 redirects.
  189. * 'strict' => true, // use "strict" RFC compliant redirects.
  190. * 'referer' => true, // add a Referer header
  191. * 'protocols' => ['https'] // only allow https URLs
  192. * ],
  193. * 'save_to' => '/path/to/file', // save to a file or a stream
  194. * 'verify' => true, // bool or string to CA file
  195. * 'debug' => true,
  196. * @return IResponse
  197. * @throws \Exception If the request could not get completed
  198. * @since 8.1.0
  199. */
  200. public function options(string $uri, array $options = []): IResponse;
  201. }