Re: [users@httpd] mod_lua / mod_proxy: set cookie on the proxied connection
On 1/8/21 6:23 PM, Yann Ylavic wrote: I'm not a Lua coder but wouldn't (something like) this here: local cookie_in = r.headers_in['Cookie'] if cookie_in ~= nil then cookie_in = cookie_in .. "; key=value" else cookie_in = "key=value" end r.headers_in['Cookie'] = cookie_in work? Hi Yann, Seems our posts crossed each other. That's pretty much exactly what I ended up doing indeed, and it works. Thank you for looking into it and providing feedback! Cheers, Gerry - To unsubscribe, e-mail: users-unsubscr...@httpd.apache.org For additional commands, e-mail: users-h...@httpd.apache.org
Re: [users@httpd] mod_lua / mod_proxy: set cookie on the proxied connection
On 1/8/21 5:29 PM, Gerry wrote: Effectively, I would like to modify the proxied HTTP request in such a way that I can inject a Cookie: header. I do not want to set a cookie in the user's client. As usual, after mulling over it for way too long before posting, I found the solution less than an hour after. Turns out one can modify the incoming Cookie: header value by setting r.headers_in["Coookie"] to the desired value, and mod_proxy will happily use it for its request. Sample code, should anyone need it: function proxy_handler(r) if r.uri:match("^/local/websocket") then r.headers_in["Cookie"] = 'MyCookie=foobar' r.handler = "proxy-server" r.proxyreq = apache2.PROXYREQ_REVERSE r.filename = "proxy:wss://192.0.2.1/remote/websocket" return apache2.OK end return apache2.DECLINED end Cheers, Gerry - To unsubscribe, e-mail: users-unsubscr...@httpd.apache.org For additional commands, e-mail: users-h...@httpd.apache.org
Re: [users@httpd] mod_lua / mod_proxy: set cookie on the proxied connection
On Fri, Jan 8, 2021 at 10:30 AM Gerry wrote: > > > function proxy_handler(r) > > if r.uri:match("^/local/websocket") then > > r.handler = "proxy-server" > > r.proxyreq = apache2.PROXYREQ_REVERSE > > r.filename = "proxy:wss://192.0.2.1/remote/websocket" I'm not a Lua coder but wouldn't (something like) this here: local cookie_in = r.headers_in['Cookie'] if cookie_in ~= nil then cookie_in = cookie_in .. "; key=value" else cookie_in = "key=value" end r.headers_in['Cookie'] = cookie_in work? > > return apache2.OK > > end > > return apache2.DECLINED > > end Regards; Yann. - To unsubscribe, e-mail: users-unsubscr...@httpd.apache.org For additional commands, e-mail: users-h...@httpd.apache.org
[users@httpd] mod_lua / mod_proxy: set cookie on the proxied connection
I am using a combination of mod_lua, mod_proxy, mod_proxy and mod_proxy_wstunnel. Excerpt from the relevant VirtualHost: LuaHookTranslateName /etc/apache2/proxy.lua proxy_handler Simplified proxy: function proxy_handler(r) if r.uri:match("^/local/websocket") then r.handler = "proxy-server" r.proxyreq = apache2.PROXYREQ_REVERSE r.filename = "proxy:wss://192.0.2.1/remote/websocket" return apache2.OK end return apache2.DECLINED end This works like a charm, except that I need a cookie to be set towards the remote websocket, the content of which I do not want to disclose to the user. For simplicity's sake, assume the value of the cookie is a fixed string. Effectively, I would like to modify the proxied HTTP request in such a way that I can inject a Cookie: header. I do not want to set a cookie in the user's client. I'm not sure what the best approach would be here. Any hint is welcome! Thanks, Gerry - To unsubscribe, e-mail: users-unsubscr...@httpd.apache.org For additional commands, e-mail: users-h...@httpd.apache.org