On Tue, Dec 01, 2020 at 07:13:32AM +0100, Maciej Zdeb wrote:
> For such defaults section:
> defaults
> log stdout local0
> log-format 'path:%[path]'
> 
> I'm getting following error:
> [ALERT] 335/060923 (13259) : Parsing [haproxy.cfg:11]: failed to parse
> log-format : sample fetch <path]}> may not be reliably used here because it
> needs 'HTTP request headers' which is not available here.
> 
> What I'm doing wrong? :)

You're missing "mode http" in your defaults section. I tend to recommend not
to mix TCP and HTTP defaults, because that tends to make TCP proxies inherit
lots of HTTP settings. The checks are done everywhere (as you can see here),
but this requires a lot of dedicated code to deal with corner cases, and I
must admit I never know if from time to time an HTTP directive slips into a
TCP proxy.

The good practice instead is to have one "defaults" section for TCP and
another one later for HTTP. I've long wanted to have named defaults that
could be reused in proxies. This would require to extend the "frontend",
"listen" and "backend" directives to take a section name at the declaration
moment. For example:

  defaults tcp
     timeout client 1h

  defaults http
     mode http
     timeout client 10s

  frontend f1 from tcp
     bind :1234

  frontend f2 from http
     bind :80

The last declared section would always set the current defaults though.
If anyone is interested in working on this, it's not very difficult, the
config parser currently knows about a single "defproxy", instead it could
perform a lookup (or even copy it from the current designated one).

Willy

Reply via email to