From e292f58be5d19be832f7db83f3d1d9c61ab1996a Mon Sep 17 00:00:00 2001 From: Jamie Thompson Date: Mon, 15 Jul 2024 14:48:45 +0100 Subject: [PATCH] Add bind flag for specifying address to bind to --- CHANGELOG.md | 2 ++ README.md | 4 +++- main.go | 4 +++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd530cf..9779eba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added +- New `--bind` option which allows you to specify what address to bind to, defaults to `0.0.0.0`. ## [v1.1.1] - 2023-12-04 ### Fixed diff --git a/README.md b/README.md index e360fcd..d15897e 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,8 @@ Usage of simple-proxy: log to standard error as well as files -basic-auth string basic auth, format 'username:password', no auth if not provided + -bind string + address to bind the proxy server to (default "0.0.0.0") -cert string path to cert file -key string @@ -112,7 +114,7 @@ and port. On Windows you can use: ```powershell -curl.exe 'https://www.random.org/integers/?num=1&min=1&max=5&col=1&base=10&format=plain&rnd=new' --proxy 'http://localhost:8888' +curl.exe --proxy 'http://localhost:8888' 'https://www.random.org/integers/?num=1&min=1&max=5&col=1&base=10&format=plain&rnd=new' ``` ## Contributing diff --git a/main.go b/main.go index 7644a6f..98fa34e 100644 --- a/main.go +++ b/main.go @@ -32,6 +32,8 @@ func main() { flag.BoolVar(&version, "version", false, "prints current simple-proxy version") var protocol string flag.StringVar(&protocol, "protocol", httpProtocol, "proxy protocol (http or https)") + var bind string + flag.StringVar(&bind, "bind", "0.0.0.0", "address to bind the proxy server to") var port string flag.StringVar(&port, "port", "8888", "proxy port to listen on") var certPath string @@ -83,7 +85,7 @@ func main() { } server := &http.Server{ - Addr: fmt.Sprintf(":%s", port), + Addr: fmt.Sprintf("%s:%s", bind, port), Handler: handler, // Disable HTTP/2. TLSNextProto: make(map[string]func(*http.Server, *tls.Conn, http.Handler)),