通过openresty流式下载文件

353 views
Skip to first unread message

lhmwzy

unread,
Mar 11, 2012, 4:27:04 AM3/11/12
to open...@googlegroups.com
ngx.header["content-type"] = [[application/octet-stream]]
ngx.header["Content-disposition"]= "attachment; filename=lockingplan.txt"
local f = assert(io.open("/usr/local/openresty/nginx/html/uploadfile/6ce0b53cf6cd44b13fc3a8687f17e4a3c7ddae5d", "rb"))
local block =5000
while true do
  local bytes = f:read(block)
  if not bytes then break end
  ngx.say(bytes)
end

这样写对吗?似乎下载到的东西不完整

agentzh

unread,
Mar 11, 2012, 7:08:33 AM3/11/12
to open...@googlegroups.com
Regards,
-agentzh

Yunfan Jiang

unread,
Mar 12, 2012, 4:26:01 AM3/12/12
to open...@googlegroups.com
支持输出原始的gzip内容么? 支持的话可以造个http炸弹服务器

2012/3/11 agentzh <age...@gmail.com>


--
邮件自: 列表“openresty”,专用于技术讨论!
发言: 请发邮件到 open...@googlegroups.com
退订: 请发邮件至 openresty+...@googlegroups.com
详情: http://groups.google.com/group/openresty
官网: http://openresty.org/
仓库: https://github.com/agentzh/ngx_openresty
建议: 提问的智慧 http://wiki.woodpecker.org.cn/moin/AskForHelp



--
--
cheers
    Yunfan Jiang
{'nick':['jyf', 'geek42'], 'im': {'gtalk': 'jyf...@gmail.com', 'irc': 'irc.freenode.net#ubuntu-cn'}, 'blog': 'http://geek42.info', 'interesting': {'teck': ['linux', 'pyt    hon', 'lua', 'c', 'nosql', 'redis', 'nginx'], 'history': ['chinese history',], 'sf': [42,], 'music': ['NewAge style', 'chinese old theme', 'Any strange music']}}

agentzh

unread,
Mar 12, 2012, 5:08:15 AM3/12/12
to open...@googlegroups.com
On Mon, Mar 12, 2012 at 4:26 PM, Yunfan Jiang <jyf...@gmail.com> wrote:
> 支持输出原始的gzip内容么? 支持的话可以造个http炸弹服务器
>

可以直接配合使用标准的 ngx_gzip 模块:

http://wiki.nginx.org/HttpGzipModule

因为它是一个输出过滤器,可以和 ngx_lua 中的 Lua 输出协同工作 :)

Regards,
-agentzh

Zoom.Quiet

unread,
Mar 12, 2012, 5:19:36 AM3/12/12
to open...@googlegroups.com
在 2012年3月12日 下午5:08,agentzh <age...@gmail.com> 写道:
> On Mon, Mar 12, 2012 at 4:26 PM, Yunfan Jiang <jyf...@gmail.com> wrote:
>> 支持输出原始的gzip内容么? 支持的话可以造个http炸弹服务器
>>
>
> 可以直接配合使用标准的 ngx_gzip 模块:
>
> http://wiki.nginx.org/HttpGzipModule
>
- 直接 ngx_gzip 解开,输出数据流給 lua ?
- 不缓存的话,lua 从哪儿获取正确的内容? 特别是有编码的中文时,,,

> 因为它是一个输出过滤器,可以和 ngx_lua 中的 Lua 输出协同工作 :)
>
>
> Regards,
> -agentzh

--
人生苦短, Pythonic! 冗余不做,日子甭过!备份不做,十恶不赦!
俺: http://about.me/zoom.quiet
文字协议: http://creativecommons.org/licenses/by-sa/2.5/cn/

Reply all
Reply to author
Forward
0 new messages