openresty / lua-resty-upload

Streaming reader and parser for http file uploading based on ngx_lua cosocket
405 stars 113 forks source link

How to reconstruct body after upload #41

Closed asyncer closed 2 years ago

asyncer commented 6 years ago

I'm trying to make an anti-virus middle ware which first check the uploaded files with help of lua-resty-upload and if they are not infected proxy_pass them to some dynamic proxy target. I was able to handle the first part easily thanks to lua-resty-upload but the issue is when I proxy_pass the request after anti-virus check the body is empty. which seems pretty normal because lua-resty-upload has consumed the body already. So I should reconstruct the body again after virus check, But I don't have the raw binary data of request at that point to easily reconstruct the body, all I have is parsed body which is hard to be converted to raw binary again. Is there any shortcut method which can give me the raw binary data after process of lua-resty-upload is finished?

bungle commented 6 years ago

I think this library should possibly get an option to: https://github.com/openresty/lua-nginx-module#ngxreqinit_body https://github.com/openresty/lua-nginx-module#ngxreqappend_body https://github.com/openresty/lua-nginx-module#ngxreqfinish_body

So that it rewrites the buffer back (while it reads it). Currently you cannot use e.g. proxy module to forward the body read by lua-resty-upload. So in that sense it is not proxy friendly currently.