Hello!
On Wed, Jul 31, 2013 at 12:25 AM, Andrey Oktyabrskiy wrote:
> I have strange problem with ngx.location.capture():
>
> location /usr_info {
> rds_json on;
>
> postgres_escape $whoami =$cookie_whoami;
>
> postgres_pass db_home;
> postgres_query "SELECT name FROM usr WHERE cookie = $whoami";
> postgres_output rds;
> postgres_rewrite no_rows 204;
> }
>
> location /lua {
> default_type 'text/plain';
> content_by_lua '
> local json = ngx.location.capture("/usr_info");
> if json.status == 200 then
> ngx.print(json.body)
> end
> ';
> }
>
> /usr_info returns right result in utf-8 charset.
> /lua returns UTF-16 or UTF-32 or something else.
>
> Can you please to give me some clue where I'm wrong?
It seems that your ngx_lua's capturing filter runs *before*
ngx_rds_json's output filter. So you're getting the binary RDS
formatted data emitted directly from ngx_postgres. What you're seeing
is neither UTF-16 nor UTF-32.
To fix this, you need to get the filter order right by passing the
--add-module=PATH options in the right order to nginx's ./configure
script.
Basically, you should make ngx_lua's filter runs *after*
ngx_rds_json's, so you should put
--add-module=/path/to/lua-nginx-module *before*
--add-module=/path/to/rds-json-nginx-module while building nginx. Yes,
the orders here are reversed because nginx's output filter chain works
like a stack.
BTW, if you're on Linux, you can always use the ngx-body-filters tool
in my Nginx Systemtap Toolkit to get the exact output filter order in
any of your nginx worker process that is serving requests:
https://github.com/agentzh/nginx-systemtap-toolkit#ngx-body-filters
Also, I'm cc'ing the openresty-en mailing list:
https://groups.google.com/group/openresty-en You're also recommended
to join this list and post such questions there.
Thanks!
-agentzh