From d9cc34ea8568ef73e0f5785406ec537b1fbb0227 Mon Sep 17 00:00:00 2001 From: fangdingjun Date: Wed, 4 Jan 2017 16:55:12 +0800 Subject: [PATCH] fix for reverse proxy for unix socket --- proxy.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/proxy.go b/proxy.go index 4bd3d82..8cb41d6 100644 --- a/proxy.go +++ b/proxy.go @@ -17,6 +17,7 @@ type proxy struct { addr string prefix string dialer *net.Dialer + network string } func newProxy(addr string, prefix string) *proxy { @@ -25,22 +26,26 @@ func newProxy(addr string, prefix string) *proxy { prefix: prefix, dialer: &net.Dialer{Timeout: 2 * time.Second}, } + if addr[0] == '/' { + p.network = "unix" + } else { + p.network = "tcp" + } p.transport = &http.Transport{ DialContext: p.dialContext, MaxIdleConns: 5, IdleConnTimeout: 30 * time.Second, - //Dial: p.dial, } return p } func (p *proxy) dialContext(ctx context.Context, network, addr string) (net.Conn, error) { - return p.dialer.DialContext(ctx, network, p.addr) + return p.dialer.DialContext(ctx, p.network, p.addr) } func (p *proxy) dial(network, addr string) (conn net.Conn, err error) { - return p.dialer.Dial(network, p.addr) + return p.dialer.Dial(p.network, p.addr) } func (p *proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {