Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support WsHandler symmetry #1049

Open
oharaandrew314 opened this issue Feb 2, 2024 · 1 comment
Open

Support WsHandler symmetry #1049

oharaandrew314 opened this issue Feb 2, 2024 · 1 comment

Comments

@oharaandrew314
Copy link
Contributor

oharaandrew314 commented Feb 2, 2024

The HttpHandler supports perfect symmetry, where it can be used as the interface for a server and client.

Currently, the WsHandler is only supported on the server-side, making it more of a chore to fake websocket connections.

Workaround

class MyService(
    private val openWs: (Uri) -> Websocket 
) {
  fun open(): Websocket {
      return openWs(Uri.of("ws://foo"))
  }
}

val realService = MyService { uri ->
    WebsocketClient.nonBlocking(uri)
}

val testWs = websockets()
val testService = MyService { uri ->
    val request = Request(Method.GET, uri)
    testWs.testWebsocket(request)
}

Desired

class MyService2(
    private val wsHandler: WsHandler
) {
    fun open(): Websocket {
        val request = Request(Method.GET, "ws://foo")
        return wsHandler(request).nonBlocking()
    }
}

val realService2 = MyService2(JavaWebSocketClient())

val testWs2 = websockets()
val testService2 = MyService2(testWs2) 

Does this seem reasonable and doable?

@daviddenton
Copy link
Member

I'm struggling to see how this could work TBH. Also, I'd probably strive to have the open function as:

operator fun invoke(req: Request): Websocket

Have a go though - it might fit in your brain! 🙃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants