tarantool / nginx_upstream_module

Tarantool NginX upstream module (REST, JSON API, websockets, load balancing)
Other
174 stars 18 forks source link

Nginx produces incorrect JSON when tnt_multireturn_skip_count is set to 2 #102

Closed karlovnv closed 6 years ago

karlovnv commented 6 years ago

Tarantool upstream module: v2.5-rc2-docker-dirty Tarantool: 1.7.5-88-g1f73658

Nginx upstream module produces malformed JSON in case of tnt_multireturn_skip_count 2; tnt_pure_result on;

How to reproduce 1) use lua and config provided 2) GET http://localhost:9191/

Expected response:

{"data": {}, "code": 200, "message","hello"}

Actual response (malformed JSON):

{"data":"code","200":"message","hello":}

init.lua

box.cfg({
    listen=3301
})

box.once('gr', function()
    box.schema.user.grant('guest', 'read,write,execute', 'universe')
end)

function httpRequestHandler(req, ...)
    return {
        code=200,
        message="hello",
        data={}
    }
end

Config

... some code ommited

   upstream test {
     server 127.0.0.1:3301 max_fails=1 fail_timeout=1s;
     keepalive 10;
   }

   server {
     listen 9191 default;
     server_name tnt_test;

     location / {
       tnt_pass test;
       tnt_method "httpRequestHandler";
       add_header 'Content-Type' 'application/json; charset=utf-8;';
       tnt_pass_http_request on parse_args;
       tnt_http_rest_methods all;
       tnt_http_methods all;
       tnt_multireturn_skip_count 2;
       tnt_pure_result on;
     }
  }

... some code ommited

Another examples:

This produces incorrect JSON too:
   {
        code=200,
        message="hello",
        data={1,2}
   }
-> {"data":1,"2":"code","200":"message"}

This lua-table leads to correct JSON:
   {
        code=200,
        message="hello",
        data={a=1, b=2}
   }
-> {"data":{"a":1,"b":2},"code":200,"message":"hello"}
dedok commented 6 years ago

It does'nt a bug. I have added some information to the README.md in 7bde62075f6cc7b9b6f03f7b31b466c91e8c7939 I will think about how it could be fixed. Seems better way is validating outgoing JSON if this option is used.

dedok commented 6 years ago

Fixed in 291a05271e92a1c6c4e222d4cba42685232779ee