11package oginy
22
33import (
4- "context"
54 "crypto/rand"
65 "crypto/rsa"
76 "crypto/tls"
@@ -46,19 +45,24 @@ func (m *muxProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
4645 if pe .pathBasedRouting {
4746 // Only forward /_api/artifactcache requests to local service
4847 if strings .HasPrefix (r .URL .Path , "/_api/artifactcache" ) {
48+ log .Printf ("[OGINY ROUTING] %s %s → LOCAL SERVICE (port %s)" , r .Method , r .URL .Path , pe .target .Host )
4949 pe .proxy .ServeHTTP (w , r )
5050 } else if pe .remoteProxy != nil {
5151 // Forward all other requests to the actual domain
52+ log .Printf ("[OGINY ROUTING] %s %s → REMOTE DOMAIN" , r .Method , r .URL .Path )
5253 pe .remoteProxy .ServeHTTP (w , r )
5354 } else {
55+ log .Printf ("[OGINY ROUTING] %s %s → ERROR: no remote proxy configured" , r .Method , r .URL .Path )
5456 http .Error (w , "no remote proxy configured" , http .StatusBadGateway )
5557 }
5658 } else {
5759 // Standard routing - forward all requests to local service
60+ log .Printf ("[OGINY ROUTING] %s %s → LOCAL SERVICE (port %s) [no path routing]" , r .Method , r .URL .Path , pe .target .Host )
5861 pe .proxy .ServeHTTP (w , r )
5962 }
6063 return
6164 }
65+ log .Printf ("[OGINY ROUTING] %s %s → ERROR: no backend for host %s" , r .Method , r .URL .Path , host )
6266 http .Error (w , "no backend for host" , http .StatusBadGateway )
6367}
6468
@@ -190,6 +194,7 @@ func generateLeafCert(hostname, certPath, keyPath, caCertPath, caKeyPath string)
190194func resolveRealIP (hostname string ) (string , error ) {
191195 // Use Cloudflare's DNS over HTTPS
192196 url := fmt .Sprintf ("https://1.1.1.1/dns-query?name=%s&type=A" , hostname )
197+ log .Printf ("[DNS RESOLUTION] Resolving real IP for %s using DNS over HTTPS..." , hostname )
193198
194199 req , err := http .NewRequest ("GET" , url , nil )
195200 if err != nil {
@@ -223,6 +228,7 @@ func resolveRealIP(hostname string) (string, error) {
223228 // Find the first A record (type 1)
224229 for _ , answer := range result .Answer {
225230 if answer .Type == 1 && answer .Data != "" {
231+ log .Printf ("[DNS RESOLUTION] Found IP %s for %s" , answer .Data , hostname )
226232 return answer .Data , nil
227233 }
228234 }
@@ -389,21 +395,8 @@ func Start(port int) error {
389395
390396 // Create custom transport that sets the proper SNI
391397 remoteTransport := & http.Transport {
392- Proxy : http .ProxyFromEnvironment ,
393- DialContext : func (ctx context.Context , network , addr string ) (net.Conn , error ) {
394- // Always dial the real IP, not the hostname
395- if strings .HasPrefix (addr , realIP ) {
396- return (& net.Dialer {
397- Timeout : 10 * time .Second ,
398- KeepAlive : 60 * time .Second ,
399- }).DialContext (ctx , network , addr )
400- }
401- // For any other connections, use the default dialer
402- return (& net.Dialer {
403- Timeout : 10 * time .Second ,
404- KeepAlive : 60 * time .Second ,
405- }).DialContext (ctx , network , addr )
406- },
398+ Proxy : http .ProxyFromEnvironment ,
399+ DialContext : (& net.Dialer {Timeout : 10 * time .Second , KeepAlive : 60 * time .Second }).DialContext ,
407400 TLSClientConfig : & tls.Config {
408401 ServerName : resultsReceiverHost , // Set SNI to the original hostname
409402 },
@@ -420,10 +413,18 @@ func Start(port int) error {
420413 remoteProxy := httputil .NewSingleHostReverseProxy (remoteURL )
421414 remoteProxy .Transport = remoteTransport
422415 remoteProxy .Director = func (r * http.Request ) {
416+ // Log the request details before modification
417+ origURL := r .URL .String ()
418+ origHost := r .Host
419+
423420 r .URL .Scheme = remoteURL .Scheme
424421 r .URL .Host = remoteURL .Host
425422 r .Host = resultsReceiverHost // Keep the original Host header
426423 // Don't set X-Forwarded-Proto for remote requests as they're already HTTPS
424+
425+ // Log where the request is being sent
426+ log .Printf ("[REMOTE PROXY] Forwarding request: %s %s (orig host: %s) → %s (IP: %s, Host header: %s)" ,
427+ r .Method , origURL , origHost , r .URL .String (), realIP , r .Host )
427428 }
428429 entry .remoteProxy = remoteProxy
429430
0 commit comments