Request

class OC\AppFramework\Http\Request
Class for accessing variables in the request.
This class provides an immutable object with request variables.
Source:lib/private/AppFramework/Http/Request.php#60
Implements:ArrayAccess Countable OCP\IRequest

Constants

USER_AGENT_IE = /(MSIE)|(Trident)/
Source:lib/private/AppFramework/Http/Request.php#62
USER_AGENT_MS_EDGE = /^Mozilla\/5\.0 \([^)]+\) AppleWebKit\/[0-9.]+ \(KHTML, like Gecko\) Chrome\/[0-9.]+ (Mobile Safari|Safari)\/[0-9.]+ Edge\/[0-9.]+$/
Source:lib/private/AppFramework/Http/Request.php#64
USER_AGENT_FIREFOX = /^Mozilla\/5\.0 \([^)]+\) Gecko\/[0-9.]+ Firefox\/[0-9.]+$/
Source:lib/private/AppFramework/Http/Request.php#66
USER_AGENT_CHROME = /^Mozilla\/5\.0 \([^)]+\) AppleWebKit\/[0-9.]+ \(KHTML, like Gecko\)( Ubuntu Chromium\/[0-9.]+|) Chrome\/[0-9.]+ (Mobile Safari|Safari)\/[0-9.]+$/
Source:lib/private/AppFramework/Http/Request.php#68
USER_AGENT_SAFARI = /^Mozilla\/5\.0 \([^)]+\) AppleWebKit\/[0-9.]+ \(KHTML, like Gecko\) Version\/[0-9.]+ Safari\/[0-9.A-Z]+$/
Source:lib/private/AppFramework/Http/Request.php#70
USER_AGENT_ANDROID_MOBILE_CHROME = #Android.*Chrome/[.0-9]*#
Source:lib/private/AppFramework/Http/Request.php#72
USER_AGENT_FREEBOX = #^Mozilla/5\.0$#
Source:lib/private/AppFramework/Http/Request.php#73
REGEX_LOCALHOST = /^(127\.0\.0\.1|localhost|::1)$/
Source:lib/private/AppFramework/Http/Request.php#74
USER_AGENT_OWNCLOUD_IOS = /^Mozilla\/5\.0 \(iOS\) (ownCloud|Nextcloud)\-iOS.*$/
Source:lib/private/AppFramework/Http/Request.php#79
Deprecated:use \OCP\IRequest::USER_AGENT_CLIENT_IOS instead
USER_AGENT_OWNCLOUD_ANDROID = /^Mozilla\/5\.0 \(Android\) ownCloud\-android.*$/
Source:lib/private/AppFramework/Http/Request.php#83
Deprecated:use \OCP\IRequest::USER_AGENT_CLIENT_ANDROID instead
USER_AGENT_OWNCLOUD_DESKTOP = /^Mozilla\/5\.0 \([A-Za-z ]+\) (mirall|csyncoC)\/.*$/
Source:lib/private/AppFramework/Http/Request.php#87
Deprecated:use \OCP\IRequest::USER_AGENT_CLIENT_DESKTOP instead

Properties

protected static property OC\AppFramework\Http\Request::$inputStream
Source:lib/private/AppFramework/Http/Request.php#89
protected static property OC\AppFramework\Http\Request::$content
Source:lib/private/AppFramework/Http/Request.php#90
protected static property OC\AppFramework\Http\Request::$items
Source:lib/private/AppFramework/Http/Request.php#91
protected static property OC\AppFramework\Http\Request::$allowedKeys
Source:lib/private/AppFramework/Http/Request.php#92
protected static property OC\AppFramework\Http\Request::$secureRandom
Source:lib/private/AppFramework/Http/Request.php#105
Type:\OCP\Security\ISecureRandom
protected static property OC\AppFramework\Http\Request::$config
Source:lib/private/AppFramework/Http/Request.php#107
Type:\OCP\IConfig
protected static property OC\AppFramework\Http\Request::$requestId
Source:lib/private/AppFramework/Http/Request.php#109
Type:string
protected static property OC\AppFramework\Http\Request::$crypto
Source:lib/private/AppFramework/Http/Request.php#111
Type:\OCP\Security\ICrypto
protected static property OC\AppFramework\Http\Request::$csrfTokenManager
Source:lib/private/AppFramework/Http/Request.php#113
Type:\OC\Security\CSRF\CsrfTokenManager | null
protected static property OC\AppFramework\Http\Request::$contentDecoded
Source:lib/private/AppFramework/Http/Request.php#116
Type:bool

Methods

public OC\AppFramework\Http\Request::__construct($vars=[], $secureRandom=null, $config, $csrfTokenManager=null, $stream=php://input)
Source:

lib/private/AppFramework/Http/Request.php#135

Parameters:
  • $vars (array) An associative array with the following optional values:
  • array ‘urlParams’ the parameters which were matched from the URL
  • array ‘get’ the $_GET array
  • array|string ‘post’ the $_POST array or JSON string
  • array ‘files’ the $_FILES array
  • array ‘server’ the $_SERVER array
  • array ‘env’ the $_ENV array
  • array ‘cookies’ the $_COOKIE array
  • string ‘method’ the request method (GET, POST etc)
  • string|false ‘requesttoken’ the requesttoken or false when not available
See:

http://www.php.net/manual/en/reserved.variables.php

public OC\AppFramework\Http\Request::setUrlParameters($parameters)
Source:

lib/private/AppFramework/Http/Request.php#167

Parameters:
  • $parameters (array)
public OC\AppFramework\Http\Request::count()
Countable method
Source:lib/private/AppFramework/Http/Request.php#179
Returns:int
public OC\AppFramework\Http\Request::offsetExists($offset)
ArrayAccess methods
Gives access to the combined GET, POST and urlParams arrays

Examples:

$var = $request[‘myvar’];

or

if(!isset($request[‘myvar’]) {
// Do something
}

$request[‘myvar’] = ‘something’; // This throws an exception.
Source:

lib/private/AppFramework/Http/Request.php#203

Parameters:
  • $offset (string) The key to lookup
Returns:

bool

public OC\AppFramework\Http\Request::offsetGet($offset)
Source:

lib/private/AppFramework/Http/Request.php#212

Parameters:
  • $offset (string)
See:

\OC\AppFramework\Http\offsetExists

Returns:

mixed

public OC\AppFramework\Http\Request::offsetSet($offset, $value)
Source:

lib/private/AppFramework/Http/Request.php#223

Parameters:
  • $offset (string)
  • $value (mixed)
See:

\OC\AppFramework\Http\offsetExists

public OC\AppFramework\Http\Request::offsetUnset($offset)
Source:

lib/private/AppFramework/Http/Request.php#231

Parameters:
  • $offset (string)
See:

\OC\AppFramework\Http\offsetExists

public OC\AppFramework\Http\Request::__set($name, $value)
Magic property accessors
Source:

lib/private/AppFramework/Http/Request.php#240

Parameters:
  • $name (string)
  • $value (mixed)
public OC\AppFramework\Http\Request::__get($name)
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.
Source:

lib/private/AppFramework/Http/Request.php#259

Parameters:
  • $name (string) The key to look for.
Throws:

\LogicException

Returns:

mixed | null

public OC\AppFramework\Http\Request::__isset($name)
Source:

lib/private/AppFramework/Http/Request.php#292

Parameters:
  • $name (string)
Returns:

bool

public OC\AppFramework\Http\Request::__unset($id)
Source:

lib/private/AppFramework/Http/Request.php#302

Parameters:
  • $id (string)
public OC\AppFramework\Http\Request::getHeader($name)
Returns the value for a specific http header.
This method returns null if the header did not exist.
Source:

lib/private/AppFramework/Http/Request.php#314

Parameters:
  • $name (string)
Returns:

string

public OC\AppFramework\Http\Request::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/private/AppFramework/Http/Request.php#353

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

public OC\AppFramework\Http\Request::getParams()
Returns all params that were received, be it from the request
(as GET or POST) or throuh the URL by the route
Source:lib/private/AppFramework/Http/Request.php#364
Returns:array the array with all parameters
public OC\AppFramework\Http\Request::getMethod()
Returns the method of the request
Source:lib/private/AppFramework/Http/Request.php#372
Returns:string the method of the request (POST, GET, etc)
public OC\AppFramework\Http\Request::getUploadedFile($key)
Shortcut for accessing an uploaded file through the $_FILES array
Source:

lib/private/AppFramework/Http/Request.php#381

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

array the file in the $_FILES element

public OC\AppFramework\Http\Request::getEnv($key)
Shortcut for getting env variables
Source:

lib/private/AppFramework/Http/Request.php#390

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

array the value in the $_ENV element

public OC\AppFramework\Http\Request::getCookie($key)
Shortcut for getting cookie variables
Source:

lib/private/AppFramework/Http/Request.php#399

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

string the value in the $_COOKIE element

protected OC\AppFramework\Http\Request::getContent()
Returns the request body content.
If the HTTP request method is PUT and the body
not application/x-www-form-urlencoded or application/json a stream
resource is returned, otherwise an array.
Source:lib/private/AppFramework/Http/Request.php#414
Returns:array | string | resource The request body content or a resource to read the body stream.
Throws:\LogicException
protected OC\AppFramework\Http\Request::decodeContent()
Attempt to decode the content and populate parameters
Source:lib/private/AppFramework/Http/Request.php#439
public OC\AppFramework\Http\Request::passesCSRFCheck()
Checks if the CSRF check was correct
Source:lib/private/AppFramework/Http/Request.php#478
Returns:bool true if CSRF check passed
public OC\AppFramework\Http\Request::getCookieParams()
Wrapper around session_get_cookie_params
Source:lib/private/AppFramework/Http/Request.php#523
Returns:array
protected OC\AppFramework\Http\Request::getProtectedCookieName($name)
Appends the __Host- prefix to the cookie if applicable
Source:

lib/private/AppFramework/Http/Request.php#533

Parameters:
  • $name (string)
Returns:

string

public OC\AppFramework\Http\Request::passesStrictCookieCheck()
Checks if the strict cookie has been sent with the request if the request
is including any cookies.
Source:lib/private/AppFramework/Http/Request.php#550
Returns:bool
Since:9.1.0
public OC\AppFramework\Http\Request::passesLaxCookieCheck()
Checks if the lax cookie has been sent with the request if the request
is including any cookies.
Source:lib/private/AppFramework/Http/Request.php#570
Returns:bool
Since:9.1.0
public OC\AppFramework\Http\Request::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/private/AppFramework/Http/Request.php#588
Returns:string
protected OC\AppFramework\Http\Request::matchesTrustedProxy($trustedProxy, $remoteAddress)
Checks if given $remoteAddress matches given $trustedProxy.
If $trustedProxy is an IPv4 IP range given in CIDR notation, true will be returned if
$remoteAddress is an IPv4 address within that IP range.
Otherwise $remoteAddress will be compared to $trustedProxy literally and the result
will be returned.
Source:lib/private/AppFramework/Http/Request.php#609
Returns:bool true if $remoteAddress matches $trustedProxy, false otherwise
protected OC\AppFramework\Http\Request::isTrustedProxy($trustedProxies, $remoteAddress)
Checks if given $remoteAddress matches any entry in the given array $trustedProxies.
For details regarding what “match” means, refer to `matchesTrustedProxy`.
Source:lib/private/AppFramework/Http/Request.php#629
Returns:bool true if $remoteAddress matches any entry in $trustedProxies, false otherwise
public OC\AppFramework\Http\Request::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/private/AppFramework/Http/Request.php#646
Returns:string IP address
public OC\AppFramework\Http\Request::getServerProtocol()
Returns the server protocol. It respects one or more reverse proxies servers
and load balancers
Source:lib/private/AppFramework/Http/Request.php#688
Returns:string Server protocol (http or https)
public OC\AppFramework\Http\Request::getHttpProtocol()
Returns the used HTTP protocol.
Source:lib/private/AppFramework/Http/Request.php#722
Returns:string HTTP protocol. HTTP/2, HTTP/1.1 or HTTP/1.0.
public OC\AppFramework\Http\Request::getRequestUri()
Returns the request uri, even if the website uses one or more
reverse proxies
Source:lib/private/AppFramework/Http/Request.php#747
Returns:string
public OC\AppFramework\Http\Request::getRawPathInfo()
Get raw PathInfo from request (not urldecoded)
Source:lib/private/AppFramework/Http/Request.php#760
Throws:\Exception
Returns:string Path info
public OC\AppFramework\Http\Request::getPathInfo()
Get PathInfo from request
Source:lib/private/AppFramework/Http/Request.php#805
Throws:\Exception
Returns:string | bool Path info or false when not found
public OC\AppFramework\Http\Request::getScriptName()
Returns the script name, even if the website uses one or more
reverse proxies
Source:lib/private/AppFramework/Http/Request.php#825
Returns:string the script name
public OC\AppFramework\Http\Request::isUserAgent($agent)
Checks whether the user agent matches a given regex
Source:

lib/private/AppFramework/Http/Request.php#842

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

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

public OC\AppFramework\Http\Request::getInsecureServerHost()
Returns the unverified server host from the headers without checking
whether it is a trusted domain
Source:lib/private/AppFramework/Http/Request.php#859
Returns:string Server host
public OC\AppFramework\Http\Request::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/private/AppFramework/Http/Request.php#884
Returns:string Server host