A netcat-like tool for analysing or mocking HTTP requests.

Mark George authored on 13 Mar 2022
src Big bang. Pretty much complete. 2 years ago
README.md Add license section 2 years ago
README.md

httpcat

A netcat like tool for analysing/mocking HTTP requests (from both server and client perspective). My first experiment with Go.

Usage

httpcat [OPTIONS] <command>

Application Options:
  -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 are blue and responses are red)
        --notimestamps  Don't show timestamps

Help Options:
  -h, --help          Show this help message

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

Get help about a specific command by adding --help after the command. Example:

httpcat client --help

Client Mode

Sends a request to the specified server and displays the response.

Usage

httpcat [OPTIONS] client [client-OPTIONS]

Application Options:
  -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 are blue and responses are red)
      --notimestamps  Don't show timestamps

Help Options:
  -h, --help          Show this help message

[client command options]
      -u, --uri=      The URI to send the request to
          --header=   A header to add to request in the form name:value. Use multiple times for multiple headers.
      -m, --method=   HTTP method for request (default: GET)
      -b, --body=     Request body to send

Example

httpcat client --method POST --body TESTING --uri http://localhost:8080/api/testing

Server Mode

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

Usage

httpcat [OPTIONS] server [server-OPTIONS]

Application Options:
  -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 are blue and responses are red)
      --notimestamps  Don't show timestamps

Help Options:
  -h, --help          Show this help message

[server command 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|200)
      -c, --cors      Enable Cross Origin Resource Sharing (CORS).
      -H, --header=   A header to add to response in the form name:value. Repeat for additional headers.

Example

httpcat server --port 8080 --route "/hello|Hello World|200" --header "Content-Type:text/plain"

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. Repeat the --route option to add more routes.

Proxy Mode

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

Usage

httpcat [OPTIONS] proxy [proxy-OPTIONS]

Application Options:
  -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 are blue and responses are red)
      --notimestamps  Don't show timestamps

Help Options:
  -h, --help          Show this help message

[proxy command 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.