Hi Jérôme,
On Thu, Jan 30, 2014 at 06:09:27PM +0100, Jérôme Féneau wrote:
> Hi,
>
> I would like to replace incoming request's User Agent with a custom one
> before it reaches the destination server.
>
> Here is the incoming User Agent :
>
> Mozilla/5.0 (;;;) AppleWebKit/534.6 HbbTV/1.1.1 (+DL+PVR; television;
> Television EMC1000i; 1.0; 1.0;) hdplusinteraktiv/1.0 (NETRANGEMMH;)
> CE-HTML/1.0
>
> and there is the target one :
>
> Mozilla/5.0 (Windows NT 6.1; WOW64; rv:26.0) Gecko/20100101 Firefox/26.0
>
> I wrote the following configuration (not complete) :
>
> listen stb 0.0.0.0:80
> ....
> acl inverto_acl hdr(User-Agent) -i AppleWebKit
You need to use "hdr_sub" instead of "hdr" if you want to match a substring.
> use_backend inverto if inverto_acl
>
> backend inverto
> http-request set-header user-agent Mozilla/5.0....
> server octop1 193.33.168.14:80 check inter 2000 fall 3
> ...
>
> and a lot of combinations for target User Agent but haproxy generates an
> error each time. I read on the manual that I have to use a "fmt" format but
> I can not find out how to translate the User Agent I wand to use into
> something suitable for haproxy.
>
> BTW is the acl well formatted to trigger on the incoming User Agent ?
I suspect that your rewritten string is full of spaces. The space is
a word delimiter for the config file, so you need to escape them using
a backslash. BTW, you don't event need a specific backend to do this,
you can proceed this way :
http-request set-header user-agent Mozilla/5.0\ blah\ blah if {
hdr_sub(user-agent) -i AppleWebKit }
Regards,
Willy