On Mon, Aug 13, 2012 at 11:42 PM, Tzury Bar Yochay <tz...@reblaze.com> wrote:
>> $ curl localhost/redis_test/1
>> bulk reply
>> $ curl localhost/redis_test/2
>> bulk reply
The Lua totring() built-in function will not automatically quote
non-printable characters like "\x02" in your Lua string like
redis-cli. So the raw byte is emitted directly to your HTTP client and
is displayed on your terminal.
You can confirm this by using the "od" utility to display special
chars in the curl output, like this:
$ curl -s localhost/redis_test/2 | od -c
And the actual output on my side is
0000000 2 0 0 \n $ 1 \r \n 002 \r \n \n b u l k
0000020 r e p l y \n [ 002 ] \n
We can see that there are indeed a byte whose value is 002 between the
two square brackets on the 2nd line and also one such byte after the
first CR LF sequence on the 1st line.
Another way to confirm this is to print out the byte code on the Lua land, as in
ngx.say("byte code: ", string.format("0x%02x", string.byte(reply)))
And then you should get the output
byte code: 0x02
Yet another way is to use the lua-cjson library to quote the Lua string for you:
local cjson = require "cjson"
ngx.say("json value: ", cjson.encode(reply))
And you'll get this:
json value: "\u0002"
Yeah, there's surely millions of other ways ;)
You can try any or all the tests above. But please don't claim that
the reply string is empty just because you cannot see anything on your
terminal ;) (In fact, my terminal on Fedora Linux can actually display
that character with some special stub.)