Skip to main content

httpie-websockets

PyPI version License Static Badge PyPI - Downloads Pepy Total Downlods

Home: https://github.com/belingud/httpie-websockets

httpie-websockets is an HTTPie CLI plugin that adds WebSocket support to the HTTPie command line.

Features

  • WebSocket Support: Seamlessly connect to WebSocket servers using the familiar HTTPie command line interface.
  • Bidirectional Communication: Send and receive messages in real-time.
  • Secure Connections: Supports both ws:// and wss:// protocols.
  • Easy Integration: Simple installation and usage within the HTTPie environment.

Install

You can install by httpie plugins command:

httpie plugins install httpie-websockets

When you upgrade httpie-websockets by httpie plugins upgrade httpie-websockets, the dist dir of lower version will not be removed. You can remove it manually if you want. On Mac it's in ~/.config/httpie/plugins/lib/python3.12/site-packages.

or use pip in the same environment with httpie

pip install httpie-websockets

If your httpie is installed with pipx, you also can use pipx to install httpie-websockets.

Suppose your httpie environment is named httpie.

# Replace httpie with your httpie venv name
pipx runpip httpie install -U httpie-websockets

Usage

After install this plugin, just pass websocket url to http command.

http ws://localhost:8000/ws

This allows HTTPie to interact with WebSocket servers directly from the command line.

Example:

$ http wss://echo.websocket.org
Request served by 7811941c69e658  <== This msg is from server
> Connected to wss://echo.websocket.org
> Type a message and press enter to send it.
> The backslash at the end of a line is treated as input not ended.
> Press Ctrl+C to close the connection.

When you press CTRL+C, connection will disconnect and httpie will get handshake response headers and websocket connection info with close code and close message like below:

^C
Oops! Disconnecting. Need to force quit? Press again!
HTTP/1.1 200
connection: Upgrade
date: Thu, 15 Aug 2024 13:24:10 GMT
fly-request-id: 01J5B3BHGV549MMJQ474SF7J60-sin
sec-websocket-accept: MV41qn7qZQP3IXsTzYS5eDRe2tE=
server: Fly/ddfe15ec (2024-08-14)
upgrade: websocket
via: 1.1 fly.io

Websocket connection info:
Close Code: 1006
Close Msg: KeyboardInterrupt

Debug Log

You can set HTTPIE_WS_LOG_LEVEL to DEBUG to see httpie_websocket debug log for more information.

On linux and Mac:

export HTTPIE_WS_LOG_LEVEL=DEBUG

Or

HTTPIE_WS_LOG_LEVEL=DEBUG http wss://echo.websocket.org

On Windows:

set HTTPIE_WS_LOG_LEVEL=DEBUG

Or

# Powershell
$env:HTTPIE_WS_LOG_LEVEL="DEBUG"; http wss://echo.websocket.org
# Cmd
cmd /C "set HTTPIE_WS_LOG_LEVEL=DEBUG &&; http wss://echo.websocket.org"

Proxy & Cert

This project using websocket-client to establish connection, support proxy and custom cert file. You can pass proxy and cert to httpie.

Support http, socks4, socks4a, socks5 and socks5h proxy protocol.

http wss://echo.websocket.org --proxy=http://proxy.com
http wss://echo.websocket.org --proxy=socks4://proxy.com
http wss://echo.websocket.org --proxy=socks4a://proxy.com
http wss://echo.websocket.org --proxy=socks5://proxy.com
http wss://echo.websocket.org --proxy=socks5h://proxy.com

Custom cert file same as httpie.

http wss://yourservice.com --cert=/path/to/cert --cert-key=/path/to/cert-key --cert-key-pass=pass

Headers

Also support custom headers, you can send header through httpie.

Note wss://echo.websocket.org does not support any authentication, and will ignore any headers you send.

http wss://echo.websocket.org Custom-Header:Custom-value

Subprotocol

You can send subprotocols from the headers. Multiple subprotocols need to be separated by commas, since httpie receives only the first one with the same headers key.

http wss://echo.websocket.org Sec-WebSocket-Protocol:sub1,sub2

Auth

Support pass auth option and auth-type.

basic: httpie use basic auth as default.

http wss://echo.websocket.org --auth=user1:pass

Websocket server will receive a header like 'Authorization': 'Basic dXNlcjE6dGVzdA=='.

bearer: similar with basic.

http wss://echo.websocket.org --auth-type=bearer --auth=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c

Websocket server will receive a header like 'Authorization': 'Bearer eyxxxx'

digest: Technically, digest authentication is not supported, but you can generate an auth header manually if you want.

http wss://echo.websocket.org "Authorization: Digest username='user', realm='example', nonce='c3a7f38c-5e5a-45b2-a5b5-3b5e2c5c5c5c', uri='/path/to/protected/resource', response='generated_response', qop=auth, nc=00000001, cnonce='generated_cnonce', opaque='6d6b8f8f-6b8f-6b8f-6b8f-6b8f6b8f6b8f'"

Session

Support session option and perform as a header.

http wss://echo.websocket.org -s user1

Similar like basic auth, server will receive a header like 'Authorization': 'Basic dXNlcjE6dGVzdA=='.

Verify

You can disable SSL verification by using the --verify=no option

http wss://echo.websocket.org --verify=no

Timeout

Pass time out option to waiting for connection establish.

http wss://echo.websocket.org --timeout=3

Messages Download

Message download functionality is no longer supported because the plugin cannot access the httpie environment, making it impossible to manage both stdout and messages simultaneously.

Multi-line Input Support

The backslash at the end of a line is treated as input not ended, only the end-of-line.

If you want to input a multiline input, use \ at the end of the line just like bash.

Example:

One backslash at the end of a line

hello\
 world!

Will send as hello world!

Multiple backslashes at the end of a line

hello\\\
  world!

Will send as hello\ world!, assume you input two whitespace ahead of world!.

Not at the end-of-line

hel\\lo\
 world!

Will send as hel\\lo world!

Uninstall

If you want to uninstall this plugin, use the same way when you install.

Installed by httpie command, uninstall by

httpie plugins uninstall httpie-websockets

Installed by pip command, uninstall by

pip uninstall httpie-websockets

Metadata

Release files for httpie-websockets 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for httpie-websockets 1.0.0
File Size Uploaded
httpie_websockets-1.0.0.tar.gz 13.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for httpie-websockets 1.0.0
File Interpreter ABI Platform
httpie_websockets-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 24.2 kB

Release files / httpie_websockets-1.0.0.tar.gz

Download URL httpie_websockets-1.0.0.tar.gz
Size 13.0 kB
Tags Source
SHA-256 checksum
How to use checksums
6db2296a055020cd485fe9439d155203ca1eea8ce5540b661592aee1a2332079
BLAKE2b-256 checksum
How to use checksums
ac8d4de153596ddf69290e03afbc152158e056413f2ae589db77f461ed6f17ae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via pdm/2.18.2 CPython/3.12.3 Darwin/24.0.0

Release files / httpie_websockets-1.0.0-py3-none-any.whl

Download URL httpie_websockets-1.0.0-py3-none-any.whl
Size 11.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
676508bc822bfdfbb1818620df95171fa5e56e2b47ced168e18f57c92dbe6996
BLAKE2b-256 checksum
How to use checksums
754b6a3ec8e6cbb882a9e0a0db7f8648e1eed505ccab068fa46e439177f08a6a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via pdm/2.18.2 CPython/3.12.3 Darwin/24.0.0

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.4

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page