Skip to content

BasicAcid/htreq

Repository files navigation

htreq

Build Status Release License

Send raw HTTP requests over TCP or TLS with complete control.

What makes htreq different: Unlike curl which abstracts the request, or Hurl which uses its own syntax, htreq sends exactly what you write - raw HTTP bytes over the wire. No hidden headers, no automatic behaviors, just your request exactly as specified.

Features

  • HTTP/1.1 - Full support including chunked encoding
  • HTTP/2 - With ALPN negotiation and frame inspection
  • HTTP/3 - QUIC protocol support for modern low-latency connections
  • WebSocket - Interactive protocol upgrade and messaging
  • TLS - Auto-detection for port 443, certificate inspection
  • Unix sockets - Connect to Docker API and other socket services
  • Basic authentication - Automatic header generation with --user
  • Environment variables - Expand $VAR in request files
  • Colored output - Syntax highlighting (auto-disabled when piped)
  • Request timing - Detailed breakdown of connection phases
  • Automatic retries - Configurable retry logic for transient failures
  • Redirect following - Automatic HTTP redirect handling with --follow

Installation

Debian/Ubuntu

Download from releases:

wget https://github.com/BasicAcid/htreq/releases/latest/download/htreq_VERSION_amd64.deb
sudo dpkg -i htreq_VERSION_amd64.deb

From Source

Requires Go 1.24+:

git clone https://github.com/BasicAcid/htreq
cd htreq
make
sudo make install

Quick Start

Create a request file request.http:

GET /get HTTP/1.1
Host: httpbin.org
Accept: application/json

Send it:

htreq -f request.http

That's it. The target is extracted from the Host header, and TLS is auto-enabled for port 443.

Usage Examples

Basic GET Request

File: get.http

GET /json HTTP/1.1
Host: httpbin.org
Accept: application/json

Command:

htreq -f get.http

POST with JSON

File: post.http

POST /post HTTP/1.1
Host: httpbin.org
Content-Type: application/json
Content-Length: 27

{"name": "Alice", "age": 30}

Command:

htreq -f post.http --body | jq .

Environment Variables

Create .env:

API_TOKEN=your-secret-token

File: api.http

GET /api/data HTTP/1.1
Host: api.example.com
Authorization: Bearer $API_TOKEN
Accept: application/json

Command:

htreq --env-file .env -f api.http

Basic Authentication

File: auth.http

GET /basic-auth/myuser/mypass HTTP/1.1
Host: httpbin.org
Connection: close

Command:

htreq -f auth.http --user myuser:mypass

The --user flag automatically generates the Authorization: Basic header with base64-encoded credentials.

Warning: Basic auth should only be used over TLS/HTTPS to avoid sending credentials in plain text.

HTTP/2

File: http2.http

GET / HTTP/1.1
Host: cloudflare.com

Command:

htreq --http2 -f http2.http

HTTP/3 (QUIC)

File: http3.http

GET / HTTP/1.1
Host: google.com
User-Agent: htreq/1.0
Connection: close

Command:

htreq --http3 -f http3.http

HTTP/3 uses QUIC protocol (UDP-based) for improved performance and reduced latency. Most modern services like Google, Cloudflare, and Facebook support HTTP/3.

WebSocket

File: websocket.http

GET /chat HTTP/1.1
Host: websocket.example.com
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
Sec-WebSocket-Version: 13

Command:

htreq --websocket -f websocket.http

Type messages and press Enter to send. Press Ctrl+C to exit.

Unix Socket (Docker API)

File: docker.http

GET /containers/json HTTP/1.1
Host: localhost

Command:

sudo htreq --unix-socket /var/run/docker.sock -f docker.http

Debugging with Timing

htreq -f request.http --timing

Shows detailed breakdown:

[*] Timing breakdown:
DNS lookup:      21.796ms
TCP connect:     33.709ms
TLS handshake:   27.184ms
Request send:    10µs
Server processing: 36.667ms
Content download: 101µs
Total:           119.501ms

Automatic Retries

htreq -f request.http --retry 3 --retry-delay 2s

Command-Line Options

Usage: htreq [target] [options]

Arguments:
  target                  host[:port] (optional if Host header present)

Options:
  -f, --file FILE         Request file (default: stdin)
  --unix-socket PATH      Connect to Unix socket
  --env                   Expand environment variables ($VAR or ${VAR})
  --env-file FILE         Load environment variables from file

  --tls                   Force TLS (auto-enabled for port 443)
  --no-tls                Disable TLS
  --no-verify             Skip TLS certificate verification
  --dump-tls              Show TLS session and certificate info

  --http2                 Use HTTP/2 protocol
  --http3                 Use HTTP/3 protocol (QUIC)
  --websocket, --ws       Use WebSocket protocol
  --dump-frames           Show HTTP/2 frames (requires --http2)

  --retry N               Number of retries on failure (default: 0)
  --retry-delay DURATION  Delay between retries (default: 1s)
  --follow, -L            Follow HTTP redirects
  --max-redirects N       Maximum redirects to follow (default: 10)
  --timeout DURATION      Socket timeout (default: 10s)
  --max-bytes N           Limit response output to N bytes

  --user USER:PASS        Basic authentication credentials
  --print-request         Show request being sent
  --timing                Show detailed request/response timing
  --head                  Show only response headers
  --body                  Show only response body

  --no-color              Disable colored output
  -q, --quiet             Suppress informational messages
  -v, --verbose           Verbose output

Request File Format

Standard HTTP format:

METHOD /path HTTP/1.1
Header-Name: value
Content-Type: application/json
Content-Length: 27

Request body content here

Notes:

  • Line endings are automatically normalized (CRLF or LF accepted)
  • Environment variables with --env: Use $VAR or ${VAR} syntax
  • Target can be specified in the Host header or as a command-line argument

Examples Directory

The examples/ directory contains ready-to-use request files:

htreq -f examples/get-https.http
htreq -f examples/post-json.http
htreq --http2 -f examples/http2-example.http
htreq --websocket -f examples/websocket-echo.http

See examples/README.md for complete documentation.

License

GNU General Public License v3.0 - see LICENSE file.

About

Send raw HTTP requests over TCP or TLS.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors