diff options
author | Michal Piotrowski <[email protected]> | 2018-09-28 13:43:48 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2018-10-01 14:57:10 +0200 |
commit | 87e279322ba8dd86d6d8ab43f90a1b591ef090d1 (patch) | |
tree | 629a8ca004235c7b30fb86920ce4960ffeee6eef /doc/src/guide | |
parent | afc6745d3f3070418204cd5ce97adb592129777a (diff) | |
download | gun-87e279322ba8dd86d6d8ab43f90a1b591ef090d1.tar.gz gun-87e279322ba8dd86d6d8ab43f90a1b591ef090d1.tar.bz2 gun-87e279322ba8dd86d6d8ab43f90a1b591ef090d1.zip |
Document the protocols option for Websocket
Diffstat (limited to 'doc/src/guide')
-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 |