Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-72080

Content-Type wrong for core_get_fragment

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 3.11
    • Fix Version/s: None
    • Component/s: Libraries
    • Labels:
    • Affected Branches:
      MOODLE_311_STABLE

      Description

      In response to the XHR request to core_get_fragment the Moodle response has HTTP header Content-Type set to "text/html; charset=utf-8". But this function returns JSON so presumably the MIME type should be "application/json".

      This causes an error in Moodle if there's some HTML processing between the web server and the browser, for example Apache's mod_proxy_html. Moodle sends JSON in reply to core_get_fragment:

      [{"error":false,"data":{"html":...

      But the HTML proxy sees the "text/html" MIME type and processes the output so it becomes:

      <html><body><p>[{"error":false,"data":{"html":...

      Obviously this is no longer JSON so in the browser you get an error: JSON.parse: unexpected character at line 1 column 1 of the JSON data. This thread is an example of this issue.

      To reproduce the problem

      (These steps shows the incorrect MIME type, not the HTML proxy issue resulting in the above error message).

      1. In Moodle go to the Participants page of a course.
      2. In your browser open the developer tools and switch to the network monitor.
      3. Click Enrol users.
      4. In the network monitor click on the request /lib/ajax/service.php?sesskey=...&info=core_get_fragment. Examine the response headers and check the Content-Type header.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              leonstr Leon Stringer
              Participants:
              Component watchers:
              Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Ilya Tregubov, Sara Arjona (@sarjona)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated: