phoenixframework / websock_adapter

Implementation of the WebSock specification for servers
MIT License
32 stars 10 forks source link

Support for Plug.Adapters.Test.Conn #17

Closed focused closed 2 months ago

focused commented 2 months ago

Hello!

I tried to test the upgrade route from the example and got the error:

** (Plug.Conn.WrapperError) ** (ArgumentError) Unknown adapter Plug.Adapters.Test.Conn

It looks like the WebSockAdapter does not support the Plug.Adapters.Test.Conn, there is no matching clause for the test adapter.

I use only :plug package without phoenix and the latest :websock_adapter (0.5.6).

Is there any workaround? Thanks for your help!

mtrudel commented 2 months ago

Hi @focused!

Would you be able to test the branch I just linked?

focused commented 2 months ago

Yes, the branch works!

I got another error:

     ** (Plug.Conn.WrapperError) ** (WebSockAdapter.UpgradeError) 'host' header is absent
     code: conn |> MyApp.Web.Router.call(MyApp.Web.Router.init([]))
     stacktrace:
       (websock_adapter 0.5.6) lib/websock_adapter/upgrade_validation.ex:45: WebSockAdapter.UpgradeValidation.validate_upgrade!/1
       (websock_adapter 0.5.6) lib/websock_adapter.ex:66: WebSockAdapter.upgrade/4

It seems that I missed some endpoint config, but I'm not sure. I think your MR fixes the behavior. Thank you.

mtrudel commented 2 months ago

Plug's test harness is by nature pretty bare-bones. You'll be on your own for ensuring the upgrade request is valid (and even then, you'll only really be able to tell that the upgrade would have succeeded; not do anything really 'end to end').

The upgrade validation code path is here if you're looking to build yourself a compliant request.