<div dir="ltr">Thank You for the swift answer Maxim.<div>If I understand, you mean something like that should be going to Work ...</div><div><br></div><div>location /subrequest/ {<br>       proxy_pass xxx;<br>}<br>location /anyrequest/ {<br>   auth_request /subrequest/;<br>    error_page 400 = @fallback;<br>   proxy_pass xxx;<br>}<br>location @fallback {<br>      proxy_pass_request_body off;<br>  proxy_set_header Content-Length "";<br> proxy_pass <a href="http://backend">http://backend</a>;<br>}<br></div><div><br></div><div>-V.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Feb 24, 2021 at 3:01 PM Maxim Dounin <<a href="mailto:mdounin@mdounin.ru">mdounin@mdounin.ru</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hello!<br>
<br>
On Wed, Feb 24, 2021 at 10:39:57AM +0100, Vincent Blondel wrote:<br>
<br>
> Hello all,<br>
> I have a quick question about the usage of IF and auth_request.<br>
> I would like to know if it is possible to use a IF statement to condition<br>
> the proxy behaviour of one /location depending on the response headers of<br>
> the sub auth request ...<br>
> <br>
> location /subrequest/ {<br>
>     proxy_pass xxx;<br>
> }<br>
> location /anyrequest/ {<br>
>     auth_request /subrequest/;<br>
> <br>
>     if ($response_header ~ '' ) {<br>
>       proxy_pass_request_body off;<br>
>       proxy_set_header Content-Length "";<br>
>       proxy_pass ...<br>
>     }<br>
>     if ($response_header !~ '' ) {<br>
>       proxy_pass xxx;<br>
>     }<br>
> }<br>
> <br>
> Thank You in advance for your Support ...<br>
<br>
No, it is not going to work.  The "if" directive and other rewrite <br>
module directives are executed as a part of selecing a <br>
configuration to process a request[1], and this happens before any <br>
authentication checks.<br>
<br>
Things that can work:<br>
<br>
- Using variables in the configuration and map[2] to conditionally <br>
  evaluate them after auth subrequest.  This might not be the best <br>
  approach in your particular case, as proxy_pass_request_body <br>
  does not support variables.<br>
<br>
- Returning an error from auth subrequest, so you can switch to a <br>
  different location using error_page[3].<br>
<br>
[1] <a href="http://nginx.org/en/docs/http/ngx_http_rewrite_module.html" rel="noreferrer" target="_blank">http://nginx.org/en/docs/http/ngx_http_rewrite_module.html</a><br>
[2] <a href="http://nginx.org/en/docs/http/ngx_http_map_module.html" rel="noreferrer" target="_blank">http://nginx.org/en/docs/http/ngx_http_map_module.html</a><br>
[3] <a href="http://nginx.org/r/error_page" rel="noreferrer" target="_blank">http://nginx.org/r/error_page</a><br>
<br>
-- <br>
Maxim Dounin<br>
<a href="http://mdounin.ru/" rel="noreferrer" target="_blank">http://mdounin.ru/</a><br>
_______________________________________________<br>
nginx mailing list<br>
<a href="mailto:nginx@nginx.org" target="_blank">nginx@nginx.org</a><br>
<a href="http://mailman.nginx.org/mailman/listinfo/nginx" rel="noreferrer" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx</a><br>
</blockquote></div>