Search code examples
haproxy

is it possible to write the hashed value of a cookie to a header in haproxy?


I am relatively new to using haproxy, and I am trying to figure out if it is possible to use a consistent hashing algorithm to hash a cookie value in to a separate header. This seems very similar to how you would use a consistent hash-type (http://cbonte.github.io/haproxy-dconv/1.8/configuration.html#4-hash-type) for load balancing, but I don't see how you could put the output of that hashing in to a header for backend servers to see.

My use case is that I have a 'uuid' cookie which I want to use to assign users to a pool 1-100 to use in A/B (/C/D... etc) tests. Today we do this in a nodejs app, but we are adding new backends and we want to avoid implementing the same hashing in multiple languages.

I'm currently using haproxy 1.8. I appreciate any suggestions!


Solution

  • use this

     http-request set-header header_name %[req.cook(your_cookie),sdbm,mod(100)]