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

REST simpleserver ignores the moodlewsrestformat parameter

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 3.2.5, 3.3.2, 3.4
    • Fix Version/s: 3.2.6, 3.3.3
    • Component/s: Web Services
    • Labels:
    • Testing Instructions:
      Hide
      1. Enable web services and REST in "Manage protocols"
      2. Enable web services authentication plugin
      3. Enable the mobile web service (or create a new one with the function in it and make it available to selected user)
      4. Make sure a selected user has capability webservice/rest:use
      5. Execute

        curl "http://YOURSITE/webservice/rest/simpleserver.php?wsusername=USERNAME&wspassword=PASSWORD&wsfunction=core_webservice_get_site_info"
        curl "http://YOURSITE/webservice/rest/simpleserver.php?wsusername=USERNAME&wspassword=PASSWORD&wsfunction=core_webservice_get_site_info&moodlewsrestformat=xml"
        curl "http://YOURSITE/webservice/rest/simpleserver.php?wsusername=USERNAME&wspassword=PASSWORD&wsfunction=core_webservice_get_site_info&moodlewsrestformat=json"
        

        Make sure the first two return data in XML and the last one in JSON

      Show
      Enable web services and REST in "Manage protocols" Enable web services authentication plugin Enable the mobile web service (or create a new one with the function in it and make it available to selected user) Make sure a selected user has capability webservice/rest:use Execute curl "http://YOURSITE/webservice/rest/simpleserver.php?wsusername=USERNAME&wspassword=PASSWORD&wsfunction=core_webservice_get_site_info" curl "http://YOURSITE/webservice/rest/simpleserver.php?wsusername=USERNAME&wspassword=PASSWORD&wsfunction=core_webservice_get_site_info&moodlewsrestformat=xml" curl "http://YOURSITE/webservice/rest/simpleserver.php?wsusername=USERNAME&wspassword=PASSWORD&wsfunction=core_webservice_get_site_info&moodlewsrestformat=json" Make sure the first two return data in XML and the last one in JSON
    • Affected Branches:
      MOODLE_32_STABLE, MOODLE_33_STABLE, MOODLE_34_STABLE
    • Fixed Branches:
      MOODLE_32_STABLE, MOODLE_33_STABLE
    • Pull Master Branch:
      wip-MDL-59808-master

      Description

      Short description:
      webservice/rest/simpleserver.php reads moodlewsrestformat parameter and then unsets and ignores it. Therefore there is no way to set JSON encoding for REST protocol in simpleserver.php.

      Long description:

      At same point following code was added to both webservice/rest/simpleserver.php and webservice/rest/server.php:

      $restformat = optional_param('moodlewsrestformat', 'xml', PARAM_ALPHA);
       
      if (isset($_REQUEST['moodlewsrestformat'])) {
      unset($_REQUEST['moodlewsrestformat']);
      }
      if (isset($_GET['moodlewsrestformat'])) {
      unset($_GET['moodlewsrestformat']);
      }
      if (isset($_POST['moodlewsrestformat'])) {
      unset($_POST['moodlewsrestformat']);
      }
       
      $server = new webservice_rest_server(WEBSERVICE_AUTHMETHOD_XXX, $restformat);
      

      webservice/rest/server.php was later refactored - isset / unset lines were removed and $restformat from webservice_rest_server call - but simpleserver.php was not - the isset / unset lines are still there.
      And because webservice_rest_server class checks the data retrieved from GET/POST and moodlewsrestformat is not there anymore, it will always use XML as a format.

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                1 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  13/Nov/17