Re: [users@httpd] mod_lua / mod_proxy: set cookie on the proxied connection

2021-01-08 Thread Gerry

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

2021-01-08 Thread Gerry

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

2021-01-08 Thread Yann Ylavic
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