fix proxy path & add skip auth

This commit is contained in:
DeniskaRediska committed 2019-11-25 15:44:03 +03:00
1 parent 38806190e7
commit 244d8fbdc2
13 files changed
+137 -95

No files matched your search

+22 -7
View File
@@ -22,8 +22,9 @@ const (
type (
Proxy interface {
ProxyRequest(ctx *fasthttp.RequestCtx) domain.ProxyResponse
ProxyRequest(ctx *fasthttp.RequestCtx, path string) domain.ProxyResponse
Consumer([]structure.AddressConfiguration) bool
SkipAuth() bool
Close()
}
)
@@ -34,15 +35,15 @@ func Init(location conf.Location) (Proxy, error) {
}
switch location.Protocol {
case httpProtocol:
proxy := http.NewProxy()
proxy := http.NewProxy(location.SkipAuth)
store[location.PathPrefix] = proxy
return proxy, nil
case grpcProtocol:
proxy := grpc.NewProxy()
proxy := grpc.NewProxy(location.SkipAuth)
store[location.PathPrefix] = proxy
return proxy, nil
case healthCheckProtocol:
proxy := health_check.NewProxy()
proxy := health_check.NewProxy(location.SkipAuth)
store[location.PathPrefix] = proxy
return proxy, nil
default:
@@ -50,13 +51,13 @@ func Init(location conf.Location) (Proxy, error) {
}
}
func Find(path string) Proxy {
func Find(path string) (Proxy, string) {
for pathPrefix, proxy := range store {
if strings.HasPrefix(path, pathPrefix) {
return proxy
return proxy, getPathWithoutPrefix(path)
}
}
return nil
return nil, ""
}
func Close() {
@@ -64,3 +65,17 @@ func Close() {
p.Close()
}
}
func getPathWithoutPrefix(path string) string {
firstFound := false
for i, value := range path {
if value == '/' {
if firstFound {
return path[i+1:]
} else {
firstFound = true
}
}
}
return ""
}