Skip to main content

Create raw HTTP requests on the command line.

Project description

# `httpcat`

``httpcat`` is a simple utility for constructing raw HTTP
requests on the command line.

## Why?

Sometimes it is useful to be create an actual raw
[HTTP request](
on the command line:

* To debug a server issue
* To test the handling of invalid HTTP requests
* To learn how HTTP works under the hood

In such cases, existing CLI HTTP clients—such as
or [`wget`](
—are too high-level as they provide
an abstraction layer and one has no complete control over what
data that gets written to the socket.

Low-lever clients, such as the popular
[`netcat`](, are better suited for this

However, the syntax of HTTP requires headers to be separated with
`\r\n`, which make is it difficult to produce on the command line.
A typical solution involves the use of `echo`, which is inconvenient:

$ echo -ne 'GET / HTTP/1.1\r\nContent-Length: 5\r\n\r\nhello' | \
nc localhost 8000

`httpcat` make this easier.

## How it works

1. Reads command arguments as lines and then lines from ``stdin``
2. Auto-completes them, if necessary
3. Writes them to ``stdout``

## Features

* Automatic ``\r\n`` completion
* Automatic `Method` completion in `Request-Line`
* Automatic `HTTP-Version` completion in `Request-Line`

## Usage

Interactively create a request and send it with `nc`:
$ httpcat | nc 80
POST /post HTTP/1.1
-> POST /post HTTP/1.1\r\n
-> Host:\r\n
Content-Length: 6
-> Content-Length: 6\r\n

-> \r\n [headers written]

HTTP/1.1 200 OK
Server: nginx
Date: Mon, 12 Dec 2016 13:47:16 GMT
Content-Type: application/json
Content-Length: 230
Connection: keep-alive
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true

"args": {},
"data": "Hello\n",
"files": {},
"form": {},
"headers": {
"Content-Length": "6",
"Host": ""
"json": null,
"origin": "",
"url": ""

Specify headers and body on the command line.
Note that the omitted `HTTP-Version` is auto-completed:

$ httpcat 'POST /post' 'Host:' 'Content-Length: 5' '' 'Hello' | nc 80
-> POST /post HTTP/1.1\r\n
-> Host:\r\n
-> Content-Length: 5\r\n
-> \r\n [headers written]

Specify headers and body on the command line.
Note that the omitted `Method` is set to `GET` and `HTTP-Version`
is auto-completed:

$ httpcat '/' 'Host:' '' | nc 80
-> GET / HTTP/1.1\r\n
-> Host:\r\n
-> \r\n [headers written]

### Dependencies

* Python 3

### Installation

pip install httpcat

Alternatively just download `` manually invoke it as `./`
instead of `httpcat`.

### Tests

python test

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for httpcat, version 0.0.1
Filename, size File type Python version Upload date Hashes
Filename, size httpcat-0.0.1.tar.gz (4.6 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page