Newer
Older
httpcat / README.md
httpcat
===============

A netcat-like tool for analysing or mocking HTTP requests.  My first experiment with Go.

## Usage

```
httpcat <command> [OPTIONS]

Commands:

  client     Send an HTTP request
  proxy      Start a reverse HTTP logging proxy
  server     Start a mock HTTP server
  version    Display version

Command specific help:

  httpcat <command> --help
```

### Global Options

The following options apply to all commands.

```
-v, --verbose       Show additional details.

    --headers       Show headers and request/status line only (default is
                    everything).

    --bodies        Show bodies only (default is everything).

    --nocolour      Don't use colours (default is requests in blue and
                    responses in red).

    --notimestamps  Don't show timestamps.

    --noindent      Don't indent bodies (currently, only application/json
                    bodies are indented).
```

## Client Mode

Sends an HTTP request to the specified server and displays the response.

### Usage

```
httpcat client [OPTIONS]
```
### Client Specific Options
```
-u, --url=          The URL to send the request to.

-H, --header=       A header to add to request in the form name:value. Use
                    multiple times for multiple headers.

-m, --method=[GET|POST|PUT|DELETE|PATCH|HEAD|OPTIONS]
                    HTTP method for request (default: GET).

-b, --body=         Request body to send.
```

### Example

```
httpcat client \
   --method POST \
   --body "Testing 123" \
   --header "Content-Type: text/plain" \
   --header "Authorization: Bearer abc123" \
   --uri http://localhost:8080/api/testing
```

Note that the `\` character in the above example is the line continuation character that allows you to break long lines into smaller lines in most Linux/macOS shells.

For the Windows `cmd` shell, use `^` for line continuation.  For PowerShell, use <code>`</code> (the backtick character).

## Server Mode

Creates a web server with mock routes that listen on specific paths and return specific response bodies.  Displays the details of any requests that it receives.

### Usage

```
httpcat server [OPTIONS]
```

### Server Specific Options

```
-p, --port=     Port to listen on. (default: 8080).

-r, --route=    Route which is made up of a path, a response body, and a
                response status, all separated by the pipe '|' character.
                Repeat for additional routes. (default: /|testing 123|200).

-c, --cors      Enable Cross Origin Resource Sharing (CORS).  Allows all
                requested methods and headers.

-H, --header=   A header to add to response in the form name:value. Use
                multiple times for multiple headers.
```

### Example

```
httpcat server \
  --port 8080 \
  --route "/hello|Hello World|200" \
  --route "/goodbye||204" \
  --header "Content-Type: text/plain" \
  --cors
```

This creates a web server that listens on port `8080` and responds to any requests to the `/hello` path with the response `Hello World` and response code `200`, and returns an empty response with a `204` code to any requests made to `/goodbye`.  The server will allow any requested headers and methods for CORS requests.

## Proxy Mode

Creates a reverse proxy that displays all HTTP requests and responses that pass through it.

### Usage

```
httpcat proxy [OPTIONS]
```

### Proxy Specific Options
```
-p, --port=     The port that the proxy listens on.
-t, --target=
```

### Example

```
httpcat proxy --port 8090 --target http://localhost:8080
```

Any requests sent to port 8090 will be forwarded to `http://localhost:8080` and all requests and responses will be displayed.

## Building

```
cd src
go build -o ../httpcat
```

### Cross Compiling

Linux

```
GOOS=linux GOARCH=amd64 go build -o ../httpcat-linux
```

Windows

```
GOOS=windows GOARCH=amd64 go build -o ../httpcat-win64
```

Intel Mac

```
GOOS=darwin GOARCH=amd64 go build -o ../httpcat-mac-intel
```

M1/ARM64 Mac

```
GOOS=darwin GOARCH=arm64 go build -o ../httpcat-mac-arm64
```

## License

Zero-Clause BSD License

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.