CouchDB
  1. CouchDB
  2. COUCHDB-463

Allow client to insist on Content-Type: application/json in all responses

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: HTTP Interface
    • Labels:
      None
    • Skill Level:
      Regular Contributors Level (Easy to Medium)

      Description

      The Content-Type of responses is negotiated via Accept (application/json if acceptable, text/plain if not). When the client is the browser, this often fails as the Accept line usually does not include application/json.

      Consider a query parameter to force application/json responses even without the Accept header. Couchdb-lucene does this today (it didn't do it yesterday), described as;

      "force_json
      Usually couchdb-lucene determines the Content-Type of its response based on the presence of the Accept header. If Accept contains "application/json", you get "application/json" in the response, otherwise you get "text/plain;charset=utf8". Some tools, like JSONView for FireFox, do not send the Accept header but do render "application/json" responses if received. Setting force_json=true forces all response to "application/json" regardless of the Accept header."

      I recognize it duplicates the HTTP content negotiation.

        Activity

        Paul Joseph Davis made changes -
        Skill Level Regular Contributors Level (Easy to Medium)
        Adam Kocoloski made changes -
        Field Original Value New Value
        Component/s HTTP Interface [ 12312234 ]
        Hide
        Michael J. Giarlo added a comment -

        FYI, the JSONovich add-on for Firefox explicitly sends the application/json type in the Accept header as of version 1.1, so it operates as expected with CouchDB.

        JSONovich: https://addons.mozilla.org/en-US/firefox/10122

        Version 1.1 is in the sandbox, so it's not yet up on mozilla.org, but it's available via http://lackoftalent.org/michael/blog/json-in-firefox/

        Show
        Michael J. Giarlo added a comment - FYI, the JSONovich add-on for Firefox explicitly sends the application/json type in the Accept header as of version 1.1, so it operates as expected with CouchDB. JSONovich: https://addons.mozilla.org/en-US/firefox/10122 Version 1.1 is in the sandbox, so it's not yet up on mozilla.org, but it's available via http://lackoftalent.org/michael/blog/json-in-firefox/
        Hide
        Robert Newson added a comment -

        I did;

        "Some tools, like JSONView for FireFox, do not send the Accept header but do render "application/json" responses if received."

        That is, there is at least one plugin that can render returned JSON better than text/plain that does not (or cannot? I don't know firefox plugin API) send the Accept header couchdb expects.

        I've added force_json=true to couchdb-lucene as the API there is much smaller (you can query the index, that's about it) so I didn't have any qualms about adding another parameter for these rare cases. If this parameter lets users work around bugs or deficiencies in their browsers or tools, I'm fine with that. Obviously the Accept header is the way to go if you access couch programatically which is the typical case.

        JSONView: https://addons.mozilla.org/en-US/firefox/addon/10869

        Show
        Robert Newson added a comment - I did; "Some tools, like JSONView for FireFox, do not send the Accept header but do render "application/json" responses if received." That is, there is at least one plugin that can render returned JSON better than text/plain that does not (or cannot? I don't know firefox plugin API) send the Accept header couchdb expects. I've added force_json=true to couchdb-lucene as the API there is much smaller (you can query the index, that's about it) so I didn't have any qualms about adding another parameter for these rare cases. If this parameter lets users work around bugs or deficiencies in their browsers or tools, I'm fine with that. Obviously the Accept header is the way to go if you access couch programatically which is the typical case. JSONView: https://addons.mozilla.org/en-US/firefox/addon/10869
        Hide
        Chris Anderson added a comment -

        It might help motivate the patch to describe a use case where sending text/plain causes issues for clients (who can't send json headers anyway)

        Not saying it's a bad thing to fix, just looking for a concrete use case.

        Show
        Chris Anderson added a comment - It might help motivate the patch to describe a use case where sending text/plain causes issues for clients (who can't send json headers anyway) Not saying it's a bad thing to fix, just looking for a concrete use case.
        Robert Newson created issue -

          People

          • Assignee:
            Unassigned
            Reporter:
            Robert Newson
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:

              Development