2i: url encoding/decoding of index names/values
age.mooij at gmail.com
Thu Feb 21 04:42:54 EST 2013
I know, that's the reason why I thought it was probably best to encode the values coming in because otherwise I would have to reject any value coming into my client if it would contain spaces or (especially) commas.
Unfortunately an index fetch (url encoded both name and value) will then never match. How do you encode the index fetch URL in such a way that it matches encoded values?
On Feb 20, 2013, at 22:45, Christian Dahlqvist <christian at basho.com> wrote:
> Hi Age,
> 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
> Best regards,
> 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