vi / websocat

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

-H option cannot override the Host field #82

Open halfcrazy opened 4 years ago

halfcrazy commented 4 years ago

For example ./websocat ws://192.168.16.93:7789 -H 'Host: testnginx.com' The header Host field is always 192.168.16.93:7789 not testnginx.com image

I have to write /etc/hosts to archive this. image

vi commented 4 years ago

Currently may be possible only with "Websocat 2"-style pieces (which are not yet assembled into a system and are not default for handing ws://):

target/debug/websocat -t - \
    ws-ll-c:http-request:tcp:192.168.16.93:7789  \
    --request-header 'Host: testnginx.com' \
    --request-header 'Upgrade: websocket' \
    --request-header 'Sec-WebSocket-Key: mYUkMl6bemnLatx/g7ySfw==' \
    --request-header 'Sec-WebSocket-Version: 13' \
    --request-header 'Connection: Upgrade' \
    --request-uri=/
Dulanjala007 commented 11 months ago

you could use websocat --ws-c-uri=ws://echo.websocket.org/ - ws-c:tcp:127.0.0.1:8888

Connection received on 127.0.0.1 37972
GET / HTTP/1.1
Host: echo.websocket.org
Connection: Upgrade
Upgrade: websocket
Sec-WebSocket-Version: 13
Sec-WebSocket-Key: a04beHFEo1lslZnLwXJhSA==
adamwoolhether commented 1 month ago

still not possible?

vi commented 1 month ago

In Websocat4 it almost works:

websocat4  ws://localhost:1234/ -H 'Host: qqq'
GET / HTTP/1.1
connection: upgrade
upgrade: websocket
content-length: 0
sec-websocket-version: 13
sec-websocket-key: aHzCm4R1NvBaOifR6VcuwQ==
host: localhost:1234
host: qqq

You can remove the extra header by editing the script manually.

$ websocat4  ws://localhost:1234/ -H 'Host: qqq' --dump-spec > q.rh
$ grep ws_upgrade q.rh
      ws_upgrade(#{url: "/",host: "localhost:1234",}, #{"Host":"qqq",}, http1, |wsframes1| {
$ sed 's/,host: "localhost:1234",//' -i q.rh
$ grep ws_upgrade q.rh
      ws_upgrade(#{url: "/"}, #{"Host":"qqq",}, http1, |wsframes1| {
$ websocat4 -x q.rh
GET / HTTP/1.1
connection: upgrade
upgrade: websocket
content-length: 0
sec-websocket-version: 13
sec-websocket-key: RahwxlLxhFPSeIMeRrvz1g==
host: qqq