Skip to content

-l flag is ignored: HTTP server always binds to default port 8080 #23

@Geker

Description

@Geker

Description

The -l flag for specifying the HTTP proxy listen address is parsed and logged correctly, but the HTTP server always binds to the default port 8080 regardless of the value provided.

Version

gohpts v1.14.0 (built for darwin arm64 with go1.26.3)

Steps to Reproduce

# Start gohpts with custom port 38080
gohpts -l 38080 -s 13659

# Log output shows correct address:
# [INF] SOCKS5 Proxy: 127.0.0.1:13659
# [INF] HTTP Proxy: 127.0.0.1:38080

# But the server actually binds to 8080:
lsof -i :38080  # (empty - nothing listening)
lsof -i :8080   # gohpts is listening here instead

Expected Behavior

The HTTP server should bind to the address specified by the -l flag (e.g., 127.0.0.1:38080).

Actual Behavior

The HTTP server always binds to 127.0.0.1:8080 (the default), ignoring the -l flag. This applies to both the HTTP server and the HTTP/3 server.

Root Cause

In gohpts.go, both http.Server and http3.Server are initialized with the addrHTTP constant ("127.0.0.1:8080") instead of the parsed p.httpServerAddr:

  • Line 549: Addr: addrHTTP should be Addr: p.httpServerAddr
  • Line 581: Addr: addrHTTP should be Addr: p.httpServerAddr

The log output (line 768) correctly uses p.httpServerAddr, which is why the logged address appears correct while the actual binding is wrong.

Fix

--- a/gohpts.go
+++ b/gohpts.go
@@ -546,7 +546,7 @@
        hs := &http.Server{
-           Addr:           addrHTTP,
+           Addr:           p.httpServerAddr,
@@ -578,7 +578,7 @@
            hs3 := &http3.Server{
-               Addr:           addrHTTP,
+               Addr:           p.httpServerAddr,

I have a commit with this fix ready and can submit a PR if desired.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions