On Apr 9, 2014, at 05:05 , Thierry FOURNIER <tfourn...@exceliance.fr> wrote:
> On Tue, 8 Apr 2014 11:02:42 -0700 > Marc Fournier <scra...@hub.org> wrote: > >> >> as per the subject, has anyone done something like this? >> >> we’re setting up two backend pools, one geared to RTL languages, one to LTR >> … I’d like to set it up so that its transparent to the end user, so that if >> they come in requesting, for instance, Arabic, they get directed to the RTL >> pool, and if they come in requesting English, they go to the LTR … >> >> I’ve searched for examples of doing this (figure I can use req.hdr() for >> this), but have drawn a blank … >> >> Before I try and do it from scratch, just figured I’d see if I wasn’t >> re-creating the wheel first … >> >> Thanks ... > > > Hello, > > I understand your need, but the header accept-language is a little bit > complicated to understand. How do you known the language required by > the browser if the accept-language header contain data like this ("ar" > is arabic, RTL language): > > ar,vi;q=0.8,fr-FR;q=0.6,fr;q=0.4,en-US;q=0.2,en;q=0.2 > vi-vn,vi;q=0.8,ar;q=0.5,en;q=0.3 > zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4,ar > zh-TW,ar;q=0.8,ja;q=0.6,en-US;q=0.4,en;q=0.2 > > In second time, if you find a solution to the first issue, you can use > the acl file. This file can contain all RTL language, if the acl is > true you can send the request. > > This is the file (list from wikipedia > http://en.wikipedia.org/wiki/Right-to-left): > > mycomputer:~$ cat rtl_languages > ar > arc > bcc > bqi > ckb > dv > fa > glk > he > ku > mzn > pnb > ps > sd > ug > ur > yi > > Haproxy config: > > use_backend rtl if { > req.hdr(accept-language),<unknown-process-that-return-language> -m str -f > rtl_languages } nginx has a module for doing this (http://wiki.nginx.org/AcceptLanguageModule) that appears to work on a ‘first match’ basis: == set_from_accept_language $lang en ja pl; == so site supports en/ja/pl … $lang variable set based on the first Accept-Languages value that matches that list … if no match, default to the first one (en) … This might be more then could be done in the config file though, if you want to honor the q= prioritizer, but that is just a method of grouping, from what I’ve read in RFC2616 … your examples above, for instance, would translate as: > zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4,ar zh-TW;q=1,zh;q=0.8,en-US;q=0.6,en;q=0.4,ar;q=1 which would then sort out to: zh-TW,ar,zh,en-US,en Of course, that assumes I’m reading how it works from RFC2616 correctly … without any q= value, everything defaults to 1 and is parsed “in hte order presented” … the q= modifier provides a sort order by weighting everything from ‘most desired’ to ‘least desired’ … Hrmmm … a bit messy, but what I could probably do is use nginx in front of haproxy to set a cookie that I could read in haproxy and redirect accordingly … which I may need to do anyway, to support https:// … And yes, I could use nginx to do the load balancing too, but I’m using haproxy’s stats interface for load monitoring / alerting … I’d rather avoid using nginx if I can, since it just adds one more layer ...