IRequest

interface OCP\IRequest
This interface provides an immutable object with with accessors to
request variables and headers.
Access request variables by method and name.

Examples:

$request->post[‘myvar’]; // Only look for POST variables
$request->myvar; or $request->{‘myvar’}; or $request->{$myvar}
Looks in the combined GET, POST and urlParams array.

If you access e.g. ->post but the current HTTP request method
is GET a \LogicException will be thrown.

NOTE:
- When accessing ->put a stream resource is returned and the accessor
will return false on subsequent access to ->put or ->patch.
- When accessing ->patch and the Content-Type is either application/json
or application/x-www-form-urlencoded (most cases) it will act like ->get
and ->post and return an array. Otherwise the raw data will be returned.
Implemented by:OC\AppFramework\Http\Request
Source:lib/public/IRequest.php#71

Constants

USER_AGENT_CLIENT_ANDROID = /^Mozilla\/5\.0 \(Android\) (ownCloud|Nextcloud)\-android.*$/
Source:lib/public/IRequest.php#75
Since:9.1.0
USER_AGENT_TALK_ANDROID = /^Mozilla\/5\.0 \(Android\) Nextcloud\-Talk v.*$/
Source:lib/public/IRequest.php#80
Since:13.0.0
USER_AGENT_CLIENT_DESKTOP = /^Mozilla\/5\.0 \([A-Za-z ]+\) (mirall|csyncoC)\/.*$/
Source:lib/public/IRequest.php#85
Since:9.1.0
USER_AGENT_CLIENT_IOS = /^Mozilla\/5\.0 \(iOS\) (ownCloud|Nextcloud)\-iOS.*$/
Source:lib/public/IRequest.php#90
Since:9.1.0
USER_AGENT_TALK_IOS = /^Mozilla\/5\.0 \(iOS\) Nextcloud\-Talk v.*$/
Source:lib/public/IRequest.php#95
Since:13.0.0
USER_AGENT_OUTLOOK_ADDON = /^Mozilla\/5\.0 \([A-Za-z ]+\) Nextcloud\-Outlook v.*$/
Source:lib/public/IRequest.php#100
Since:13.0.1
USER_AGENT_THUNDERBIRD_ADDON = /^Mozilla\/5\.0 \([A-Za-z ]+\) Nextcloud\-Thunderbird v.*$/
Source:lib/public/IRequest.php#105
Since:13.0.1

Methods

public OCP\IRequest::getHeader($name)
Source:

lib/public/IRequest.php#115

Parameters:
  • $name (string)
Returns:

string

Since:

6.0.0

public OCP\IRequest::getParam($key, $default=null)
Lets you access post and get parameters by the index
In case of json requests the encoded json body is accessed
Source:

lib/public/IRequest.php#133

Parameters:
  • $key (string) the key which you want to access in the URL Parameter

placeholder, $_POST or $_GET array. The priority how they’re returned is the following: 1. URL parameters 2. POST parameters 3. GET parameters * $default (mixed) If the key is not found, this value will be returned

Returns:

mixed the content of the array

Since:

6.0.0

public OCP\IRequest::getParams()
Returns all params that were received, be it from the request
(as GET or POST) or through the URL by the route
Source:lib/public/IRequest.php#146
Returns:array the array with all parameters
Since:6.0.0
public OCP\IRequest::getMethod()
Returns the method of the request
Source:lib/public/IRequest.php#154
Returns:string the method of the request (POST, GET, etc)
Since:6.0.0
public OCP\IRequest::getUploadedFile($key)
Shortcut for accessing an uploaded file through the $_FILES array
Source:

lib/public/IRequest.php#163

Parameters:
  • $key (string) the key that will be taken from the $_FILES array
Returns:

array the file in the $_FILES element

Since:

6.0.0

public OCP\IRequest::getEnv($key)
Shortcut for getting env variables
Source:

lib/public/IRequest.php#173

Parameters:
  • $key (string) the key that will be taken from the $_ENV array
Returns:

array the value in the $_ENV element

Since:

6.0.0

public OCP\IRequest::getCookie($key)
Shortcut for getting cookie variables
Source:

lib/public/IRequest.php#185

Parameters:
  • $key (string) the key that will be taken from the $_COOKIE array
Returns:

string | null the value in the $_COOKIE element

Since:

6.0.0

public OCP\IRequest::passesCSRFCheck()
Checks if the CSRF check was correct
Source:lib/public/IRequest.php#194
Returns:bool true if CSRF check passed
Since:6.0.0
public OCP\IRequest::passesStrictCookieCheck()
Checks if the strict cookie has been sent with the request if the request
is including any cookies.
Source:lib/public/IRequest.php#203
Returns:bool
Since:9.0.0
public OCP\IRequest::passesLaxCookieCheck()
Checks if the lax cookie has been sent with the request if the request
is including any cookies.
Source:lib/public/IRequest.php#212
Returns:bool
Since:9.0.0
public OCP\IRequest::getId()
Returns an ID for the request, value is not guaranteed to be unique and is mostly meant for logging
If `mod_unique_id` is installed this value will be taken.
Source:lib/public/IRequest.php#221
Returns:string
Since:8.1.0
public OCP\IRequest::getRemoteAddress()
Returns the remote address, if the connection came from a trusted proxy
and `forwarded_for_headers` has been configured then the IP address
specified in this header will be returned instead.
Do always use this instead of $_SERVER[‘REMOTE_ADDR’]
Source:lib/public/IRequest.php#232
Returns:string IP address
Since:8.1.0
public OCP\IRequest::getServerProtocol()
Returns the server protocol. It respects reverse proxy servers and load
balancers.
Source:lib/public/IRequest.php#241
Returns:string Server protocol (http or https)
Since:8.1.0
public OCP\IRequest::getHttpProtocol()
Returns the used HTTP protocol.
Source:lib/public/IRequest.php#249
Returns:string HTTP protocol. HTTP/2, HTTP/1.1 or HTTP/1.0.
Since:8.2.0
public OCP\IRequest::getRequestUri()
Returns the request uri, even if the website uses one or more
reverse proxies
Source:lib/public/IRequest.php#260
Returns:string
Since:8.1.0
public OCP\IRequest::getRawPathInfo()
Get raw PathInfo from request (not urldecoded)
Source:lib/public/IRequest.php#271
Throws:\Exception
Returns:string Path info
Since:8.1.0
public OCP\IRequest::getPathInfo()
Get PathInfo from request
Source:lib/public/IRequest.php#282
Throws:\Exception
Returns:string | bool Path info or false when not found
Since:8.1.0
public OCP\IRequest::getScriptName()
Returns the script name, even if the website uses one or more
reverse proxies
Source:lib/public/IRequest.php#291
Returns:string the script name
Since:8.1.0
public OCP\IRequest::isUserAgent($agent)
Checks whether the user agent matches a given regex
Source:

lib/public/IRequest.php#300

Parameters:
  • $agent (array) array of agent names
Returns:

bool true if at least one of the given agent matches, false otherwise

Since:

8.1.0

public OCP\IRequest::getInsecureServerHost()
Returns the unverified server host from the headers without checking
whether it is a trusted domain
Source:lib/public/IRequest.php#311
Returns:string Server host
Since:8.1.0
public OCP\IRequest::getServerHost()
Returns the server host from the headers, or the first configured
trusted domain if the host isn’t in the trusted list
Source:lib/public/IRequest.php#320
Returns:string Server host
Since:8.1.0