tarantool / nginx_upstream_module

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

Add abbility to change HTTP reply code from LUA procedure. #74

Closed amdei closed 7 years ago

amdei commented 7 years ago

It would be quite nice to have abbility to send arbitrary HTTP reply code from within called LUA procedure.

In particular, it will make possible to utilize http://nginx.org/en/docs/http/ngx_http_auth_request_module.html for access control, based on result of LUA function invocation.

AFAICS, we could control only reply body so far. If this feature already available, would be good to see example in readme.

dedok commented 7 years ago

This feature does not exist. Basically it is hard to implement due to Tarantool binary protocol limitations and nginx upstream phases synchronisation.

So I thought about this feature a lot and I have the only one idea. if I share it with you can you implement it? :)

P.S. This feature does not have high priority at the moment.

amdei commented 7 years ago
if I share it with you can you implement it?

Will do my best!

dedok commented 7 years ago

The first part is

Before we go any further you have to read this one:

Tarantool iproto: https://tarantool.org/doc/dev_guide/internals_index.html

So there are have few problems:

1) Tarantool does not produce headers or stutes in own headers, information passed via body. That is a pain, because nginx has phases handlers. For instance nginx sends http headers and status right after process_headers, but Tarantool may not return full body in this stage due to may reasons. (src/ngx_http_tnt_handlers.c:972)

2) Tarantool has greeting, which needs sync with phases handlers.

3) Tarantool's response may return in many buffers due to network issues and configuration.

Possible implementation is: Tarantool protocol does not good for classical STATUS HEADERS BODY.

How could it be fixed?

Well. All problems could be solved by re-implement nginx socket handlers (i.e. write/read to upstream write/read from upstream). - nginx gives such feature.

In detail it will be like - The new Nginx write handler should wait all body at the header phase. After it happened (means all body recived) parser should try to find information about status and headers in body and if it found (means status and header) it should send status and headers to the client.

Or you can hack nginx's phases.

dedok commented 7 years ago

This version is support this feature, a link https://github.com/tarantool/nginx_upstream_module/releases/tag/v2.4.0-beta

For details see https://github.com/tarantool/nginx_upstream_module#tnt_eval