Custom hash based on payload

I need to be able to route to specific backend servers based on a field’s value in the HTTP JSON data payload containing the IP address of the ingress end-user (the request is coming from another proxy, which inserts the end-user’s details in the JSON body). As I understand the hashing functionality can only be applied to a combination of values in the HTTP header but not the body. Does HAproxy support any plugins or perhaps there’s some other approach that would help in creating such hashed routing?

This would require waiting for the entire body and putting it in memory before making a load-balancing decision.

Check option http-buffer-request and http-request wait-for-body time.

You should then be able to use balance url_param I think.

How all this is strongly discouraged. Waiting and buffering the entire body is very bad for performance reasons and memory consumption. It should not be done on a load balancer.

The other proxy should really put the IP address in the headers as opposed to the body.

1 Like

Unfortunately I don’t have control of the ingress proxy. In this particular case the JSON payload is a few hundred bytes, and can be limited by the at least option of the wait-for-body parameter. It seems that url_param would only search for the key-value pairs of a form-encoded body. I guess I would have to patch the proxy’s source code to implement search in a JSON-encoded payload.

I don’t know if it is possible to access and parse the body in a LUA script.

This would avoid the requirement to change haproxy source code. I suggest you ask on the haproxy mailing list (just write to haproxy@formilux.org) if this is possible with LUA (or alternatively, but probably more complicated with SPOE).

This is all to avoid having to patch haproxy source code.

1 Like