Skip to content

onewesong/http-relay

Repository files navigation

http-relay

A lightweight HTTP relay tool.

CI Release License Ask DeepWiki LLMAPIS

English | 简体中文

image

http-relay listens on local HTTP and relays requests in this format:

http://localhost:{port}/https://example.com/path?...

It forwards the request to the target absolute URL in the path and returns the upstream response as-is (status code, headers, body).

Installation

go install github.com/onewesong/http-relay/cmd/http-relay@latest

Quick Start

  1. Start service (default 127.0.0.1:8080):
http-relay
  1. Send a request:
curl -i "http://127.0.0.1:8080/https://example.com"

Check version:

http-relay version

Configuration (Environment Variables)

  • HOST: listen host (default: 127.0.0.1)
  • PORT: listen port (default: 8080)

Example:

HOST=0.0.0.0 PORT=9000 http-relay

Traffic Dump

Enable request/response dump:

http-relay -w

Mask auth-related headers in request dump:

http-relay -w -mask-auth

Masked request headers: Authorization, Proxy-Authorization, Cookie, X-Api-Key, X-Auth-Token.

Use WIRE_SCOPE (effective only when -w is enabled):

  • req: dump request only
  • resp: dump response only
  • req,resp: dump both (default)

Examples:

WIRE_SCOPE=req http-relay -w
WIRE_SCOPE=resp http-relay -w
WIRE_SCOPE=req,resp http-relay -w

Upstream Proxy

Supported proxy env vars:

  • ALL_PROXY (highest priority)
  • HTTP_PROXY / HTTPS_PROXY
  • NO_PROXY (bypass proxy when matched)

Examples:

HTTPS_PROXY=http://127.0.0.1:7890 http-relay
ALL_PROXY=socks5://127.0.0.1:1080 http-relay
HTTPS_PROXY=http://127.0.0.1:7890 NO_PROXY=example.com http-relay

Route Rule

Only supports /{absolute-url}, for example:

  • http://127.0.0.1:8080/https://example.com
  • http://127.0.0.1:8080/http://httpbin.org/post

Target URL must include http:// or https://.

Error Codes

  • 400: missing or invalid target URL
  • 502: upstream connection failure or timeout
  • 500: internal server error

About

A lightweight HTTP relay that forwards /{absolute-url} requests with optional proxy and traffic dump.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages