Has anyone tried to build an http4k proxy that sup...
# http4k
a
Has anyone tried to build an http4k proxy that supports websockets? I've done it before with Netty, but hoping I can continue to use http4k for this, since I don't need to support all of TCP this time.
d
Never done it, but the setup is broadly the same with routers and filters and handlers, so i am pretty bullish that it might work. If you come up with anything good, we can add it back into http4k-realtime-core 😉
a
My initial attempt shows the websocket can be established, but I suspect my server is failing to send follow-up frames from the client, despite switching my WS server's
BodyMode
to
Stream
. It's difficult to debug, because it's a blackbox client and server initiating the websocket, but I'm attempting to reproduce it in test. On that note, assuming I've created a fake
WsHandler
, is it possible to convert it to an
HttpHandler
, so I can attach it as a fake device to my reverse-proxy? Or would I need to run my tests against running servers (via
PolyServerConfig
) to accomplish this?
d
no you can't convert between them - but you*should* be able to run it in memory without the server to unit test.
a
Well, I know I can connect a test client to an in-memory websocket, but the problem is that my fake reverse-proxy is supposed to have both regular http and websocket devices it can route to. I know I can do that by merging them into a
PolyServerConfig
and running a server. But I'm not sure how I can do that in-memory. I might be making things confusing by the fact that there is both a fake reverse-proxy, and the reverse-proxy application under test. It's a reverse-proxy for several reverse-proxies 🙄 . The fake websocket server is a server behind the fake reverse-proxy, and my websocket client is connecting to the reverse proxy under test.
Untitled drawing (1).png
d
You can't do that in memory I'm afraid. Each protocol "type" is a single distinct function and there isn't a combining function to test them all at once like that. That's why we combine them in the runtime later, so yes - you need the poly config
a
Got it. Thanks