CouchDB
  1. CouchDB
  2. COUCHDB-1298

X-Couch-Update-NewRev and "ETag" and Content-Type

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Trivial Trivial
    • Resolution: Unresolved
    • Affects Version/s: 1.2
    • Fix Version/s: 2.0.0
    • Component/s: HTTP Interface
    • Labels:
    • Skill Level:
      New Contributors Level (Easy)

      Description

      There are three inconsistencies
      1) The use of ETag vs X-Couch-Update-NewRev
      2) The use of "..." around the rev number
      3) Content-Type: is different, see the space between ;...charset

      PUT /users/_design/user/_update/form/gert HTTP/1.1
      Host: 127.0.0.1:5984

      HTTP/1.1 201 Created
      X-Couch-Update-NewRev: 245-2ddebfc32429bc723cb20543a97d3598
      Server: CouchDB/1.3.0a-f07c75f-git (Erlang OTP/R13B03)
      Date: Wed, 28 Sep 2011 15:49:49 GMT
      Content-Type: text/html; charset=utf-8
      Content-Length: 8

      PUT /users/gert/picture.png HTTP/1.1
      Host: 127.0.0.1:5984

      HTTP/1.1 201 Created
      Server: CouchDB/1.3.0a-f07c75f-git (Erlang OTP/R13B03)
      Location: http://127.0.0.1:5984/users/gert/picture.png
      ETag: "246-f1291707f1827ef38217972ea1f3824c"
      Date: Wed, 28 Sep 2011 15:50:25 GMT
      Content-Type: text/plain;charset=utf-8
      Content-Length: 69
      Cache-Control: must-revalidate

      Pleas always use ETag without "..."
      When a new document is been created, also use ETag because its already indicated by status 201, no need for special headers.

      Also note Content-Type: is different, see the space between ;...charset

        Activity

        Hide
        Randall Leeds added a comment -

        I suspect X-Couch-Update-NewRev was added so that the revision could be returned even if the _update handler decides to provide its own ETag in the response and to leave the revision out of the response body. I will make the new revision the default ETag in the response headers for _update functions if the function author does not provide one explicitly. Thanks.

        Note that a proper ETag should be surround by quotes, so that will not change: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.19

        Show
        Randall Leeds added a comment - I suspect X-Couch-Update-NewRev was added so that the revision could be returned even if the _update handler decides to provide its own ETag in the response and to leave the revision out of the response body. I will make the new revision the default ETag in the response headers for _update functions if the function author does not provide one explicitly. Thanks. Note that a proper ETag should be surround by quotes, so that will not change: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.19
        Hide
        gert cuykens added a comment -

        ok thanks

        I tried to create a ETag manually but that does not seem to work?
        "updates":{"form":"function(doc,req){for(i in req.form)doc[i]=req.form[i];return [doc,{headers:

        {'Content-Type':'application/json','ETag':doc._rev}

        ,body:'

        {ok:201}

        '}]}"},

        Also check Content-Type: text/plain;...charset=utf-8 of the PUT /users/gert/picture.png HTTP/1.1 pleas
        http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17

        Show
        gert cuykens added a comment - ok thanks I tried to create a ETag manually but that does not seem to work? "updates":{"form":"function(doc,req){for(i in req.form)doc [i] =req.form [i] ;return [doc,{headers: {'Content-Type':'application/json','ETag':doc._rev} ,body:' {ok:201} '}]}"}, Also check Content-Type: text/plain;...charset=utf-8 of the PUT /users/gert/picture.png HTTP/1.1 pleas http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17
        Hide
        Benoit Chesneau added a comment - - edited

        this not an inconsistancy. The reason we don't put it as an etag is that you don't want to cache a post or a put results, since the results will likely change each time.

        Show
        Benoit Chesneau added a comment - - edited this not an inconsistancy. The reason we don't put it as an etag is that you don't want to cache a post or a put results, since the results will likely change each time.
        Hide
        gert cuykens added a comment - - edited

        ok, but the second PUT or normal PUT/POST should also use X-Couch-Update-NewRev then and not ETag. So to be consistent only GET should return a ETag, everything else X-Couch-Update-NewRev. Aldo you can GET a update too. I think ETag is still the best way. To cache or not is something the browser should implement. Everything you read from a database should be considered likely too change anyway. For example I am likely to change my avatar more then I would change my name But as long as the admin is able to overwrite the ETag on every request it is also fine. Currently only couchdb has full control over the ETag.

        Show
        gert cuykens added a comment - - edited ok, but the second PUT or normal PUT/POST should also use X-Couch-Update-NewRev then and not ETag. So to be consistent only GET should return a ETag, everything else X-Couch-Update-NewRev. Aldo you can GET a update too. I think ETag is still the best way. To cache or not is something the browser should implement. Everything you read from a database should be considered likely too change anyway. For example I am likely to change my avatar more then I would change my name But as long as the admin is able to overwrite the ETag on every request it is also fine. Currently only couchdb has full control over the ETag.
        Hide
        Randall Leeds added a comment -

        I'm in favor of leaving X-Couch-Update-NewRev for update requests only to maintain compatibility until 2.0. That's on principle only, because I expect almost no one relies on it now. Still, I'll leave it.

        I think it's okay to send back an ETag for PUT/POST, because maybe you want to do a conditional GET later.
        I'm implementing all these fixes now and well as fixing some other tickets related to response codes and headers from _show/_list/_update.

        Show
        Randall Leeds added a comment - I'm in favor of leaving X-Couch-Update-NewRev for update requests only to maintain compatibility until 2.0. That's on principle only, because I expect almost no one relies on it now. Still, I'll leave it. I think it's okay to send back an ETag for PUT/POST, because maybe you want to do a conditional GET later. I'm implementing all these fixes now and well as fixing some other tickets related to response codes and headers from _show/_list/_update.

          People

          • Assignee:
            Randall Leeds
            Reporter:
            gert cuykens
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:

              Time Tracking

              Estimated:
              Original Estimate - 1h
              1h
              Remaining:
              Remaining Estimate - 1h
              1h
              Logged:
              Time Spent - Not Specified
              Not Specified

                Development