CouchDB
  1. CouchDB
  2. COUCHDB-648

_update handler ignores "code" in response doc

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.1.1, 1.2
    • Component/s: Database Core
    • Labels:
    • Environment:

      CouchDB from HEAD

    • Skill Level:
      New Contributors Level (Easy)

      Description

      When using an _update handler, it should be possible to return a response code.

      return [ doc, {
      headers :

      { "Location" : "/" }

      ,
      code : 303,
      body : 'Redirecting'
      }];

      Should return 303 (the redirect for POST) but in fact, on a successful create returns 201. This means it is not possible to use the browser to POST as you cannot redirect on return. This feels like a bug.

      In any case, I would respectfully suggest that the syntax of the _update handler be changed so that there is a store(doc) call (or similar) which returns a JSON object to the update handler so that the handler may redirect appropriately. That would make it possible to do updates client-side with little or no client-side javascript.

      1. 0001-Document-update-handlers-now-honor-code-in-response-.patch
        1 kB
        Jonathan D. Knezek
      2. test.diff
        1 kB
        Christian Carter

        Issue Links

          Activity

          Hide
          Taras Puchko added a comment -

          return [null, {code: 400, headers:

          {"Content-Type" : "text/plain"}

          , body: "Client Error"}] results in "HTTP/1.1 200 OK" instead of 400.

          Show
          Taras Puchko added a comment - return [null, {code: 400, headers: {"Content-Type" : "text/plain"} , body: "Client Error"}] results in "HTTP/1.1 200 OK" instead of 400.
          Hide
          Felix Henninger added a comment -

          I would like to add that this issue persists when the start() method is used (c.f. http://wiki.apache.org/couchdb/Formatting_with_Show_and_List#Sending_a_Redirect ).

          As rnewson commented on IRC, the response code is hardcoded for _updates (couch_httpd_show:send_doc_update_response; http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_show.erl?view=markup#L125), but not for _lists and _shows – creating consistency here would also be helpful.

          In line with the original author, I would personally much appreciate this addition, since it would allow for basic form processing without javascript, and thereby provide graceful degradation for CouchDB-based web apps.

          Show
          Felix Henninger added a comment - I would like to add that this issue persists when the start() method is used (c.f. http://wiki.apache.org/couchdb/Formatting_with_Show_and_List#Sending_a_Redirect ). As rnewson commented on IRC, the response code is hardcoded for _updates (couch_httpd_show:send_doc_update_response; http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_show.erl?view=markup#L125 ), but not for _lists and _shows – creating consistency here would also be helpful. In line with the original author, I would personally much appreciate this addition, since it would allow for basic form processing without javascript, and thereby provide graceful degradation for CouchDB-based web apps.
          Hide
          Jonathan D. Knezek added a comment -

          I've attached a patch that applies to 1.0.2 (but I think applies cleanly to trunk).

          I'm unfortunately not familiar enough (read: at all) with etap to write a test, but the code is quite straightforward.

          Show
          Jonathan D. Knezek added a comment - I've attached a patch that applies to 1.0.2 (but I think applies cleanly to trunk). I'm unfortunately not familiar enough (read: at all) with etap to write a test, but the code is quite straightforward.
          Hide
          Omar Yasin added a comment - - edited

          The _update handler doesn't return the correct headers either.

          Show
          Omar Yasin added a comment - - edited The _update handler doesn't return the correct headers either.
          Hide
          Dirk Geurs added a comment -

          It seems like all other headers are also ignored when the first part of the returned array (the updated or new document) isn't null.

          Another vote from me for fixing this, it's essential to build apps that honor the rules unobtrusive javascript. Unfortunately I lack the Erlang skills to do it myself.

          Show
          Dirk Geurs added a comment - It seems like all other headers are also ignored when the first part of the returned array (the updated or new document) isn't null. Another vote from me for fixing this, it's essential to build apps that honor the rules unobtrusive javascript. Unfortunately I lack the Erlang skills to do it myself.
          Hide
          Michael Coyne added a comment -

          Being able to set response codes for "failed" updates would be very useful. I feel it's more inline with the API overall as well.

          +1 for this feature.

          Show
          Michael Coyne added a comment - Being able to set response codes for "failed" updates would be very useful. I feel it's more inline with the API overall as well. +1 for this feature.
          Hide
          Christian Carter added a comment -

          I've attached a test for this feature!

          Show
          Christian Carter added a comment - I've attached a test for this feature!
          Hide
          Randall Leeds added a comment -

          Fixed on trunk in r1177890.
          Fixed on 1.2.x in r1177891.
          Fixed on 1.1.x in r1177892.

          Show
          Randall Leeds added a comment - Fixed on trunk in r1177890. Fixed on 1.2.x in r1177891. Fixed on 1.1.x in r1177892.
          Hide
          Pulkit Singhal added a comment -

          Can someone update the wiki with the right info?
          Since this has been fixed:
          http://wiki.apache.org/couchdb/Document_Update_Handlers

          Show
          Pulkit Singhal added a comment - Can someone update the wiki with the right info? Since this has been fixed: http://wiki.apache.org/couchdb/Document_Update_Handlers

            People

            • Assignee:
              Randall Leeds
              Reporter:
              Cliff Stanford
            • Votes:
              11 Vote for this issue
              Watchers:
              9 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development