Mint.WebSocket.upgrade

You're seeing just the function upgrade, go back to Mint.WebSocket module for more information.
Link to this function

upgrade(conn, path, headers, opts \\ [])

View Source

Specs

upgrade(
  conn :: Mint.HTTP.t(),
  path :: String.t(),
  headers :: Mint.Types.headers(),
  opts :: Keyword.t()
) ::
  {:ok, Mint.HTTP.t(), Mint.Types.request_ref()}
  | {:error, Mint.HTTP.t(), error()}

Requests that a connection be upgraded to the WebSocket protocol

This function wraps Mint.HTTP.request/5 to provide a single interface for bootstrapping an upgrade for HTTP/1 and HTTP/2 connections.

For HTTP/1 connections, this function performs a GET request with WebSocket-specific headers. For HTTP/2 connections, this function performs an extended CONNECT request which opens a stream to be used for the WebSocket connection.

Options

  • :extensions - a list of extensions to negotiate. See the extensions section below.

Extensions

Extensions should be declared by passing the :extensions option in the opts keyword list. Note that in the WebSocket protocol, extensions are negotiated: the client proposes a list of extensions and the server may accept any (or none) of them. See Mint.WebSocket.Extension for more information about extension negotiation.

Extensions may be passed as a list of Mint.WebSocket.Extension structs or with the following shorthand notations:

  • module - shorthand for {module, []}
  • {module, params} - shorthand for {module, params, []}
  • {module, params, opts} - a shorthand which is expanded to a Mint.WebSocket.Extension struct

Examples

{:ok, conn} = Mint.HTTP.connect(:http, "localhost", 9_000)
{:ok, conn, ref} =
  Mint.WebSocket.upgrade(conn, "/", [], extensions: [Mint.WebSocket.PerMessageDeflate])
# or provide params:
{:ok, conn, ref} =
  Mint.WebSocket.upgrade(
    conn,
    "/",
    [],
    extensions: [{Mint.WebSocket.PerMessageDeflate, [:client_max_window_bits]]}]
  )