使用stream模块转发tcp流的时候,有没有办法丢弃掉终端的部分数据呢

472 views
Skip to first unread message

艾菲

unread,
Sep 26, 2020, 9:56:38 PM9/26/20
to openresty
我们在端上发送数据的时候会在应用层协议之前加上一些buffer,但是后端的源站并不需要这些buffer,有没有什么手段可以在代理的过程中将这些buffer 读取出来并且删除掉呢?

DeJiang Zhu

unread,
Sep 27, 2020, 2:35:20 AM9/27/20
to open...@googlegroups.com

在 preread_by_lua 里使用 ngx.req.socket 就可以的


艾菲 <aife...@gmail.com> 于2020年9月27日周日 上午9:56写道:
我们在端上发送数据的时候会在应用层协议之前加上一些buffer,但是后端的源站并不需要这些buffer,有没有什么手段可以在代理的过程中将这些buffer 读取出来并且删除掉呢?

--
--
邮件来自列表“openresty”,专用于技术讨论!
订阅: 请发空白邮件到 openresty...@googlegroups.com
发言: 请发邮件到 open...@googlegroups.com
退订: 请发邮件至 openresty+...@googlegroups.com
归档: http://groups.google.com/group/openresty
官网: http://openresty.org/
仓库: https://github.com/agentzh/ngx_openresty
教程: http://openresty.org/download/agentzh-nginx-tutorials-zhcn.html
---
您收到此邮件是因为您订阅了Google网上论坛上的“openresty”群组。
要退订此群组并停止接收此群组的电子邮件,请发送电子邮件到openresty+...@googlegroups.com
要在网络上查看此讨论,请访问https://groups.google.com/d/msgid/openresty/922fb086-7742-4ec2-a568-1434bac8d3c2n%40googlegroups.com

艾菲

unread,
Sep 27, 2020, 3:11:21 AM9/27/20
to openresty
local sock = ngx.req.socket()
local data = sock:peek(10)

这样虽然能拿到来自下游的10个byte 但是在后面proxy pass 的时候 这10个byte 依然会往upstream发送
我的意思是希望能在peek 之后 就把这个10 个byte 给删除掉  
目前我的办法是修改stream_write_filter_module  
用 ngx_chain_update_sent  给 chain 设置一段偏移~~
还有其他办法没 ? 或者能不能暴露一个 lua api 出来呢?

DeJiang Zhu

unread,
Sep 27, 2020, 3:45:00 AM9/27/20
to open...@googlegroups.com

你这个就是需要 receive 了呢

 However, keep in mind that calling the receive() method of the request socket will consume the data from the buffer and such consumed data will not be seen by handlers further down the chain.

艾菲 <aife...@gmail.com> 于2020年9月27日周日 下午3:11写道:

艾菲

unread,
Sep 27, 2020, 4:14:05 AM9/27/20
to openresty
receive 会让整个流上的所有数据都丢失 
比如客户端发送了 15个byte
receive(10) 之后 剩下的 5 个byte 是不能被proxy pass 的

Yi Zhu

unread,
Oct 28, 2020, 5:13:42 AM10/28/20
to open...@googlegroups.com
如果receive后不能被proxypass,name自己receive,然后用socket转发给自己的另外一个端口,再利用proxypass上传是否可行

winl...@gmail.com

unread,
Mar 15, 2021, 9:07:41 AM3/15/21
to openresty

企业微信截图_20210315210713.png
Reply all
Reply to author
Forward
0 new messages