vi / websocat

Command-line client for WebSockets, like netcat (or curl) for ws:// with advanced socat-like functions
MIT License
7.19k stars 280 forks source link

REQUEST: Option to display headers #48

Open FGasper opened 5 years ago

FGasper commented 5 years ago

Hello,

Is there an option to display sent/received handshake headers in client mode? I don’t see one.

Thank you!

vi commented 5 years ago

In client mode or in server mode?

In server mode they are already visible when verbose logging is on:

$ websocat -v -v -s 1234 
Listening on ws://127.0.0.1:1234/
[INFO  websocat::lints] Auto-inserting the line mode
[DEBUG websocat] Done third phase of interpreting options.
[DEBUG websocat] Done fourth phase of interpreting options.
[DEBUG websocat] Preparation done. Now actually starting.
[INFO  websocat::sessionserve] Serving Message2Line(WsServer(TcpListen(V4(127.0.0.1:1234)))) to BroadcastReuser(Line2Message(Stdio)) with Options { websocket_text_mode: true, websocket_protocol: None, websocket_reply_protocol: None, udp_oneshot_mode: false, unidirectional: false, unidirectional_reverse: false, exit_on_eof: true, oneshot: false, unlink_unix_socket: false, exec_args: [], ws_c_uri: "ws://0.0.0.0/", linemode_strip_newlines: false, linemode_strict: false, origin: None, custom_headers: [], custom_reply_headers: [], websocket_version: None, websocket_dont_close: false, one_message: false, no_auto_linemode: false, buffer_size: 65536, broadcast_queue_len: 16, read_debt_handling: Warn, linemode_zero_terminated: false, restrict_uri: None, serve_static_files: [], exec_set_env: false, reuser_send_zero_msg_on_disconnect: false, process_zero_sighup: false, process_exit_sighup: false, socks_destination: None, auto_socks5: None, socks5_bind_script: None, tls_domain: None, tls_insecure: false, max_parallel_conns: None, ws_ping_interval: None, ws_ping_timeout: None }
[INFO  websocat::net_peer] Incoming TCP connection from Some(V4(127.0.0.1:36936))
[DEBUG websocat::sessionserve] Underlying connection established
[INFO  websocat::sessionserve] Serving 1 ongoing connections
[INFO  websocat::ws_server_peer] Incoming connection to websocket: /
[DEBUG websocat::ws_server_peer] Incoming { version: Http11, subject: (Get, AbsolutePath("/")), headers: Headers { Host: l:1234
, Connection: Upgrade
, Upgrade: websocket
, Sec-WebSocket-Version: 13
, Sec-WebSocket-Key: xsmmRMYWWm+Iy5YXti9yIA==
, } }
[DEBUG websocat::ws_server_peer] Headers { }
[DEBUG websocat::ws_server_peer] Headers { Sec-WebSocket-Accept: xpz3XW1mV7L3L08tC6HX4k8R6vo=
, Connection: Upgrade
, Upgrade: websocket
, }
[INFO  websocat::ws_server_peer] Upgraded
[INFO  websocat::broadcast_reuse_peer] Initializing
[INFO  websocat::stdio_peer] get_stdio_peer (async)
[INFO  websocat::stdio_peer] Setting stdin to nonblocking mode
[INFO  websocat::stdio_peer] Installing signal handler
[DEBUG websocat::ws_peer] incoming text
sdf
[DEBUG websocat::ws_peer] incoming text
dsafadsffdsa
[DEBUG websocat::ws_peer] incoming close
[DEBUG websocat::my_copy] BrokenPipe: read_done
[DEBUG websocat::my_copy] done
[INFO  websocat::sessionserve] Forward finished
[INFO  websocat::sessionserve] Forward shutdown finished
[INFO  websocat::sessionserve] One of directions finished
[DEBUG websocat::ws_peer] drop WsWriteWrapper
[INFO  websocat::broadcast_reuse_peer] Underlying peer finished
^C[DEBUG websocat::stdio_peer] restore_blocking_status
[INFO  websocat::stdio_peer] Restoring blocking status for stdin

In client mode those messages are not visible although.

FGasper commented 5 years ago

Clarified that I mean client mode.

vi commented 5 years ago

Workaround for viewing headers on client: use socat

$ websocat -t --ws-c-uri=ws://echo.websocket.org/ - ws-c:sh-c:'socat -v - tcp:echo.websocket.org:80'
> 2019/05/24 20:25:37.397862  length=157 from=0 to=156
GET / HTTP/1.1\r
Host: echo.websocket.org\r
Connection: Upgrade\r
Upgrade: websocket\r
Sec-WebSocket-Version: 13\r
Sec-WebSocket-Key: 0e7tNlI3rZJQhahMVXk7bw==\r
\r
< 2019/05/24 20:25:37.524963  length=201 from=0 to=200
HTTP/1.1 101 Web Socket Protocol Handshake\r
Connection: Upgrade\r
Date: Fri, 24 May 2019 17:24:24 GMT\r
Sec-WebSocket-Accept: ahh65cB2anxU3TPJzTKuVWzPt0o=\r
Server: Kaazing Gateway\r
Upgrade: websocket\r
\r
sadf
> 2019/05/24 20:25:39.280030  length=11 from=157 to=167
..\v...x....< 2019/05/24 20:25:39.405917  length=7 from=201 to=207
..sadf
sadf
12313213
> 2019/05/24 20:25:40.628260  length=15 from=168 to=182
........11..33.< 2019/05/24 20:25:40.754345  length=11 from=208 to=218
.   12313213
12313213
> 2019/05/24 20:25:41.284864  length=6 from=183 to=188
....1m< 2019/05/24 20:25:41.410874  length=2 from=219 to=220

Also possible with wss://:

$ websocat -t --ws-c-uri=wss://echo.websocket.org/ - ws-c:sh-c:'socat -v - ssl:echo.websocket.org:443'