httpie-websockets


Namehttpie-websockets JSON
Version 1.0.0 PyPI version JSON
download
home_pageNone
SummaryWebsocket plugin for httpie
upload_time2024-10-05 12:55:43
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT License Copyright (c) 2024 belingud Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords http httpie plugin websocket websockets
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # httpie-websockets

[![PyPI version](https://img.shields.io/pypi/v/httpie-websockets?style=for-the-badge)](https://pypi.org/project/httpie-websockets/) [![License](https://img.shields.io/github/license/belingud/httpie-websockets.svg?style=for-the-badge)](https://opensource.org/licenses/MIT) ![Static Badge](https://img.shields.io/badge/language-Python-%233572A5?style=for-the-badge) ![PyPI - Downloads](https://img.shields.io/pypi/dm/httpie-websockets?logo=python&style=for-the-badge) ![Pepy Total Downlods](https://img.shields.io/pepy/dt/httpie-websockets?style=for-the-badge&logo=python)

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


<!-- TOC -->
* [httpie-websockets](#httpie-websockets)
  * [Features](#features)
  * [Install](#install)
  * [Usage](#usage)
    * [Debug Log](#debug-log)
    * [Proxy & Cert](#proxy--cert)
    * [Headers](#headers)
    * [Subprotocol](#subprotocol)
    * [Auth](#auth)
    * [Session](#session)
    * [Verify](#verify)
    * [Timeout](#timeout)
    * [~~Messages Download~~](#messages-download)
    * [Multi-line Input Support](#multi-line-input-support)
  * [Uninstall](#uninstall)
<!-- TOC -->

`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:

```shell
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

```shell
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.

```shell
# 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.

```shell
http ws://localhost:8000/ws
```

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

Example:

```shell
$ 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:

```shell
^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:

```shell
export HTTPIE_WS_LOG_LEVEL=DEBUG
```
Or

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

On Windows:

```shell
set HTTPIE_WS_LOG_LEVEL=DEBUG
```

Or

```shell
# 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.

```shell
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.

```shell
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.


```shell
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.

```shell
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.

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

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

**bearer**: similar with basic.

```shell
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.

```shell
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.

```shell
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

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

### Timeout

Pass time out option to waiting for connection establish.

```shell
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
```text
hello\
 world!
```

Will send as `hello world!`

Multiple backslashes at the end of a line
```text
hello\\\
  world!
```

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

Not at the end-of-line
```text
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

```shell
httpie plugins uninstall httpie-websockets
```

Installed by `pip` command, uninstall by

```shell
pip uninstall httpie-websockets
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "httpie-websockets",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "http, httpie, plugin, websocket, websockets",
    "author": null,
    "author_email": "belingud <1170202353@qq.com>",
    "download_url": "https://files.pythonhosted.org/packages/ac/8d/4de153596ddf69290e03afbc152158e056413f2ae589db77f461ed6f17ae/httpie_websockets-1.0.0.tar.gz",
    "platform": null,
    "description": "# httpie-websockets\n\n[![PyPI version](https://img.shields.io/pypi/v/httpie-websockets?style=for-the-badge)](https://pypi.org/project/httpie-websockets/) [![License](https://img.shields.io/github/license/belingud/httpie-websockets.svg?style=for-the-badge)](https://opensource.org/licenses/MIT) ![Static Badge](https://img.shields.io/badge/language-Python-%233572A5?style=for-the-badge) ![PyPI - Downloads](https://img.shields.io/pypi/dm/httpie-websockets?logo=python&style=for-the-badge) ![Pepy Total Downlods](https://img.shields.io/pepy/dt/httpie-websockets?style=for-the-badge&logo=python)\n\nHome: https://github.com/belingud/httpie-websockets\n\n\n<!-- TOC -->\n* [httpie-websockets](#httpie-websockets)\n  * [Features](#features)\n  * [Install](#install)\n  * [Usage](#usage)\n    * [Debug Log](#debug-log)\n    * [Proxy & Cert](#proxy--cert)\n    * [Headers](#headers)\n    * [Subprotocol](#subprotocol)\n    * [Auth](#auth)\n    * [Session](#session)\n    * [Verify](#verify)\n    * [Timeout](#timeout)\n    * [~~Messages Download~~](#messages-download)\n    * [Multi-line Input Support](#multi-line-input-support)\n  * [Uninstall](#uninstall)\n<!-- TOC -->\n\n`httpie-websockets` is an HTTPie CLI plugin that adds WebSocket support to the HTTPie command line.\n\n## Features\n\n- **WebSocket Support:** Seamlessly connect to WebSocket servers using the familiar HTTPie command line interface.\n- **Bidirectional Communication:** Send and receive messages in real-time.\n- **Secure Connections:** Supports both `ws://` and `wss://` protocols.\n- **Easy Integration:** Simple installation and usage within the HTTPie environment.\n\n## Install\n\nYou can install by httpie plugins command:\n\n```shell\nhttpie plugins install httpie-websockets\n```\n\n> When you upgrade `httpie-websockets` by `httpie plugins upgrade httpie-websockets`, the dist dir of lower version will not be removed.\n> You can remove it manually if you want. On Mac it's in `~/.config/httpie/plugins/lib/python3.12/site-packages`.\n\nor use pip in the same environment with httpie\n\n```shell\npip install httpie-websockets\n```\n\nIf your `httpie` is installed with `pipx`, you also can use `pipx` to install `httpie-websockets`.\n\nSuppose your httpie environment is named httpie.\n\n```shell\n# Replace httpie with your httpie venv name\npipx runpip httpie install -U httpie-websockets\n```\n\n## Usage\n\nAfter install this plugin, just pass websocket url to `http` command.\n\n```shell\nhttp ws://localhost:8000/ws\n```\n\nThis allows HTTPie to interact with WebSocket servers directly from the command line.\n\nExample:\n\n```shell\n$ http wss://echo.websocket.org\nRequest served by 7811941c69e658  <== This msg is from server\n> Connected to wss://echo.websocket.org\n> Type a message and press enter to send it.\n> The backslash at the end of a line is treated as input not ended.\n> Press Ctrl+C to close the connection.\n\n```\n\nWhen you press CTRL+C, connection will disconnect and httpie will get handshake response headers\nand websocket connection info with close code and close message like below:\n\n```shell\n^C\nOops! Disconnecting. Need to force quit? Press again!\nHTTP/1.1 200\nconnection: Upgrade\ndate: Thu, 15 Aug 2024 13:24:10 GMT\nfly-request-id: 01J5B3BHGV549MMJQ474SF7J60-sin\nsec-websocket-accept: MV41qn7qZQP3IXsTzYS5eDRe2tE=\nserver: Fly/ddfe15ec (2024-08-14)\nupgrade: websocket\nvia: 1.1 fly.io\n\nWebsocket connection info:\nClose Code: 1006\nClose Msg: KeyboardInterrupt\n```\n\n### Debug Log\n\nYou can set `HTTPIE_WS_LOG_LEVEL` to `DEBUG` to see `httpie_websocket` debug log for more information.\n\nOn linux and Mac:\n\n```shell\nexport HTTPIE_WS_LOG_LEVEL=DEBUG\n```\nOr\n\n```shell\nHTTPIE_WS_LOG_LEVEL=DEBUG http wss://echo.websocket.org\n```\n\nOn Windows:\n\n```shell\nset HTTPIE_WS_LOG_LEVEL=DEBUG\n```\n\nOr\n\n```shell\n# Powershell\n$env:HTTPIE_WS_LOG_LEVEL=\"DEBUG\"; http wss://echo.websocket.org\n# Cmd\ncmd /C \"set HTTPIE_WS_LOG_LEVEL=DEBUG &&; http wss://echo.websocket.org\"\n```\n\n### Proxy & Cert\n\nThis project using `websocket-client` to establish connection, support proxy and custom cert file.\nYou can pass proxy and cert to httpie.\n\nSupport `http`, `socks4`, `socks4a`, `socks5` and `socks5h` proxy protocol.\n\n```shell\nhttp wss://echo.websocket.org --proxy=http://proxy.com\nhttp wss://echo.websocket.org --proxy=socks4://proxy.com\nhttp wss://echo.websocket.org --proxy=socks4a://proxy.com\nhttp wss://echo.websocket.org --proxy=socks5://proxy.com\nhttp wss://echo.websocket.org --proxy=socks5h://proxy.com\n```\n\nCustom cert file same as httpie.\n\n```shell\nhttp wss://yourservice.com --cert=/path/to/cert --cert-key=/path/to/cert-key --cert-key-pass=pass\n```\n\n### Headers\n\nAlso support custom headers, you can send header through httpie.\n\n**Note** `wss://echo.websocket.org` does not support any authentication, and will ignore any headers you send.\n\n\n```shell\nhttp wss://echo.websocket.org Custom-Header:Custom-value\n```\n\n### Subprotocol\n\nYou can send subprotocols from the headers.\nMultiple subprotocols need to be separated by commas, since httpie receives only the first one with the same headers key.\n\n```shell\nhttp wss://echo.websocket.org Sec-WebSocket-Protocol:sub1,sub2\n```\n\n### Auth\n\nSupport pass auth option and auth-type.\n\n**basic**: httpie use basic auth as default.\n\n```shell\nhttp wss://echo.websocket.org --auth=user1:pass\n```\n\nWebsocket server will receive a header like `'Authorization': 'Basic dXNlcjE6dGVzdA=='`.\n\n**bearer**: similar with basic.\n\n```shell\nhttp wss://echo.websocket.org --auth-type=bearer --auth=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c\n```\n\nWebsocket server will receive a header like `'Authorization': 'Bearer eyxxxx'`\n\n**digest**: Technically, digest authentication is not supported, but you can generate an auth\nheader manually if you want.\n\n```shell\nhttp 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'\"\n```\n\n### Session\n\nSupport session option and perform as a header.\n\n```shell\nhttp wss://echo.websocket.org -s user1\n```\n\nSimilar like basic auth, server will receive a header like `'Authorization': 'Basic dXNlcjE6dGVzdA=='`.\n\n### Verify\n\nYou can disable SSL verification by using the --verify=no option\n\n```shell\nhttp wss://echo.websocket.org --verify=no\n```\n\n### Timeout\n\nPass time out option to waiting for connection establish.\n\n```shell\nhttp wss://echo.websocket.org --timeout=3\n```\n\n### ~~Messages Download~~\n\nMessage download functionality is no longer supported\nbecause the plugin cannot access the httpie environment,\nmaking it impossible to manage both stdout and messages simultaneously.\n\n\n### Multi-line Input Support\n\nThe backslash at the end of a line is treated as input not ended, **only the end-of-line**.\n\nIf you want to input a multiline input, use `\\` at the end of the line just like bash.\n\nExample:\n\nOne backslash at the end of a line\n```text\nhello\\\n world!\n```\n\nWill send as `hello world!`\n\nMultiple backslashes at the end of a line\n```text\nhello\\\\\\\n  world!\n```\n\nWill send as `hello\\  world!`, assume you input two whitespace ahead of `world!`.\n\nNot at the end-of-line\n```text\nhel\\\\lo\\\n world!\n```\n\nWill send as `hel\\\\lo world!`\n\n## Uninstall\n\nIf you want to uninstall this plugin, use the same way when you install.\n\nInstalled by `httpie` command, uninstall by\n\n```shell\nhttpie plugins uninstall httpie-websockets\n```\n\nInstalled by `pip` command, uninstall by\n\n```shell\npip uninstall httpie-websockets\n```\n",
    "bugtrack_url": null,
    "license": "MIT License\n         \n         Copyright (c) 2024 belingud\n         \n         Permission is hereby granted, free of charge, to any person obtaining a copy\n         of this software and associated documentation files (the \"Software\"), to deal\n         in the Software without restriction, including without limitation the rights\n         to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n         copies of the Software, and to permit persons to whom the Software is\n         furnished to do so, subject to the following conditions:\n         \n         The above copyright notice and this permission notice shall be included in all\n         copies or substantial portions of the Software.\n         \n         THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n         IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n         FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n         AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n         LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n         OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n         SOFTWARE.\n         ",
    "summary": "Websocket plugin for httpie",
    "version": "1.0.0",
    "project_urls": {
        "Documentation": "https://github.com/belingud/httpie-websockets",
        "Github": "https://github.com/belingud/httpie-websockets",
        "Homepage": "https://github.com/belingud/httpie-websockets",
        "Issues": "https://github.com/belingud/httpie-websockets/issues",
        "Source": "https://github.com/belingud/httpie-websockets"
    },
    "split_keywords": [
        "http",
        " httpie",
        " plugin",
        " websocket",
        " websockets"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "754b6a3ec8e6cbb882a9e0a0db7f8648e1eed505ccab068fa46e439177f08a6a",
                "md5": "6e1f13fa04f9d2a34747dc2f198b51e9",
                "sha256": "676508bc822bfdfbb1818620df95171fa5e56e2b47ced168e18f57c92dbe6996"
            },
            "downloads": -1,
            "filename": "httpie_websockets-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6e1f13fa04f9d2a34747dc2f198b51e9",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 11166,
            "upload_time": "2024-10-05T12:55:41",
            "upload_time_iso_8601": "2024-10-05T12:55:41.643463Z",
            "url": "https://files.pythonhosted.org/packages/75/4b/6a3ec8e6cbb882a9e0a0db7f8648e1eed505ccab068fa46e439177f08a6a/httpie_websockets-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ac8d4de153596ddf69290e03afbc152158e056413f2ae589db77f461ed6f17ae",
                "md5": "b21de239d8ed70aaf40595b81a7661cc",
                "sha256": "6db2296a055020cd485fe9439d155203ca1eea8ce5540b661592aee1a2332079"
            },
            "downloads": -1,
            "filename": "httpie_websockets-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "b21de239d8ed70aaf40595b81a7661cc",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 12994,
            "upload_time": "2024-10-05T12:55:43",
            "upload_time_iso_8601": "2024-10-05T12:55:43.304402Z",
            "url": "https://files.pythonhosted.org/packages/ac/8d/4de153596ddf69290e03afbc152158e056413f2ae589db77f461ed6f17ae/httpie_websockets-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-05 12:55:43",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "belingud",
    "github_project": "httpie-websockets",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "httpie-websockets"
}
        
Elapsed time: 0.42753s