proxy.New: assembly as a library module #47

Merged
mikluko merged 1 commit from refactor/proxy-module into main 2026-10-26 22:19:22 +00:00
Owner

Candidate 5 of the architecture review.

How the router, handlers and middleware fit together lived in the command's newHandler, and library users had to copy it. The * fallback rule was split: the router matched host patterns while the command turned * into the Connect fallback.

  • proxy.New(proxy.Config) builds the proxy from host patterns, an Issuer, middleware for plain-HTTP and intercepted requests, the two header switches, loggers and the tunnel dial timeout. It is at 100% coverage, and ExampleNew is the same code as the how-to.
  • router.Router.HandleConnectHost("*", h) sets the fallback, whenever it is added. A * in both MITM and Tunnel is an error from proxy.New.
  • "With no patterns, tunnel everything" moves from flag parsing into proxy.New, so library callers get it too.
  • The command maps flags onto proxy.Config, and header rewriting becomes one Middleware entry. registerHandler, named and spanName move out; main.go loses about 60 lines.

The header-rewriting how-to's Go section now uses proxy.New. The suite passes three times in a row under -race.

Candidate 5 of the architecture review. How the router, handlers and middleware fit together lived in the command's `newHandler`, and library users had to copy it. The `*` fallback rule was split: the router matched host patterns while the command turned `*` into the `Connect` fallback. - `proxy.New(proxy.Config)` builds the proxy from host patterns, an Issuer, middleware for plain-HTTP and intercepted requests, the two header switches, loggers and the tunnel dial timeout. It is at 100% coverage, and `ExampleNew` is the same code as the how-to. - `router.Router.HandleConnectHost("*", h)` sets the fallback, whenever it is added. A `*` in both MITM and Tunnel is an error from `proxy.New`. - "With no patterns, tunnel everything" moves from flag parsing into `proxy.New`, so library callers get it too. - The command maps flags onto `proxy.Config`, and header rewriting becomes one `Middleware` entry. `registerHandler`, `named` and `spanName` move out; `main.go` loses about 60 lines. The header-rewriting how-to's Go section now uses `proxy.New`. The suite passes three times in a row under `-race`.
proxy.New: assembly as a library module
All checks were successful
CI / changelog (pull_request) Successful in 6s
CI / test (pull_request) Successful in 50s
62fd9b7f9b
How the router, handlers and middleware fit together lived in the command,
and library users copied it; the "*" fallback rule was split between the
router and the command. proxy.New builds the proxy from host patterns, an
Issuer, middleware and loggers; the command maps flags onto proxy.Config,
and the router takes "*" as its fallback.
mikluko deleted branch refactor/proxy-module 2026-10-26 22:19:22 +00:00
Sign in to join this conversation.
No description provided.