mirror of
https://github.com/openziti/zrok.git
synced 2024-12-23 07:09:12 +01:00
http lint
This commit is contained in:
parent
6698cb98d7
commit
cec12d5827
@ -1,7 +0,0 @@
|
||||
package http
|
||||
|
||||
type Config struct {
|
||||
IdentityPath string
|
||||
EndpointAddress string
|
||||
Service string
|
||||
}
|
29
http/http.go
29
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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
Loading…
Reference in New Issue
Block a user