diff --git a/http/config.go b/http/config.go deleted file mode 100644 index 4c9b2a51..00000000 --- a/http/config.go +++ /dev/null @@ -1,7 +0,0 @@ -package http - -type Config struct { - IdentityPath string - EndpointAddress string - Service string -} diff --git a/http/http.go b/http/http.go index 81d0e785..60c279f6 100644 --- a/http/http.go +++ b/http/http.go @@ -6,10 +6,19 @@ import ( "github.com/openziti/sdk-golang/ziti/config" "github.com/openziti/sdk-golang/ziti/edge" "github.com/pkg/errors" + "github.com/sirupsen/logrus" "net/http" + "net/http/httputil" + "net/url" "time" ) +type Config struct { + IdentityPath string + EndpointAddress string + Service string +} + type httpProxy struct { Requests func() int32 listener edge.Listener @@ -49,3 +58,23 @@ func (p *httpProxy) Run() error { } return nil } + +func NewProxy(target string) (*httputil.ReverseProxy, error) { + targetURL, err := url.Parse(target) + if err != nil { + return nil, err + } + + proxy := httputil.NewSingleHostReverseProxy(targetURL) + director := proxy.Director + proxy.Director = func(req *http.Request) { + director(req) + logrus.Debugf("-> %v", req.URL.String()) + req.Header.Set("X-Proxy", "zrok") + } + proxy.ErrorHandler = func(w http.ResponseWriter, r *http.Request, err error) { + logrus.Errorf("error proxying: %v", err) + } + + return proxy, nil +} diff --git a/http/proxy.go b/http/proxy.go deleted file mode 100644 index 3848d535..00000000 --- a/http/proxy.go +++ /dev/null @@ -1,28 +0,0 @@ -package http - -import ( - "github.com/sirupsen/logrus" - "net/http" - "net/http/httputil" - "net/url" -) - -func NewProxy(target string) (*httputil.ReverseProxy, error) { - targetURL, err := url.Parse(target) - if err != nil { - return nil, err - } - - proxy := httputil.NewSingleHostReverseProxy(targetURL) - director := proxy.Director - proxy.Director = func(req *http.Request) { - director(req) - logrus.Debugf("-> %v", req.URL.String()) - req.Header.Set("X-Proxy", "zrok") - } - proxy.ErrorHandler = func(w http.ResponseWriter, r *http.Request, err error) { - logrus.Errorf("error proxying: %v", err) - } - - return proxy, nil -}