Capturing upstream response headers

39 views
Skip to first unread message

Eirik Øverby

unread,
Feb 20, 2024, 8:21:27 AMFeb 20
to openresty-en
Hi,
I'm trying to move from a shareddict implementation to using a redis store for session tokens. The reason for the move is that I need to collect these tokens from one nginx instance, and validate them in another.

The tokens are generated by the upstream application and returned to nginx as a response header. I've been using header_filter_by_lua_* with the shareddict approach, but this does not work with the redis module (as documented).

I've tried various other approaches, but I cannot seem to capture the response headers. I tried with rewrite_by_lua_*, but then the response headers disappear entirely, for reason I cannot quite understand.

Am I missing something entirely obvious here?

Thanks,
/Eirik

Aapo Talvensaari

unread,
Feb 20, 2024, 8:36:28 AMFeb 20
to openre...@googlegroups.com
You can start a timer in the header filter to connect Redis. 

Eirik Øverby

unread,
Feb 20, 2024, 7:53:14 PMFeb 20
to openresty-en
....and it's right  there in the docs. Feeling so smart right now.. Thanks!

Presumably also in the docs, but in case it isn't: Is there a best practice for how/where to set up the redis connection? If I'm using redis from the timers and from the rewrite contexts, should I be creating the redis connection somewhere else in order to get connection re-use? I am using the set_keepalive() function at the end of each redis-invoking code block so I should be saving a bit on that.

Take care,
/Eirik

Aapo Talvensaari

unread,
Mar 17, 2024, 4:55:19 AMMar 17
to openre...@googlegroups.com
On Wed, Feb 21, 2024 at 2:53 AM Eirik Øverby <ltn...@gmail.com> wrote:
Presumably also in the docs, but in case it isn't: Is there a best practice for how/where to set up the redis connection? If I'm using redis from the timers and from the rewrite contexts, should I be creating the redis connection somewhere else in order to get connection re-use? I am using the set_keepalive() function at the end of each redis-invoking code block so I should be saving a bit on that.

Just connect and setkeepalive after use. Keepalive pool is shared between different phases. 
Reply all
Reply to author
Forward
0 new messages