Closed Fr3DBr closed 7 years ago
@Fr3DBr In your case, the upstream request won't be sent until 5 sec is elapsed. Your web browser's "file being downloaded" is just its best guess and it's definitely untrue for your case here.
@Fr3DBr BTW, a much more efficient way of delaying your upstream request is using ngx_lua's access_by_lua_block
directive:
location / {
access_by_lua_block { ngx.sleep(5) }
proxy_pass http://svr_backend;
include proxy.inc;
}
It's much much more efficient than your current echo_sleep
+ echo_location
combination, especially for large upstream responses.
BTW, sorry for the delay on my side.
Hey @agentzh but, will this stop/pause any other requests while sleeping (parallelism) ?
@Fr3DBr No, it's nonblocking. Read the documentation.
@agentzh Ah, then this is fine, also do you have a way to detect in lua, if a connection was closed or not ? Or in case this is closed by the client, will it abort the current code execution just fine ?
@Fr3DBr See
https://github.com/openresty/lua-nginx-module/#lua_check_client_abort
Read the document.
@agentzh Thank you very much. 👍
@Fr3DBr BTW, you may find the lua-resty-limit-traffic library useful:
https://github.com/openresty/lua-resty-limit-traffic
It's shipped with OpenResty by default.
I've tried this:
The problem is that I always get a "file being downloaded" when any request is performed, instead of the website being show in the browser when echo module is not used... ?
What I want to achieve, is unless the client wait 5 seconds, the request won't be processed by the upstream server.