Solr
  1. Solr
  2. SOLR-56

PATCH: JSONResponseWriter JSON result wrapper function

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.1.0
    • Component/s: search
    • Labels:
      None
    • Environment:

      Tested on macosx 10.4.8, JDK 1.5

      Description

      This patch adds a "json.wrf" parameter to add a wrapper function around the JSON results, for example:

      json.wrf = eatJason
      search result = eatJason({"header":

      {"qtime":0}

      ,...}))

      The result set is sent as a parameter to eatJason instead of being sent as a plain data structure.

      This is useful to work around the cross-site limitations of JSON, when a client uses code like

      var head = document.getElementsByTagName("head")[0];
      script = document.createElement('script');
      script.id = 'uploadScript';
      script.type = 'text/javascript';
      script.src = "http://mysolrserver/solr/select?q=role:video&wt=json&json.wrf=eatJason";
      head.appendChild(script)

      function eatJason(obj)

      { ...process obj which is Solr's JSON result }

      However, I'm no javascript expert, and passing an arbitrary javascript function name in the request parameters feels a bit weird...wondering if this might enable some cross-site scripting scenarios?

      But the technique is well-known apparently, see:
      http://www.theurer.cc/blog/2005/12/15/web-services-json-dump-your-proxy/
      and
      http://www.xml.com/pub/a/2005/12/21/json-dynamic-script-tag.html

        Activity

        Hide
        Bertrand Delacretaz added a comment -

        The patch (also includes changes from SOLR-49)

        Show
        Bertrand Delacretaz added a comment - The patch (also includes changes from SOLR-49 )
        Hide
        Yonik Seeley added a comment -

        Thanks Bertrand, interesting stuff!

        Since yahoo calls the parameter "callback", should we call ours "json.callback", or do people think that name is too long? On the other hand, wrapper function is more descriptive about what it does to the actual response. I'm undecided...

        Show
        Yonik Seeley added a comment - Thanks Bertrand, interesting stuff! Since yahoo calls the parameter "callback", should we call ours "json.callback", or do people think that name is too long? On the other hand, wrapper function is more descriptive about what it does to the actual response. I'm undecided...
        Hide
        Bertrand Delacretaz added a comment -

        I though json.wrf was more in line with Solr's usual terseness in parameter names

        And callback does not mean much in that context, I think wrapper function is more precise, it is what this actually does.

        Show
        Bertrand Delacretaz added a comment - I though json.wrf was more in line with Solr's usual terseness in parameter names And callback does not mean much in that context, I think wrapper function is more precise, it is what this actually does.
        Hide
        Yonik Seeley added a comment -

        Yes, it does make more sense. Committed.

        Show
        Yonik Seeley added a comment - Yes, it does make more sense. Committed.
        Hide
        Hoss Man added a comment -

        This bug was modified as part of a bulk update using the criteria...

        • Marked ("Resolved" or "Closed") and "Fixed"
        • Had no "Fix Version" versions
        • Was listed in the CHANGES.txt for 1.1

        The Fix Version for all 38 issues found was set to 1.1, email notification
        was suppressed to prevent excessive email.

        For a list of all the issues modified, search jira comments for this
        (hopefully) unique string: 20080415hossman3

        Show
        Hoss Man added a comment - This bug was modified as part of a bulk update using the criteria... Marked ("Resolved" or "Closed") and "Fixed" Had no "Fix Version" versions Was listed in the CHANGES.txt for 1.1 The Fix Version for all 38 issues found was set to 1.1, email notification was suppressed to prevent excessive email. For a list of all the issues modified, search jira comments for this (hopefully) unique string: 20080415hossman3

          People

          • Assignee:
            Yonik Seeley
            Reporter:
            Bertrand Delacretaz
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development