1
0

IRequest.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2016, ownCloud, Inc.
  5. *
  6. * @author Bart Visscher <bartv@thisnet.nl>
  7. * @author Christoph Wurst <christoph@owncloud.com>
  8. * @author Joas Schilling <coding@schilljs.com>
  9. * @author Jörn Friedrich Dreyer <jfd@butonic.de>
  10. * @author Lukas Reschke <lukas@statuscode.ch>
  11. * @author Morris Jobke <hey@morrisjobke.de>
  12. * @author Thomas Müller <thomas.mueller@tmit.eu>
  13. * @author Thomas Tanghus <thomas@tanghus.net>
  14. *
  15. * @license AGPL-3.0
  16. *
  17. * This code is free software: you can redistribute it and/or modify
  18. * it under the terms of the GNU Affero General Public License, version 3,
  19. * as published by the Free Software Foundation.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU Affero General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU Affero General Public License, version 3,
  27. * along with this program. If not, see <http://www.gnu.org/licenses/>
  28. *
  29. */
  30. /**
  31. * Public interface of ownCloud for apps to use.
  32. * Request interface
  33. *
  34. */
  35. // use OCP namespace for all classes that are considered public.
  36. // This means that they should be used by apps instead of the internal ownCloud classes
  37. namespace OCP;
  38. /**
  39. * This interface provides an immutable object with with accessors to
  40. * request variables and headers.
  41. *
  42. * Access request variables by method and name.
  43. *
  44. * Examples:
  45. *
  46. * $request->post['myvar']; // Only look for POST variables
  47. * $request->myvar; or $request->{'myvar'}; or $request->{$myvar}
  48. * Looks in the combined GET, POST and urlParams array.
  49. *
  50. * If you access e.g. ->post but the current HTTP request method
  51. * is GET a \LogicException will be thrown.
  52. *
  53. * NOTE:
  54. * - When accessing ->put a stream resource is returned and the accessor
  55. * will return false on subsequent access to ->put or ->patch.
  56. * - When accessing ->patch and the Content-Type is either application/json
  57. * or application/x-www-form-urlencoded (most cases) it will act like ->get
  58. * and ->post and return an array. Otherwise the raw data will be returned.
  59. *
  60. * @property-read string[] $server
  61. * @property-read string[] $urlParams
  62. * @since 6.0.0
  63. */
  64. interface IRequest {
  65. /**
  66. * @since 9.1.0
  67. */
  68. const USER_AGENT_CLIENT_ANDROID = '/^Mozilla\/5\.0 \(Android\) (ownCloud|Nextcloud)\-android.*$/';
  69. /**
  70. * @since 13.0.0
  71. */
  72. const USER_AGENT_TALK_ANDROID = '/^Mozilla\/5\.0 \(Android\) Nextcloud\-Talk v.*$/';
  73. /**
  74. * @since 9.1.0
  75. */
  76. const USER_AGENT_CLIENT_DESKTOP = '/^Mozilla\/5\.0 \([A-Za-z ]+\) (mirall|csyncoC)\/.*$/';
  77. /**
  78. * @since 9.1.0
  79. */
  80. const USER_AGENT_CLIENT_IOS = '/^Mozilla\/5\.0 \(iOS\) (ownCloud|Nextcloud)\-iOS.*$/';
  81. /**
  82. * @since 13.0.0
  83. */
  84. const USER_AGENT_TALK_IOS = '/^Mozilla\/5\.0 \(iOS\) Nextcloud\-Talk v.*$/';
  85. /**
  86. * @since 13.0.1
  87. */
  88. const USER_AGENT_OUTLOOK_ADDON = '/^Mozilla\/5\.0 \([A-Za-z ]+\) Nextcloud\-Outlook v.*$/';
  89. /**
  90. * @since 13.0.1
  91. */
  92. const USER_AGENT_THUNDERBIRD_ADDON = '/^Mozilla\/5\.0 \([A-Za-z ]+\) Nextcloud\-Thunderbird v.*$/';
  93. /**
  94. * @param string $name
  95. *
  96. * @return string
  97. * @since 6.0.0
  98. */
  99. public function getHeader(string $name): string;
  100. /**
  101. * Lets you access post and get parameters by the index
  102. * In case of json requests the encoded json body is accessed
  103. *
  104. * @param string $key the key which you want to access in the URL Parameter
  105. * placeholder, $_POST or $_GET array.
  106. * The priority how they're returned is the following:
  107. * 1. URL parameters
  108. * 2. POST parameters
  109. * 3. GET parameters
  110. * @param mixed $default If the key is not found, this value will be returned
  111. * @return mixed the content of the array
  112. * @since 6.0.0
  113. */
  114. public function getParam(string $key, $default = null);
  115. /**
  116. * Returns all params that were received, be it from the request
  117. *
  118. * (as GET or POST) or through the URL by the route
  119. *
  120. * @return array the array with all parameters
  121. * @since 6.0.0
  122. */
  123. public function getParams(): array;
  124. /**
  125. * Returns the method of the request
  126. *
  127. * @return string the method of the request (POST, GET, etc)
  128. * @since 6.0.0
  129. */
  130. public function getMethod(): string;
  131. /**
  132. * Shortcut for accessing an uploaded file through the $_FILES array
  133. *
  134. * @param string $key the key that will be taken from the $_FILES array
  135. * @return array the file in the $_FILES element
  136. * @since 6.0.0
  137. */
  138. public function getUploadedFile(string $key);
  139. /**
  140. * Shortcut for getting env variables
  141. *
  142. * @param string $key the key that will be taken from the $_ENV array
  143. * @return array the value in the $_ENV element
  144. * @since 6.0.0
  145. */
  146. public function getEnv(string $key);
  147. /**
  148. * Shortcut for getting cookie variables
  149. *
  150. * @param string $key the key that will be taken from the $_COOKIE array
  151. * @return string|null the value in the $_COOKIE element
  152. * @since 6.0.0
  153. */
  154. public function getCookie(string $key);
  155. /**
  156. * Checks if the CSRF check was correct
  157. *
  158. * @return bool true if CSRF check passed
  159. * @since 6.0.0
  160. */
  161. public function passesCSRFCheck(): bool;
  162. /**
  163. * Checks if the strict cookie has been sent with the request if the request
  164. * is including any cookies.
  165. *
  166. * @return bool
  167. * @since 9.0.0
  168. */
  169. public function passesStrictCookieCheck(): bool;
  170. /**
  171. * Checks if the lax cookie has been sent with the request if the request
  172. * is including any cookies.
  173. *
  174. * @return bool
  175. * @since 9.0.0
  176. */
  177. public function passesLaxCookieCheck(): bool;
  178. /**
  179. * Returns an ID for the request, value is not guaranteed to be unique and is mostly meant for logging
  180. * If `mod_unique_id` is installed this value will be taken.
  181. *
  182. * @return string
  183. * @since 8.1.0
  184. */
  185. public function getId(): string;
  186. /**
  187. * Returns the remote address, if the connection came from a trusted proxy
  188. * and `forwarded_for_headers` has been configured then the IP address
  189. * specified in this header will be returned instead.
  190. * Do always use this instead of $_SERVER['REMOTE_ADDR']
  191. *
  192. * @return string IP address
  193. * @since 8.1.0
  194. */
  195. public function getRemoteAddress(): string;
  196. /**
  197. * Returns the server protocol. It respects reverse proxy servers and load
  198. * balancers.
  199. *
  200. * @return string Server protocol (http or https)
  201. * @since 8.1.0
  202. */
  203. public function getServerProtocol(): string;
  204. /**
  205. * Returns the used HTTP protocol.
  206. *
  207. * @return string HTTP protocol. HTTP/2, HTTP/1.1 or HTTP/1.0.
  208. * @since 8.2.0
  209. */
  210. public function getHttpProtocol(): string;
  211. /**
  212. * Returns the request uri, even if the website uses one or more
  213. * reverse proxies
  214. *
  215. * @return string
  216. * @since 8.1.0
  217. */
  218. public function getRequestUri(): string;
  219. /**
  220. * Get raw PathInfo from request (not urldecoded)
  221. *
  222. * @throws \Exception
  223. * @return string Path info
  224. * @since 8.1.0
  225. */
  226. public function getRawPathInfo(): string;
  227. /**
  228. * Get PathInfo from request
  229. *
  230. * @throws \Exception
  231. * @return string|false Path info or false when not found
  232. * @since 8.1.0
  233. */
  234. public function getPathInfo();
  235. /**
  236. * Returns the script name, even if the website uses one or more
  237. * reverse proxies
  238. *
  239. * @return string the script name
  240. * @since 8.1.0
  241. */
  242. public function getScriptName(): string;
  243. /**
  244. * Checks whether the user agent matches a given regex
  245. *
  246. * @param array $agent array of agent names
  247. * @return bool true if at least one of the given agent matches, false otherwise
  248. * @since 8.1.0
  249. */
  250. public function isUserAgent(array $agent): bool;
  251. /**
  252. * Returns the unverified server host from the headers without checking
  253. * whether it is a trusted domain
  254. *
  255. * @return string Server host
  256. * @since 8.1.0
  257. */
  258. public function getInsecureServerHost(): string;
  259. /**
  260. * Returns the server host from the headers, or the first configured
  261. * trusted domain if the host isn't in the trusted list
  262. *
  263. * @return string Server host
  264. * @since 8.1.0
  265. */
  266. public function getServerHost(): string;
  267. }