ReqClinet.MintWs (req_client v0.1.17)

Copy Markdown View Source

Websocket client based on mint-websocket and mint

At the time of writing, very few HTTP/2 server libraries support or enable HTTP/2 WebSockets by default.

Summary

Functions

check!()

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

client(opts \\ [])

close(opts \\ [])

Close connection

connect(opts \\ [])

connet_opts(opts \\ [])

decode(data, opts \\ [])

Ws.encode |> Ws.decode

encode(frame \\ {:ping, ""}, opts \\ [])

Try frame encoding

Mint.WebSocket.encode(%{extensions: []}, :ping) Mint 在编码 WebSocket 帧时自动添加了随机掩码(Masking Key) 根据 RFC 6455,客户端发送到服务端的帧必须被掩码(Masked),而服务端发送给客户端的帧不能被掩码。掩码的目的是防止缓存污染和代理攻击。 掩码密钥的随机性确保了相同内容的不同帧在传输时二进制数据不同,防止恶意代理篡改或缓存敏感信息。

Why result changed every time??? iex(210)> Mint.WebSocket.Frame.encode(%{extensions: []}, :ping) {:ok, %{extensions: []}, <<137, 128, 215, 178, 102, 78>>} iex(211)> Mint.WebSocket.Frame.encode(%{extensions: []}, :ping) {:ok, %{extensions: []}, <<137, 128, 88, 223, 225, 101>>}

get_client_pid(opts \\ [])

handle_frames(state, frames)

hi(msg \\ [])

local_state(opts \\ [])

peer_state(opts \\ [])

ping(opts \\ [])

send_msg(msg, opts \\ [])

url_hash_name(url, opts \\ [])