Skip to content

Commit

Permalink
Set correct content type for JSON responses
Browse files Browse the repository at this point in the history
Signed-off-by: Michal Čihař <michal@cihar.com>
  • Loading branch information
nijel committed Jan 19, 2016
1 parent dbb2673 commit 0a24f92
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 12 deletions.
6 changes: 3 additions & 3 deletions import_status.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@
}
*/

// AJAX requests can't be cached!
PMA_noCacheHeader();

// $_GET["message"] is used for asking for an import message
if (isset($_GET["message"]) && $_GET["message"]) {

// AJAX requests can't be cached!
PMA_noCacheHeader();

header('Content-type: text/html');

// wait 0.3 sec before we check for $_SESSION variable,
Expand Down
5 changes: 1 addition & 4 deletions libraries/Response.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,7 @@ private function _ajaxResponse()

// Set the Content-Type header to JSON so that jQuery parses the
// response correctly.
if (! defined('TESTSUITE')) {
header('Cache-Control: no-cache');
header('Content-Type: application/json');
}
PMA_headerJSON();

echo json_encode($this->_JSON);
}
Expand Down
20 changes: 20 additions & 0 deletions libraries/core.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,26 @@ function PMA_sendHeaderLocation($uri, $use_refresh = false)
}
}

/**
* Outputs application/json headers. This includes no caching.
*
* @return void
*/
function PMA_headerJSON()
{
if (defined('TESTSUITE') && ! defined('PMA_TEST_HEADERS')) {
return;
}
// No caching
PMA_noCacheHeader();
// MIME type
header('Content-Type: application/json; charset=UTF-8');
// Disable content sniffing in browser
// This is needed in case we include HTML in JSON, browser might assume it's
// html to display
header('X-Content-Type-Options: nosniff');
}

/**
* Outputs headers to prevent caching in browser (and on the way).
*
Expand Down
2 changes: 1 addition & 1 deletion libraries/display_import_ajax.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function PMA_Import_nopluginCheck()
*/
function PMA_importAjaxStatus($id)
{
header('Content-type: application/json');
PMA_headerJSON();
echo json_encode(
$_SESSION[$GLOBALS['SESSION_KEY']]['handler']::getUploadStatus($id)
);
Expand Down
5 changes: 3 additions & 2 deletions lint.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
$sql_query = !empty($_POST['sql_query']) ? $_POST['sql_query'] : '';

// Disabling standard response.
$response = PMA_Response::getInstance();
$response->disable();
PMA_Response::getInstance()->disable();

PMA_headerJSON();

echo json_encode(PMA_Linter::lint($sql_query));
2 changes: 2 additions & 0 deletions normalization.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
$dependencies = json_decode($_REQUEST['pd']);
$tables = json_decode($_REQUEST['tables']);
$newTables = PMA_getHtmlForNewTables3NF($dependencies, $tables, $db);
PMA_Response::getInstance()->disable();
PMA_headerJSON();
echo json_encode($newTables);
exit;
}
Expand Down
2 changes: 1 addition & 1 deletion setup/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
$validators = array();
require './libraries/config/Validator.class.php';

header('Content-type: application/json');
PMA_headerJSON();

$ids = isset($_POST['id']) ? $_POST['id'] : null;
$vids = explode(',', $ids);
Expand Down
2 changes: 1 addition & 1 deletion version_check.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
require_once 'libraries/VersionInformation.php';

// Always send the correct headers
header('Content-type: application/json; charset=UTF-8');
PMA_headerJSON();

$versionInformation = new VersionInformation();
$versionDetails = $versionInformation->getLatestVersion();
Expand Down

0 comments on commit 0a24f92

Please sign in to comment.