filter available?
is there anything like a filter in stream-lua-nginx-module?
like this: https://nginx.org/en/docs/stream/ngx_stream_js_module.html#js_filter
in this filter we can do something with each packet.
thank you!
Any solution to this?
Openresty gives a lua API https://github.com/openresty/stream-lua-nginx-module/blob/master/README.md?plain=1#L82 which can get raw downstream in lua coroutine, So maybe it's a better way to meet your need. @toremick @MageekChiu
Openresty gives a lua API https://github.com/openresty/stream-lua-nginx-module/blob/master/README.md?plain=1#L82 which can get raw downstream in lua coroutine, So maybe it's a better way to meet your need. @toremick @MageekChiu
Hi @oowl That's not what i at least am trying to accomplish. I need to send a string upstream on the first connect. No use for the downstream.
in njs i can do this like:
function inject_string(s)
{
s.on('upstream', function(data, flags)
{
s.sendUpstream("My string\n");
s.off('upstream');
});
}
and then use js_filter inject_string; in nginx it will on a new connection send my string by using filter, then turn off filter so the next data in the stream will continue as usual.
I have read njs doc. Yeah, it seems openresty can not inject some content in proxy, But openresty ngx.req.socket can get raw downstream socket in lua coroutine, this means you can combine openresty cosocket to do anything you want
local downstream = ngx.tcp.socket(true)
local upstream = ngx.tcp.socket()
upstream:connect("1.1.1.1:8080")
local first_process = false
while true do
local line, err, partial = downstream:receive()
if not line then
return
end
if not first_process then
upstream.send("My string\n")
first_process = true
end
upstream.send(line)
end
Of course, this bypasses a lot of configurations in nginx, such as the upstream, but it is feasible in openresty.
I have read njs doc. Yeah, it seems openresty can not inject some content in proxy, But openresty
ngx.req.socketcan get raw downstream socket in lua coroutine, this means you can combine openresty cosocket to do anything you wantlocal downstream = ngx.tcp.socket(true) local upstream = ngx.tcp.socket() upstream:connect("1.1.1.1:8080") local first_process = false while true do local line, err, partial = downstream:receive() if not line then return end if not first_process then upstream.send("My string\n") first_process = true end upstream.send(line) endOf course, this bypasses a lot of configurations in nginx, such as the upstream, but it is feasible in openresty.
Thanks for the input, but it will not work very good i guess, since i need traffic both ways etc. I think proxy_pass is a bit more too it than that.