Create WebSocket using Gatling Expression

I have a use case that requires creating web sockets for multiple endpoints based on values stored in the session. Currently websockets can only be created with a string, i.e. I need to know upfront how my websocket should be named.
I’d like to be able to pass an Expression so that I can use an ID or something like that as wsName.
Looking at the code it should in theory be possible since the session is available:
https://github.com/gatling/gatling/blob/master/gatling-http/src/main/scala/io/gatling/http/action/ws/WsAction.scala#L26
https://github.com/gatling/gatling/blob/master/gatling-http/src/main/scala/io/gatling/http/action/ws/WsConnect.scala

Is that something that would be possible to implement or is there something I didn’t consider?

I have a use case that requires creating web sockets for multiple endpoints based on values stored in the session.

This statement is confusing requirements and possible implementation.
Could you please tell more about your use case?Are you sure you need a generic solution and not have different scenarios?

Thanks Stéphan for your reply.
I should have given you more details about my scenario and why I added a reference to the code.
We have multiple systems inter connected to a central search database. We search across all of the connected systems.
For assets we can open a websocket connect to the server and query details about it. However some of the assets might be from a different server so that we need to open another websocket connection.
Now I do not want to restrict the scenario to two web socket connections (let’s call them local & remote) because there could potentially be more than one (remote) this system that need to be connected to.
The systems can be identified by their ID (stored in the gatling session), so Ideally I’d like to open & store a websocket for this system, so that I can reuse it in case an asset of the system is chosen again from the search results.

Now for the code part. I was looking at the code to see if what I wanted would be doable in general (i.e. creating a feature request) or if there is a hard limitation on the web socket implementation.
If I understood it correctly it could be achieved by changing the type to an Expression[String] and evaluating the session.
However since I’m still not entirely sure that I got the concepts of execution builders and execution chains correctly I might be wrong.

So TL;DR:
I’d like to use session information to generate WebSocket names so that I do not need to know upfront how many web socket connections / servers there are.

Hi,

Thanks for the explanation.
Feel free to send a PR, it should be pretty easy.

Cheers,

Thanks Stéphane.
I’ve created a pull request for this:
https://github.com/gatling/gatling/pull/4035