Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
karlovnv opened this issue Sep 20, 2017 · 2 comments
Closed
Assignees

Comments

@karlovnv
Copy link

karlovnv commented Sep 20, 2017

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 dedok self-assigned this Sep 21, 2017
@dedok dedok added the bug Something isn't working label Sep 21, 2017
@dedok dedok added this to the v2.6 milestone Sep 21, 2017
@dedok
Copy link
Contributor

dedok commented Oct 21, 2017

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

@dedok dedok removed this from the v2.6 milestone Oct 21, 2017
@dedok dedok added enhancement and removed bug Something isn't working labels Oct 21, 2017
dedok added a commit that referenced this issue Dec 18, 2017
@dedok
Copy link
Contributor

dedok commented Dec 18, 2017

Fixed in 291a052

@dedok dedok closed this as completed Dec 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants