Large downloads getting truncated when Content-Length missing

64 views
Skip to first unread message

Shreesha K.K

unread,
Nov 17, 2023, 6:17:11 AM11/17/23
to openresty
We are using using nginx with lua open resty.

We are using Open Resty httpc:request method with a read timeout of 5 minutes.


For requests involving large contents approximately 5MB and above we see that Browser is not getting the full content of the file inspite seeing a 200 OK response when Content-Length not present in response header.

Method httpc:set_keepalive after request method gives Error - Error: unread data in buffer 

What could be the reason for these issues. what should be the ideal way of retrieving full file content from server.

Upstream server is outside our control, so we are restricted with not having Content-Length in response header.

Ron Yu

unread,
Nov 20, 2023, 5:29:12 AM11/20/23
to openresty
When buffering is enabled, nginx receives a response from the proxied server as soon as possible, saving it into the buffers set by the proxy_buffer_size and proxy_buffers directives. If the whole response does not fit into memory, a part of it can be saved to a temporary file on the disk. 

I think this is the reason why you can't get comlete response. Check nginx directives about proxy buffer for detail.

along

unread,
Feb 3, 2024, 11:02:28 PMFeb 3
to openresty
1,浏览器发起请求到nginx server;
2,这个nginx server有一些lua代码,lua代码又通过httpc:request,请求后端服务的一个文件,返回给浏览器;

这里 有几个问题呀,
1,nginx server配置的给浏览器的超时时间是多少;
2,后端服务有没有报错;
3,lua代码接收到后端服务的时候,再转发给浏览器的时候,响应的header有没有设置好,比如没有content-length的时候,需要设置content-encoding是chunked模式;
4,可以分析一下debug日志,也可以抓包瞅瞅;
Reply all
Reply to author
Forward
0 new messages