tarantool / nginx_upstream_module

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

http headears and status example is ambiguous for me #96

Closed SWSAmor closed 7 years ago

SWSAmor commented 7 years ago

I followed the instructions in https://github.com/tarantool/nginx_upstream_module#http-headers-and-status but i think it's a bit ambiguous:

I don't get any body with

tnt_pass_http_request on parse_args;

but get body with

tnt_pass_http_request on parse_args pass_body;

this way i get

{"params": [...]}

with the body, but i need body without that. That's because i don't understand hide in this:

-- hide `{"params": [...]}` from a user
ngx.req.read_body()
local body = ngx.req.get_body_data()
if body then
    body = "{\\"params\\": [" .. body .. "]}"
end

because it says hide {"params": [...]} from a user, but without the

if body then
    body = "{\\"params\\": [" .. body .. "]}"
end

it works flawlessly.

Perhaps my bad. Sry.

dedok commented 7 years ago

Hi,

sorry for the late answer (deals & vacation)

tnt_pass_http_request on parse_args;

parse_args means that nginx will do parsing query args and those parsed args will be added into the req table (it's first argument).

tnt_pass_http_request on parse_args pass_body;

pass_body means that nginx will not parse body by using JSON parser. The body will be in the req table. This option exists only for passing non standard data, like image and so on.

If this options is not set, then nginx will wait for JSON in the body ({"params": [1, 2, {"str": 1}]}) the body will be in Lua like:

function foo(req, one, two, obj)
 one -- = 1
 two -- = 2
 obj.str -- =  1
end
SWSAmor commented 7 years ago

Thank you for the clarification. What will be happening if i do not set pass_body, and the body is empty or not a json?

dedok commented 7 years ago

Well, you will have 'bad request' at client side. If be honestly I don't like 'pass_body' feature, that function appeared because some of my users wish to have some method to transfer image into the tarantool over https. It was fast hack...

Nowadays I'm tring to add more types of body, for instance nginx can transfer urlencoded.

If you have some good ideas you are welcome, feel free and create an issue :)

SWSAmor commented 7 years ago

I'm developing an API based on JSON API and i should and want to control most of the responses. For JSON API custom statuses and custom response bodies needed. Because of that i should get all of bodies and need to analyze them on the Tarantool side. Actually my work based on pass body. :-) I think i love pass_body. ;-) Very good fast hack, thank you. 👍