Uploaded image for project: 'CouchDB'
  1. CouchDB
  2. COUCHDB-2673

"Location" header in HTTP response should properly encode the document _id

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 1.6.1
    • 2.0.0, 1.7.0
    • HTTP Interface
    • None

    Description

      When inserting a document in a CouchDB 1.6.1 database, the response sent by CouchDB contains a "Location" HTTP header with the URI of the newly created document.

      However, if the "_id" of the new document contains non-ASCII characters, this "Location" header is not properly encoded.

      Example:

       % curl -v -H "Content-Type: application/json" -X POST http://localhost:5984/test/ --data '{"_id": "xxxé"}'
      *   Trying ::1...
      * Connected to localhost (::1) port 5984 (#0)
      > POST /test/ HTTP/1.1
      > Host: localhost:5984
      > User-Agent: curl/7.42.0
      > Accept: */*
      > Content-Type: application/json
      > Content-Length: 16
      > 
      * upload completely sent off: 16 out of 16 bytes
      < HTTP/1.1 201 Created
      < Server: CouchDB/1.6.1 (Erlang OTP/17)
      < Location: http://localhost:5984/test/xxxé
      < ETag: "1-967a00dff5e02add41819138abb3284d"
      < Date: Sat, 25 Apr 2015 21:33:04 GMT
      < Content-Type: text/plain; charset=utf-8
      < Content-Length: 68
      < Cache-Control: must-revalidate
      < 
      {"ok":true,"id":"xxxé","rev":"1-967a00dff5e02add41819138abb3284d"}
      

      According to RFC 2616 ("HTTP headers only contain ASCII") and RFC 2396 ("here is how to construct an URI from ASCII characters"), the "Location" header should be formatted as:

      Location: http://localhost:5984/test/xxx%C3%A9
      

      The "spray.io" framework warns against this invalid response when doing such a request towards a CouchDB database.

      Attachments

        Activity

          People

            Unassigned Unassigned
            sam@rfc1149.net Samuel Tardieu
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: