tarantool / nginx_upstream_module

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

Handling pure POST request #76

Closed fsitedev closed 7 years ago

fsitedev commented 7 years ago

Currently if we need to send POST request there is only JSON-RPC technique available. It 's not convenient in some cases, for example simple html form submission. "multipart/form-data" variant seems to be the most interesting, giving an ability to send binary data without encoding/escaping

dedok commented 7 years ago

I guess that I will handle the content-type header to detect input type, for instance if the content-type equals 'application/json' then I will use an json transcoding and if thecontent-type equals 'multipart/form-data' I will use a multipart transcoding.

But I still don't know how exactly does It work.

Let says we have follow POST

POST /
Content-Type: multipart/form-data; boundary=boundary

--boundary
Content-Type: text/plain
Content-Disposition: form-data; name="title"

...(some body)...
--boundary
Content-Type: image/jpeg
Content-Disposition: form-data; filename="some.jpg"; name="some_name"

...(binary bytes of the image)...
--boundary--

Should I send everything as is, or should I parse the body somehow?

For example 'as is' looks:

function tnt(req, ...)
  req.body -- raw content of POST /
end
fsitedev commented 7 years ago

I think it must depend on "tnt_pass_http_request" option. You can provide value similar to "parse_args" but with more precise meaning, ex: "parse_body", "parse_post_body"

dedok commented 7 years ago

I see your point and I guess that makes sense :)

dedok commented 7 years ago

Hi! The feature added (including auto tests). For details see https://github.com/tarantool/nginx_upstream_module#tnt_pass_http_request (pass_body) Also you can get some examples here https://github.com/tarantool/nginx_upstream_module/blob/master/test/v24_features.py#L52

dedok commented 7 years ago

PS Here is a configuration example - https://github.com/tarantool/nginx_upstream_module/blob/master/test/ngx_confs/tnt_server_test.conf#L230

dedok commented 7 years ago

@fsitedev is it work for you? Or maybe have you more cool ideas? :)

fsitedev commented 7 years ago

Yes, it's definitely great job 👍 And of course I have ideas how to make it even more usefull: https://github.com/tarantool/nginx_upstream_module/issues/77