Download & Extend

json output must use correct mime-type

Project:Drupal core
Version:6.x-dev
Component:base system
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs review

Issue Summary

The function drupal_json() in common.inc sets the headers for a JSON response. Currently it uses an old mime-type for javascript, text/javascript, when it's actually a JSON response which I think should be using the JSON-mime-type, application/json.

JSON has it's origin in javascript - but is a format understandable by practically all languages. The mime-type should reflect that so consumers of the content will be given the right signal about what content it has recieved - because consumers of real JSON shouldn't treat it as javascript because of security reasons.

I'm attaching a patch that changes this.

If the mime-type for some reasons should be kept as javascript - then the mime-type should at least be changed to application/javascript - since text/javascript is considered obsolete. Read more about that in: http://en.wikipedia.org/wiki/Internet_media_type

AttachmentSizeStatusTest resultOperations
drupal_json_mime_type.patch608 bytesIdleFailed: Failed to apply patch.View details | Re-test

Comments

#1

Status:needs review» needs work

The last submitted patch failed testing.

#2

Status:needs work» needs review

Rerolling the patch - apparently the test bot didn't like git's formatting of it...

AttachmentSizeStatusTest resultOperations
drupal_json_mime_type.patch489 bytesIdleFailed: Failed to install HEAD.View details | Re-test

#3

Status:needs review» needs work

AFAICT from RFC 4627, the charset parameter is not allowed with application/json. For comparison, see RFC 4329 that explicitly mentions charset as an optional parameter.

#4

Status:needs work» needs review

Ah - that's interesting - great that valid JSON needs to be UTF-8 encoded!

I'm attaching a new patch that removes the charset from the header.

AttachmentSizeStatusTest resultOperations
drupal_json_mime_type_3.patch504 bytesIdleFailed: 10267 passes, 1 fail, 0 exceptionsView details | Re-test

#5

Appearently IE has some issues with application/json:
http://www.entwicklungsgedanken.de/2008/06/06/problems-with-internet-exp...

Not sure whether this is relevant for Drupal, though.

#6

I haven't come across any problems with IE, AJAX-requests and application/json - I believe that blogger does something wrong.

You can try out a non-drupal site I've built that uses application/json (although with the incorrect charset which I hadn't noticed when the site was built): http://www.bergkrantz.se/projekt/lista

#7

Status:needs review» needs work

The last submitted patch failed testing.

#8

Status:needs work» needs review

Reroll

AttachmentSizeStatusTest resultOperations
drupal_json_mime_type_4.patch587 bytesIdleFailed: Failed to install HEAD.View details | Re-test

#9

Status:needs review» needs work

The last submitted patch failed testing.

#10

drupal_set_header() was just renamed to drupal_add_http_header() in #451604: Rename drupal_set_header().

#11

Title:drupal_json() should use correct mime-type» drupal_json_output() should use correct mime-type
Status:needs work» needs review

Given that Drupal’s current behaviour is in violation of RFC 4627 that clearly states “The MIME media type for JSON text is application/json.” as defined by IANA, I’m taking the liberty of elevating this to critical.

I’ve attached a new patch. Easy fix :)

AttachmentSizeStatusTest resultOperations
2010-05-01-json-content-type.patch1.09 KBIdlePASSED: [[SimpleTest]]: [MySQL] 20,157 pass(es).View details | Re-test

#12

Title:drupal_json_output() should use correct mime-type» drupal_json_output() must use correct mime-type
Priority:normal» critical

Elevating to critical.

#13

This patch changes the comment, as in the above version. The patch looks fine.

AttachmentSizeStatusTest resultOperations
2010-05-01-json-content-type.patch633 bytesIdlePASSED: [[SimpleTest]]: [MySQL] 20,155 pass(es).View details | Re-test

#14

Priority:critical» normal
Status:needs review» reviewed & tested by the community

This doesn't break anything, and as a consequence is not critical.

Otherwise, I'm fine with the change.

#15

Status:reviewed & tested by the community» needs work

The last submitted patch, 2010-05-01-json-content-type.patch, failed testing.

#16

Status:needs work» needs review

retest

#17

#13: 2010-05-01-json-content-type.patch queued for re-testing.

#18

Status:needs review» needs work

The last submitted patch, 2010-05-01-json-content-type.patch, failed testing.

#19

Status:needs work» needs review

#13: 2010-05-01-json-content-type.patch queued for re-testing.

#20

Status:needs review» reviewed & tested by the community

Well, the test checked out, and it’s been manually reviewed, so I suppose this is RTBC.

#21

Is it intentionally that the feedback from #3 has been ignored?

#22

#21: No, I managed to miss that, sorry. Here’s a new patch which should be compliant.

AttachmentSizeStatusTest resultOperations
2010-05-04-json-content-type.patch836 bytesIdlePASSED: [[SimpleTest]]: [MySQL] 20,154 pass(es).View details | Re-test

#23

Status:reviewed & tested by the community» fixed

Committed to CVS HEAD. Thanks.

#24

Status:fixed» closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

#25

Title:drupal_json_output() must use correct mime-type» json output must use correct mime-type
Version:7.x-dev» 6.x-dev
Status:closed (fixed)» patch (to be ported)

Reopening for backport to D6.

#26

This is an API-change so I don't think it should be allowed into D6.

#27

Create for D6 module work with JSON, to not change API))

#28

Status:patch (to be ported)» needs review

D6 backport.

AttachmentSizeStatusTest resultOperations
json_content_type-341588-d6-28.patch600 bytesIdlePASSED: [[SimpleTest]]: [MySQL] 190 pass(es).View details | Re-test
nobody click here