Bug 62422

Summary: Allow ProxySet to be used inside <If> expr.
Product: Apache httpd-2 Reporter: Raphaël Droz <raphael.droz>
Component: mod_proxyAssignee: Apache HTTPD Bugs Mailing List <bugs>
Status: NEW ---    
Severity: enhancement    
Priority: P2    
Version: 2.5-HEAD   
Target Milestone: ---   
Hardware: PC   
OS: Linux   

Description Raphaël Droz 2018-05-31 13:20:27 UTC
Sample:

```
<VirtualHost *:80>
  <Proxy "foo">
  </Proxy>
  <If "%{REQUEST_METHOD} == 'POST'">
    ProxySet "foo" timeout=10
  </If>
  <If "%{REQUEST_METHOD} == 'GET'">
    ProxySet "foo" timeout=2
  </If>
</VirtualHost>
```

Expected:
$ curl -X POST / # should timeout after 10 seconds
$ curl -X GET  / # should timeout after 2 seconds

Actual:
$ curl -X POST / # timeout after 2 seconds
$ curl -X GET  / # timeout after 2 seconds


Note:
* According to above test, latest ProxySet directive is considered disregarding the enclosing <If-expr>
* Neither ProxyTimeout nor Proxy are allowed inside <If-expr>
* ProxySet inside <If-expr> inside <Proxy> won't work either (proxy URL is mandatory but unknown)
Comment 1 Luca Toscano 2018-06-27 17:42:11 UTC
Hi Raphaël,

the <If> blocks are evaluated for each request, meanwhile the Proxy sections are evaluated when httpd parses the config and creates the workers/proxy-conn-pools. I believe that despite ProxySet being available in a Directory context (so ok to have it inside an <If>) it gets evaluated once when parsed, hence the 2s timeout. The https://httpd.apache.org/docs/2.4/mod/mod_proxy.html#proxyset seems wrong since in "Context" I can only see "directory", probably need to be fixed.

Hope that helps,

Luca
Comment 2 Luca Toscano 2018-06-27 17:56:15 UTC
Just tried to fix it adding server and vhost contexts to the available list.
Comment 3 Yann Ylavic 2018-06-27 19:26:51 UTC
Actually <Proxy> is one of the directory contexts, where ProxySet is allowed.
But I agree that it's not quite right to document "directory" like this (it's certainly not allowed in a <If>), and ACCESS_CONF is even wider.

The proxy context exists now though since r1740967 (including in 2.4.x), maybe we could use it for documenting several Proxy* directives, and probably turn some ACCESS_CONF to PROXY_CONF in the corresponding AP_INIT_ declarations?
Comment 4 Yann Ylavic 2018-06-27 19:37:31 UTC
(In reply to Yann Ylavic from comment #3)
> The proxy context exists now though since r1740967 (including in 2.4.x)

I meant r1740998 (r1740967 is more its usage in docs).
Comment 5 Luca Toscano 2018-06-28 05:39:59 UTC
(In reply to Yann Ylavic from comment #3)
> The proxy context exists now though since r1740967 (including in 2.4.x),
> maybe we could use it for documenting several Proxy* directives, and
> probably turn some ACCESS_CONF to PROXY_CONF in the corresponding AP_INIT_
> declarations?

I think it would be great for trunk, may we break anything though for 2.4.x users?

Interesting comment in set_proxy_param:

    /* XXX: Should this be NOT_IN_DIRECTORY|NOT_IN_FILES? */
    const char *err = ap_check_cmd_context(cmd, NOT_IN_HTACCESS);