feat: match proxy's from on whole targeted url
Cadoles/bouncer/pipeline/head This commit looks good
Details
Cadoles/bouncer/pipeline/head This commit looks good
Details
This commit is contained in:
parent
f548c8c8e7
commit
274bef13d8
|
@ -3,7 +3,6 @@ package director
|
|||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"sort"
|
||||
|
||||
"forge.cadoles.com/Cadoles/go-proxy"
|
||||
|
@ -28,12 +27,23 @@ func (d *Director) rewriteRequest(r *http.Request) (*http.Request, error) {
|
|||
return r, errors.WithStack(err)
|
||||
}
|
||||
|
||||
url := getRequestURL(r)
|
||||
ctx = logger.With(r.Context(), logger.F("url", url.String()))
|
||||
|
||||
var match *store.Proxy
|
||||
|
||||
MAIN:
|
||||
for _, p := range proxies {
|
||||
for _, from := range p.From {
|
||||
if matches := wildcard.Match(r.Host, from); !matches {
|
||||
logger.Debug(
|
||||
ctx, "matching request with proxy's from",
|
||||
logger.F("from", from),
|
||||
)
|
||||
if matches := wildcard.Match(url.String(), from); !matches {
|
||||
logger.Debug(
|
||||
ctx, "proxy's from matched",
|
||||
logger.F("from", from),
|
||||
)
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package director
|
|||
|
||||
import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"forge.cadoles.com/Cadoles/go-proxy"
|
||||
"forge.cadoles.com/Cadoles/go-proxy/util"
|
||||
|
@ -16,3 +17,19 @@ func createMiddlewareChain(handler http.Handler, middlewares []proxy.Middleware)
|
|||
|
||||
return handler
|
||||
}
|
||||
|
||||
func getRequestURL(r *http.Request) *url.URL {
|
||||
scheme := "http"
|
||||
if r.URL.Scheme != "" {
|
||||
scheme = r.URL.Scheme
|
||||
}
|
||||
|
||||
url := url.URL{
|
||||
Host: r.Host,
|
||||
Scheme: scheme,
|
||||
Path: r.URL.Path,
|
||||
RawQuery: r.URL.RawQuery,
|
||||
}
|
||||
|
||||
return &url
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue