You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When opening connections through the ktor client API, it looks like there's no good way to customize the setup metadata for each connection. It can only be set once for the entire HttpClient.
Motivation
I'm trying to connect to an RSocket endpoint that requires a JWT token as part of the SETUP frame. In my client, I want to fetch this token before I open the WebSocket:
val client:HttpClient=TODO()
val token = fetchToken()
val rSocket = httpClient.rSocket {
url.takeFrom(myWebSocketUri())
// TODO: Specify connection setup metadata here?
setupPayload = buildPayload {
metadata(json.encodeToString(mapOf("token" to token)))
}
}
emitAll(rSocket.requestStream(buildPayload { /* ... */ }))
However, it doesn't look like there's an option on the rSocket callback to specify these options.
Desired solution
Since I want to keep my configured HttpClient around for the entire lifetime of the application instead of re-creating it for every RSocket connection, it would be good to have an option to set the setup payload on the rSocket method since that is ultimately what's actually opening the connection in the end.
Considered alternatives
I see that I can set the payload when configuring the engine, but it looks like these would be used for every connection?
install(RSocketSupport) {
connector {
connectionConfig {
setupPayload {
buildPayload {
metadata("todo: I want this to be called for every new connection")
}
}
}
}
}
Maybe an easy change is to call setupPayload again for every connection, but I think being able to customize this when creating the connection would still be better (I need the function creating the setup payload to be suspending, for instance).
The text was updated successfully, but these errors were encountered:
I should add that if the maintainers agree that adding e.g. a connection: RSocketConnectorBuilder.() -> Unit function to the HttpClient.rSocket, I'd be happy to contribute. Just need some guidance on how this would best be integrated :)
When opening connections through the ktor client API, it looks like there's no good way to customize the setup metadata for each connection. It can only be set once for the entire
HttpClient
.Motivation
I'm trying to connect to an RSocket endpoint that requires a JWT token as part of the
SETUP
frame. In my client, I want to fetch this token before I open the WebSocket:However, it doesn't look like there's an option on the
rSocket
callback to specify these options.Desired solution
Since I want to keep my configured
HttpClient
around for the entire lifetime of the application instead of re-creating it for every RSocket connection, it would be good to have an option to set the setup payload on therSocket
method since that is ultimately what's actually opening the connection in the end.Considered alternatives
I see that I can set the payload when configuring the engine, but it looks like these would be used for every connection?
Maybe an easy change is to call
setupPayload
again for every connection, but I think being able to customize this when creating the connection would still be better (I need the function creating the setup payload to be suspending, for instance).The text was updated successfully, but these errors were encountered: