diff options
author | Vincent Petry <pvince81@owncloud.com> | 2013-12-12 11:32:56 +0100 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2013-12-19 18:40:22 +0100 |
commit | 09bd5bd517fee80e8b44b7645b51a8ba482a4d7c (patch) | |
tree | f61ac99c6d759701a723b1fee9ea09d90941b492 /lib | |
parent | 82bf1f9c8ccbfed39790d22b2fbea2c5286122dc (diff) | |
download | nextcloud-server-09bd5bd517fee80e8b44b7645b51a8ba482a4d7c.tar.gz nextcloud-server-09bd5bd517fee80e8b44b7645b51a8ba482a4d7c.zip |
Added isUserAgent() method to request
- added isUserAgent() method to OC_Request which makes it possible to
test it
- OC_Response::setContentDisposition now uses OC_Request::isUserAgent()
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/private/request.php | 23 | ||||
-rw-r--r-- | lib/private/response.php | 3 |
2 files changed, 24 insertions, 2 deletions
diff --git a/lib/private/request.php b/lib/private/request.php index b2afda35922..d9d5ae08e28 100755 --- a/lib/private/request.php +++ b/lib/private/request.php @@ -7,6 +7,11 @@ */ class OC_Request { + + const USER_AGENT_IE = '/MSIE/'; + // Android Chrome user agent: https://developers.google.com/chrome/mobile/docs/user-agent + const USER_AGENT_ANDROID_MOBILE_CHROME = '#Android.*Chrome/[.0-9]*#'; + /** * @brief Check overwrite condition * @param string $type @@ -210,4 +215,22 @@ class OC_Request { return false; } } + + /** + * Checks whether the user agent matches a given regex + * @param string|array $agent agent name or array of agent names + * @return boolean true if at least one of the given agent matches, + * false otherwise + */ + static public function isUserAgent($agent) { + if (!is_array($agent)) { + $agent = array($agent); + } + foreach ($agent as $regex) { + if (preg_match($regex, $_SERVER['HTTP_USER_AGENT'])) { + return true; + } + } + return false; + } } diff --git a/lib/private/response.php b/lib/private/response.php index c6edda0f949..04746437347 100644 --- a/lib/private/response.php +++ b/lib/private/response.php @@ -153,8 +153,7 @@ class OC_Response { * @param string $type disposition type, either 'attachment' or 'inline' */ static public function setContentDispositionHeader( $filename, $type = 'attachment' ) { - // Android Chrome user agent: https://developers.google.com/chrome/mobile/docs/user-agent - if ( preg_match( '/MSIE/', $_SERVER['HTTP_USER_AGENT'] ) or preg_match( '#Android.*Chrome/[.0-9]*#', $_SERVER['HTTP_USER_AGENT'] ) ) { + if (OC_Request::isUserAgent(array(OC_Request::USER_AGENT_IE, OC_Request::USER_AGENT_ANDROID_MOBILE_CHROME))) { header( 'Content-Disposition: ' . rawurlencode($type) . '; filename="' . rawurlencode( $filename ) . '"' ); } else { header( 'Content-Disposition: ' . rawurlencode($type) . '; filename*=UTF-8\'\'' . rawurlencode( $filename ) |