/** * Prepares the start of an AJAX output. */ public function header() { // unfortunately YUI iframe upload does not support application/json if (!empty($_FILES)) { @header('Content-type: text/plain; charset=utf-8'); if (!core_useragent::supports_json_contenttype()) { @header('X-Content-Type-Options: nosniff'); } } else if (!core_useragent::supports_json_contenttype()) { @header('Content-type: text/plain; charset=utf-8'); @header('X-Content-Type-Options: nosniff'); } else { @header('Content-type: application/json; charset=utf-8'); } // Headers to make it not cacheable and json @header('Cache-Control: no-store, no-cache, must-revalidate'); @header('Cache-Control: post-check=0, pre-check=0', false); @header('Pragma: no-cache'); @header('Expires: Mon, 20 Aug 1969 09:23:00 GMT'); @header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); @header('Accept-Ranges: none'); }
define('NO_MOODLE_COOKIES', false); } } } } } // Start session and prepare global $SESSION, $USER. if (empty($CFG->sessiontimeout)) { $CFG->sessiontimeout = 7200; } \core\session\manager::start(); // Set default content type and encoding, developers are still required to use // echo $OUTPUT->header() everywhere, anything that gets set later should override these headers. // This is intended to mitigate some security problems. if (AJAX_SCRIPT) { if (!core_useragent::supports_json_contenttype()) { // Some bloody old IE. @header('Content-type: text/plain; charset=utf-8'); @header('X-Content-Type-Options: nosniff'); } else { if (!empty($_FILES)) { // Some ajax code may have problems with json and file uploads. @header('Content-type: text/plain; charset=utf-8'); } else { @header('Content-type: application/json; charset=utf-8'); } } } else { if (!CLI_SCRIPT) { @header('Content-type: text/html; charset=utf-8'); }
/** * @dataProvider user_agents_providers */ public function test_useragent_supports($useragent, $tests) { // Setup the core_useragent instance. core_useragent::instance(true, $useragent); // Supports SVG. if (!isset($tests['supports_svg']) || $tests['supports_svg']) { $this->assertTrue(core_useragent::supports_svg(), "SVG Support was not reported (and should have been)"); } else { $this->assertFalse(core_useragent::supports_svg(), "SVG Support was reported (and should not have been)"); } // Supports JSON ContentType. if (!isset($tests['supports_json_contenttype']) || $tests['supports_json_contenttype']) { $this->assertTrue(core_useragent::supports_json_contenttype(), "JSON ContentType Support was not reported (and should have been)"); } else { $this->assertFalse(core_useragent::supports_json_contenttype(), "JSON ContentType Support was reported (and should not have been)"); } }