Thanks! I truly appreciate your guidance. Just to confirm, I tried the header_filter approach, but it doesn't allow exec etc. So I'm assuming thats not a viable approach.
Below is what I've been trying. Is this possible? (Either way I'll start integrating lua-resty-http for the challenge / response location).
I'm attempting to use "proxy_pass" and proxy_intercept_errors to test for challenges.
But, I'm hitting the wall as I can't seem to figure out how to "test" the response header $upstream_http_ , let alone how to do AND logic. I believe the "if" statement approach runs in an earlier phase.
Do you know if its possible to test upstream_http_my_header and the $upstream_status?
location website {
proxy_pass http://backend;
proxy_intercept_errors on;
error_page 401 = @challenge
}
location @challenge {
internal
# do lua-resty-http stuff here.
}
On Saturday, September 5, 2015 at 12:27:19 AM UTC-5, agentzh wrote:
Hello!
On Sat, Sep 5, 2015 at 3:53 AM, Martin Gee wrote:
> Here is the flow
> 1) browser makes request
>
> 2) proxy_pass to get resource
> if (response status_code == 401) and
> if (resp.header has header == x)
> resend request with a response header
>
> 3) Check response
> if (response is 200)
> return results to browser
> else
> send error back to client
>
> Is ngx.locatoin.capture the best approach to manage a flow like this?
> Other approaches?
>
ngx.location.capture can work, though it's not the most efficient
approach since it always buffers the whole subrequest response in
memory, which can be a problem for big responses.
Another approach is to talk to your backend with a lua-resty-http
library with streaming support and avoid ngx_proxy altogether.
In theory, you may be able to initiate an internal redirect in the
context of a output header filter (like header_filter_by_lua) but I'm
not sure. Apparently ngx_lua does not yet support it.
Regards,
-agentzh