vi / websocat

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

WebSocketOtherError::ResponseError detail/message is lost #109

Closed andlaz closed 3 years ago

andlaz commented 3 years ago

Hi,

i'm trying to debug a websocket connection issue with websocat, and am getting

websocat: WebSocketError: WebSocket response error
websocat: error running

i was able to find WebSocketError in the websocket crate and it does seem like it carries a message that i'd like to dig out of this websocat run. I couldn't even find where the first error line above is written out, it doesn't seem like it is produced by the websocket crate's display implementation the very least

Any suggestions on where exactly this error is dumped to stdout, so we can have it give up it's message field? I'd be happy to send a PR if you can point me in the right direction.

thanks!! Andras

vi commented 3 years ago

Maybe try the newly added debug mode?

If it is not available, you can also try the ws-c trick.

it doesn't seem like it is produced by the websocket crate's display implementation the very least

If you contribute a rust-websocket pull request, I can merge&release it + maybe make a websocat build, but in the long term I am planning to sunset "rust-websocket" project and use some other implementation for forthcoming version of Websocat.

andlaz commented 3 years ago

yup, i was way behind. In 1.7.0 the message is printed

websocat: WebSocketError: Received unexpected status code (403 Forbidden)

the protocol level debugging works as well and it's super useful. Thanks!

sammoh94 commented 3 years ago

@vi Hi I am using websocat to test a websocket server I am writing. When I make the following request:

websocat 'ws://localhost:[port]?qp1=value&qp2=value&qp3=value' -H='header: value' --ping-interval 30 -v

I am seeing the following message: [INFO websocat::ws_peer] Received WebSocket close message However, in my server (using tokio-tungstenite), I am sending a code and a reason when I close the websocket. I would like to show that reason in this line. Could you direct me on how the above command should be run. It's not clear to me how the log: overlay should be used. Thanks!

vi commented 3 years ago

@sammoh94 , Added a debug log (websocat -v -v message which is supposed to contain the closing message content. If you can build Websocat from source code, you should see it.

sammoh94 commented 3 years ago

@vi Would it not work if ran cargo install --features=ssl websocat to install? I checked my version and it's 1.7.0.

So I should run websocat 'ws://localhost:[port]?qp1=value&qp2=value&qp3=value' -H='header: value' --ping-interval 30 -v -v? Tried that but still only seeing the Websocket close message without the reason

vi commented 3 years ago

Would it not work if ran cargo install --features=ssl websocat to install?

Maybe, if you also add --git https://github.com/vi/websocat option.

So I should run ... -v -v.

Yes.

Tried that but still only seeing the Websocket close message without the reason

Because previous cargo install installed last published version (1.7.0), not in-development version from the master branch.

sammoh94 commented 3 years ago

@vi Yay that works thanks!

Just wondering is there a way to suppress debug messages from the output of that command. Example, not show a message like this:

[DEBUG websocat::sessionserve] Serving Line2Message(ThreadedStdio) to Message2Line(WsClient("ws://localhost:9000
...
vi commented 3 years ago

@sammoh94, Try using RUST_LOG=websocat::ws_peer=debug environment variable instead of -v -v.

sammoh94 commented 3 years ago

That works thank you very much!