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.

IRequest.php 7.3KB

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