Skip to content

Commit

Permalink
[!!!][TASK] Do not add JSON to header if type equals "json"
Browse files Browse the repository at this point in the history
If you choose "json" as contentType in AJAX-Calls the encoded
json-string will be pushed to the HTTP-Header and will be
outputted on the website. But HTTP-Header is not the right
place for huge json-strings.
So this patch lets "json" works like "jsonbody".

Back in the days, JSON data in the X-JSON header
was for prototypeJS usage, which is now not used
anymore for AJAX requests within the core.

Resolves: #50509
Releases: master
Change-Id: I782cdf2817e30f2e5f016fa92edb06f1e8cbd5b2
Reviewed-on: http://review.typo3.org/22655
Reviewed-by: Nicole Cordes <typo3@cordes.co>
Tested-by: Nicole Cordes <typo3@cordes.co>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Reviewed-by: Jan Helke <typo3@helke.de>
Tested-by: Jan Helke <typo3@helke.de>
Reviewed-by: Benjamin Mack <benni@typo3.org>
Tested-by: Benjamin Mack <benni@typo3.org>
  • Loading branch information
bmack committed Mar 23, 2015
1 parent f8aa3ee commit 3124ebb
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions typo3/sysext/core/Classes/Http/AjaxRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ protected function renderAsXML() {
* in your AJAX options of your AJAX request object in JS
*
* the content will be available
* - in the second parameter of the onSuccess / onComplete callback (except when contentFormat = 'jsonbody')
* - in the second parameter of the onSuccess / onComplete callback
* - and in the xhr.responseText as a string (except when contentFormat = 'jsonhead')
* you can evaluate this in JS with xhr.responseText.evalJSON();
*
Expand All @@ -248,9 +248,11 @@ protected function renderAsXML() {
protected function renderAsJSON() {
$content = json_encode($this->content);
header('Content-type: application/json; charset=utf-8');
header('X-JSON: ' . ($this->contentFormat != 'jsonbody' ? $content : TRUE));
// Bring content in xhr.responseText except when in "json head only" mode
if ($this->contentFormat != 'jsonhead') {
if ($this->contentFormat === 'jsonhead') {
header('X-JSON: ' . $content);
} else {
header('X-JSON: true');
echo $content;
}
}
Expand Down

0 comments on commit 3124ebb

Please sign in to comment.