Sticky sessions based on SOAP contents

Our application has a SOAP API to set up sessions (usually done by an integrating application) that are then consumed by a client. The session is maintained on the server, and the integrating application transfers the session ID to the webbrowser client, ensuring that a particular client connects to the specific session that was set up for them.
We want to load-balance this with HAProxy. Of course we need sticky sessions, and I have it working with a cookie – so far, so good. But that puts a requirement to the integrating application: it has to transfer that cookie (gotten from the response) to the browser of the client. And since we have a plethora of integrating applications that we do not have control over, we’d rather avoid this.
And we already have the/a session ID: it’s returned by the server, and it’s sent with (almost) every subsequent call from the clients to the server. But that session ID is in the contents of the call, and not in a header or cookie.
I’ve found this article that explains how to parse the request with a Lua script, but that is now outdated because txn.req:dup() doesn’t work anymore. And the HTX class that came in as its replacement does not contain methods to get to the body of the HTTP request.

Is this particular use case now impossible with HAProxy 2.0 and up? Or am I missing something?

Hi,

I do agree, the documentation is unclear on how it works and I could not make it work.
You can use the following instead of dup():

local payload = txn.sf:req_body()

1 Like

Don’t forget option http-buffer-request in your frontend / defaults section

1 Like

Thank you so much, that indeed solved this particular problem!