2i: url encoding/decoding of index names/values
christian at basho.com
Wed Feb 20 16:45:08 EST 2013
One thing to consider is that Riak allows a secondary index to have multiple values. I can e.g. create an object with two values for a integer secondary index as follows:
curl -X PUT -H "Content-Type: text/plain" -H 'x-riak-index-idx_int: 12' -H 'x-riak-index-idx_int: 13' -d 'data' http://localhost:8098/buckets/testbucket/keys/key2
When this object is retrieved, the secondary index with the two values will/may be presented in a single header containing a comma and a space to separate the values as follows:
curl -v -X HEAD http://localhost:8098/buckets/testbucket/keys/key2
< HTTP/1.1 200 OK
< X-Riak-Vclock: a85hYGBgzGDKBVIcEQaWHIFK0u0ZTImMeawMRntnnuLLAgA=
< x-riak-index-idx_int: 12, 13
< Vary: Accept-Encoding
< Server: MochiWeb/1.1 WebMachine/1.9.0 (someone had painted it blue)
< Link: </buckets/testbucket>; rel="up"
< Last-Modified: Wed, 20 Feb 2013 21:33:38 GMT
< ETag: "3Wz7RJnOL4ofIeX1hYDr84"
< Date: Wed, 20 Feb 2013 21:40:30 GMT
< Content-Type: text/plain
< Content-Length: 4
On 20 Feb 2013, at 20:56, Age Mooij <age.mooij at gmail.com> wrote:
> Hi all,
> I'm writing a new Scala (http) client library for Riak  and I ran into some trouble with special characters while implementing 2i.
> Reading through the docs, all the 2i examples are for simple one-word index names but I have not been able to find any rules about index names and values containing spaces, commas, and other special characters and how the HTTP api deals with encoding and decoding these?
> My unit tests use the following troublesome corner cases:
> - index values containing spaces
> - index names containing spaces
> - index values containing commas
> I tried a number of approaches and none of them work for all three:
> 1) Don't encode the index names or the values when creating "x-riak-index-" http headers but encode both the name and the value in the URL used to fetch by an index
> This works fine for values containing spaces but creates illegal headers for index names containing spaces and breaks for values containing commas (the values get split into two).
> 2) Encode everything
> This creates valid headers and storing index values containing commas now works fine. The only trouble is that index fetching fails whenever there are spaces, commas or other encoded characters involved.
> Could anyone enlighten me about the correct way to deal with these cases?
>  https://github.com/agemooij/riak-scala-client
> riak-users mailing list
> riak-users at lists.basho.com
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the riak-users