
The httputil.ReverseProxy Trap in Go: Why Director Drops Your Headers
You build an API Gateway in Go, validate a token, and dutifully forward the user ID to an internal microservice via the standard Director. Yet in production the backend suddenly receives an empty string, and authentication silently breaks without a single warning in the logs.
The root cause lies in the HTTP specification and the execution order inside the legacy httputil.ReverseProxy. Any external client can send a Connection header naming your internal field. Go's handler runs your Director first and then obediently strips all hop-by-hop fields, erasing the header you just set before sending the request into your private network.
The fix arrived in Go 1.20 with the Rewrite interface. It strips all client transit headers first and only then hands control to your code, guaranteeing your auth data gets through.




