diff options
Diffstat (limited to 'doc/src/guide/websocket.asciidoc')
-rw-r--r-- | doc/src/guide/websocket.asciidoc | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/doc/src/guide/websocket.asciidoc b/doc/src/guide/websocket.asciidoc index 418b456..8503670 100644 --- a/doc/src/guide/websocket.asciidoc +++ b/doc/src/guide/websocket.asciidoc @@ -26,13 +26,13 @@ gun:ws_upgrade(ConnPid, "/websocket"). Gun will set all the necessary headers for performing the Websocket upgrade, but you can specify additional headers -if needed. For example you can request a custom sub-protocol. +if needed. For example you can authenticate. -.Upgrade to Websocket and request a protocol +.Upgrade to Websocket using HTTP authentication [source,erlang] ---- gun:ws_upgrade(ConnPid, "/websocket", [ - {<<"sec-websocket-protocol">>, "mychat"} + {<<"authorization">>, "Basic dXNlcm5hbWU6cGFzc3dvcmQ="} ]). ---- @@ -40,6 +40,22 @@ You can pass the Websocket options as part of the `gun:open/2,3` call when opening the connection, or using the `gun:ws_upgrade/4`. The fourth argument is those same options. +Gun can negotiate the protocol to be used for the Websocket +connection. The `protocols` option can be given with a list +of protocols accepted and the corresponding handler module. +Note that the interface for handler modules is currently +undocumented and must be set to `gun_ws_h`. + +.Upgrade to Websocket with protocol negotiation +[source,erlang] +---- +gun:ws_upgrade(ConnPid, "/websocket", [] + #{protocols => [{<<"xmpp">>, gun_ws_h}]}). +---- + +The upgrade will fail if the server cannot satisfy the +protocol negotiation. + When the upgrade succeeds, a `gun_upgrade` message is sent. If the server does not understand Websocket or refused the upgrade, a `gun_response` message is sent. If Gun couldn't |