1
0

IRequest.php 7.6 KB

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